diff --git a/src/components/03_customer-management/CustomerInfoComponent.vue b/src/components/03_customer-management/CustomerInfoComponent.vue index 9d8f7cef..7f33f4bb 100644 --- a/src/components/03_customer-management/CustomerInfoComponent.vue +++ b/src/components/03_customer-management/CustomerInfoComponent.vue @@ -4,22 +4,34 @@ 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, Customer } from 'src/stores/customer/types'; +import { + CustomerBranch, + Customer, + CustomerType, +} from 'src/stores/customer/types'; +import { watch } from 'vue'; const userCustomer = useCustomerStore(); -const { fetchListById } = userCustomer; +const { fetchListById, fetchListBranch } = userCustomer; const inputSearch = ref(''); const branch = defineModel('branch'); const currentCustomerName = defineModel('currentCustomerName'); -const currentCustomerUrlImage = ref(); -const returnCustomer = ref(); +const currentCustomerUrlImage = defineModel( + 'currentCustomerUrlImage', +); + +const currentPageBranch = ref(1); +const maxPageBranch = ref(1); +const pageSizeBranch = ref(30); + const prop = withDefaults( defineProps<{ color?: 'purple' | 'green'; customerId: string; + customerType: CustomerType; }>(), { color: 'green', @@ -28,21 +40,44 @@ const prop = withDefaults( const emit = defineEmits<{ (e: 'back'): void; - ( - e: 'viewDetail', - returnCustomer: Customer & { branch: CustomerBranch[] }, - ): void; - + (e: 'viewDetail', branch: CustomerBranch[]): void; (e: 'dialog'): void; }>(); +async function searchBranch() { + const resultList = await fetchListBranch({ + query: inputSearch.value, + includeCustomer: true, + }); + + if (resultList) { + branch.value = resultList.result; + } +} + onMounted(async () => { - const result = await fetchListById(prop.customerId); + const result = await fetchListBranch({ + customerId: prop.customerId, + page: 1, + pageSize: pageSizeBranch.value, + }); if (result) { - returnCustomer.value = result; - currentCustomerName.value = result.customerName; - currentCustomerUrlImage.value = result.imageUrl; - branch.value = result.branch; + currentCustomerName.value = 'dasd'; + + branch.value = result.result; + } +}); + +watch(currentPageBranch, async () => { + const resultList = await fetchListBranch({ + page: currentPageBranch.value, + pageSize: pageSizeBranch.value, + }); + + if (resultList) { + currentPageBranch.value = resultList.page; + maxPageBranch.value = Math.ceil(resultList.total / pageSizeBranch.value); + branch.value = resultList.result; } }); @@ -59,6 +94,7 @@ onMounted(async () => { @click="$emit('back')" class="q-mr-md" /> + { -
+
+ +
+ +
- +