| 
									
										
										
										
											2024-09-27 09:06:45 -05:00
										 |  |  | <template> | 
					
						
							|  |  |  |   <v-select | 
					
						
							|  |  |  |     v-model="selected" | 
					
						
							|  |  |  |     :items="households" | 
					
						
							|  |  |  |     :label="label" | 
					
						
							|  |  |  |     :hint="description" | 
					
						
							|  |  |  |     :persistent-hint="!!description" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     item-title="name" | 
					
						
							| 
									
										
										
										
											2024-09-27 09:06:45 -05:00
										 |  |  |     :multiple="multiselect" | 
					
						
							|  |  |  |     :prepend-inner-icon="$globals.icons.household" | 
					
						
							|  |  |  |     return-object | 
					
						
							|  |  |  |   > | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     <template #chip="data"> | 
					
						
							| 
									
										
										
										
											2024-09-27 09:06:45 -05:00
										 |  |  |       <v-chip | 
					
						
							|  |  |  |         :key="data.index" | 
					
						
							|  |  |  |         class="ma-1" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |         :input-value="data.item" | 
					
						
							|  |  |  |         size="small" | 
					
						
							|  |  |  |         closable | 
					
						
							| 
									
										
										
										
											2024-09-27 09:06:45 -05:00
										 |  |  |         label | 
					
						
							|  |  |  |         color="accent" | 
					
						
							|  |  |  |         dark | 
					
						
							|  |  |  |         @click:close="removeByIndex(data.index)" | 
					
						
							|  |  |  |       > | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |         {{ data.item.raw.name || data.item }} | 
					
						
							| 
									
										
										
										
											2024-09-27 09:06:45 -05:00
										 |  |  |       </v-chip> | 
					
						
							|  |  |  |     </template> | 
					
						
							|  |  |  |   </v-select> | 
					
						
							|  |  |  | </template> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <script lang="ts"> | 
					
						
							|  |  |  | import { useHouseholdStore } from "~/composables/store/use-household-store"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | interface HouseholdLike { | 
					
						
							|  |  |  |   id: string; | 
					
						
							|  |  |  |   name: string; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  | export default defineNuxtComponent({ | 
					
						
							| 
									
										
										
										
											2024-09-27 09:06:45 -05:00
										 |  |  |   props: { | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     modelValue: { | 
					
						
							| 
									
										
										
										
											2024-09-27 09:06:45 -05:00
										 |  |  |       type: Array as () => HouseholdLike[], | 
					
						
							|  |  |  |       required: true, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     multiselect: { | 
					
						
							|  |  |  |       type: Boolean, | 
					
						
							|  |  |  |       default: false, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     description: { | 
					
						
							|  |  |  |       type: String, | 
					
						
							|  |  |  |       default: "", | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |   emits: ["update:modelValue"], | 
					
						
							| 
									
										
										
										
											2024-09-27 09:06:45 -05:00
										 |  |  |   setup(props, context) { | 
					
						
							|  |  |  |     const selected = computed({ | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |       get: () => props.modelValue, | 
					
						
							| 
									
										
										
										
											2024-09-27 09:06:45 -05:00
										 |  |  |       set: (val) => { | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |         context.emit("update:modelValue", val); | 
					
						
							| 
									
										
										
										
											2024-09-27 09:06:45 -05:00
										 |  |  |       }, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     onMounted(() => { | 
					
						
							|  |  |  |       if (selected.value === undefined) { | 
					
						
							|  |  |  |         selected.value = []; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     const i18n = useI18n(); | 
					
						
							| 
									
										
										
										
											2024-09-27 09:06:45 -05:00
										 |  |  |     const label = computed( | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |       () => props.multiselect ? i18n.t("household.households") : i18n.t("household.household"), | 
					
						
							| 
									
										
										
										
											2024-09-27 09:06:45 -05:00
										 |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const { store: households } = useHouseholdStore(); | 
					
						
							|  |  |  |     function removeByIndex(index: number) { | 
					
						
							|  |  |  |       if (selected.value === undefined) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       const newSelected = selected.value.filter((_, i) => i !== index); | 
					
						
							|  |  |  |       selected.value = [...newSelected]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |       selected, | 
					
						
							|  |  |  |       label, | 
					
						
							|  |  |  |       households, | 
					
						
							|  |  |  |       removeByIndex, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | </script> |