feat: emit Customer เก็บใน form

This commit is contained in:
Net 2024-06-10 15:57:12 +07:00
parent 75246296ae
commit b7d4178d63

View file

@ -4,7 +4,7 @@ import AppBox from 'components/app/AppBox.vue';
import BranchCardCustomer from 'components/03_customer-management/BranchCardCustomer.vue';
import { onMounted } from 'vue';
import useCustomerStore from 'src/stores/customer';
import { CustomerBranch } from 'src/stores/customer/types';
import { CustomerBranch, Customer } from 'src/stores/customer/types';
const userCustomer = useCustomerStore();
const { fetchListById } = userCustomer;
@ -13,8 +13,9 @@ const inputSearch = ref<string>('');
const branch = defineModel<CustomerBranch[]>('branch');
const currentCustomerName = defineModel<string>('currentCustomerName');
const currentCustomerUrlImage = defineModel<string>('currentCustomerUrlImage');
const currentCustomerUrlImage = ref<string | null>();
const returnCustomer = ref<Customer & { branch: CustomerBranch[] }>();
const prop = withDefaults(
defineProps<{
color?: 'purple' | 'green';
@ -25,15 +26,20 @@ const prop = withDefaults(
},
);
defineEmits<{
const emit = defineEmits<{
(e: 'back'): void;
(e: 'viewDetail'): void;
(
e: 'viewDetail',
returnCustomer: Customer & { branch: CustomerBranch[] },
): void;
(e: 'dialog'): void;
}>();
onMounted(async () => {
const result = await fetchListById(prop.customerId);
if (result) {
returnCustomer.value = result;
currentCustomerName.value = result.customerName;
currentCustomerUrlImage.value = result.imageUrl;
branch.value = result.branch;
@ -140,9 +146,12 @@ onMounted(async () => {
</q-btn>
</div>
</div>
<div class="row q-pa-lg q-col-gutter-xl">
<div class="row q-pa-lg q-col-gutter-xl" v-if="!!returnCustomer">
<div v-for="(br, i) in branch" :key="i" class="col-4">
<BranchCardCustomer :data="br" @view-detail="$emit('viewDetail')" />
<BranchCardCustomer
:data="br"
@view-detail="emit('viewDetail', { ...returnCustomer, branch: [br] })"
/>
</div>
</div>
</AppBox>