diff --git a/src/pages/03_customer-management/MainPage.vue b/src/pages/03_customer-management/MainPage.vue index a6099b5d..93136b98 100644 --- a/src/pages/03_customer-management/MainPage.vue +++ b/src/pages/03_customer-management/MainPage.vue @@ -24,13 +24,19 @@ import FormBusiness from 'src/components/03_customer-management/FormBusiness.vue import DrawerInfo from 'src/components/DrawerInfo.vue'; import InfoForm from 'src/components/02_personnel-management/InfoForm.vue'; import CustomerInfoComponent from 'src/components/03_customer-management/CustomerInfoComponent.vue'; -import { CustomerCreate, CustomerStats, Customer } from 'stores/customer/types'; +import { + CustomerCreate, + CustomerStats, + Customer, + CustomerUpdate, + CustomerBranch, +} from 'stores/customer/types'; import { onMounted } from 'vue'; import { dialog } from 'src/stores/utils'; const userCustomer = useCustomerStore(); -const { create, getStatsCustomer, fetchList } = userCustomer; +const { create, getStatsCustomer, fetchList, editById } = userCustomer; const formData = ref({ status: 'CREATED', customerType: 'CORP', @@ -80,6 +86,8 @@ const isMainPage = ref(true); const statsCustomerType = ref(); const currentCustomerId = ref(''); +const currentCustomer = ref(); + const inputFile = (() => { const element = document.createElement('input'); element.type = 'file'; @@ -100,7 +108,7 @@ const inputFile = (() => { return element; })(); -const listCustomer = ref>(); +const listCustomer = ref<(Customer & { branch: CustomerBranch[] })[]>(); const itemCard = [ { @@ -169,6 +177,7 @@ function openDialogInputForm(action: 'FORM' | 'INFO' = 'FORM', id?: string) { function onClose() { infoDrawer.value = false; dialogInputForm.value = false; + clearForm(); } function clearForm() { @@ -223,20 +232,78 @@ async function onSubmit() { clearForm(); } +async function onSubmitEdit(id: string) { + if (!formData.value) return; + + const tempValue: CustomerUpdate = { + status: 'ACTIVE', + customerType: formData.value.customerType, + customerName: formData.value.customerName, + customerNameEN: formData.value.customerNameEN, + customerBranch: formData.value.customerBranch, + taxNo: formData.value.taxNo, + }; + + await editById(id, tempValue); + clearForm(); +} + function undo() { infoDrawerEdit.value = false; } +async function assignFormData(data: Customer & { branch: CustomerBranch[] }) { + formData.value = { + status: 'CREATED', + customerType: data.customerType, + customerName: data.customerName, + customerNameEN: data.customerNameEN, + taxNo: data.taxNo, + customerBranch: [], + image: new File([''], 'dummy.jpg'), + }; + + data.branch.forEach((v) => { + formData.value.customerBranch?.push({ + address: v.address, + addressEN: v.addressEN, + provinceId: v.province.id, + districtId: v.district.id, + subDistrictId: v.subDistrict.id, + zipCode: v.zipCode, + email: v.email, + telephoneNo: v.telephoneNo, + name: v.name, + status: undefined, + taxNo: v.taxNo, + nameEN: v.nameEN, + legalPersonNo: v.legalPersonNo, + registerName: v.registerName, + registerDate: new Date(v.registerDate), + authorizedCapital: v.authorizedCapital, + employmentOffice: v.employmentOffice, + bussinessType: v.bussinessType, + bussinessTypeEN: v.bussinessTypeEN, + jobPosition: v.jobPosition, + jobPositionEN: v.jobPositionEN, + jobDescription: v.jobDescription, + saleEmployee: v.saleEmployee, + payDate: new Date(v.payDate), + wageRate: v.wageRate, + }); + }); +} + onMounted(async () => { const resultStats = await getStatsCustomer(); - const resultList = await fetchList(); + const resultList = await fetchList({ includeBranch: true }); if (resultStats) statsCustomerType.value = resultStats; - if (resultList) listCustomer.value = resultList; + console.log(resultList); - console.log(listCustomer.value); + if (resultList) listCustomer.value = resultList.result; }); @@ -322,10 +389,11 @@ onMounted(async () => { :style="`grid-template-columns: repeat(${$q.screen.lt.sm ? '1' : '4'}, 1fr)`" > @@ -654,6 +744,29 @@ onMounted(async () => { indexTab !== undefined && formData.customerBranch?.[indexTab] " + v-model:employment-office=" + formData.customerBranch[indexTab].employmentOffice + " + v-model:bussiness-type=" + formData.customerBranch[indexTab].bussinessType + " + v-model:bussiness-type-en=" + formData.customerBranch[indexTab].bussinessTypeEN + " + v-model:job-position=" + formData.customerBranch[indexTab].jobPosition + " + v-model:job-position-en=" + formData.customerBranch[indexTab].jobPositionEN + " + v-model:job-description=" + formData.customerBranch[indexTab].jobDescription + " + v-model:sale-employee=" + formData.customerBranch[indexTab].saleEmployee + " + v-model:pay-date="formData.customerBranch[indexTab].payDate" + v-model:wage-rate="formData.customerBranch[indexTab].wageRate" separator dense outlined