refactor: edit defaultFormData

This commit is contained in:
Net 2024-08-21 14:42:56 +07:00
parent 98f7806a34
commit 447330bfb5

View file

@ -128,32 +128,36 @@ export const useCustomerForm = defineStore('form-customer', () => {
resetFormData.customerBranch = data.branch.map((v) => ({ resetFormData.customerBranch = data.branch.map((v) => ({
id: v.id, id: v.id,
code: v.code, code: v.code,
branchNo: v.branchNo, customerCode: '',
address: v.address,
addressEN: v.addressEN,
provinceId: v.provinceId, provinceId: v.provinceId,
districtId: v.districtId, districtId: v.districtId,
subDistrictId: v.subDistrictId, subDistrictId: v.subDistrictId,
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, wageRate: v.wageRate,
payDate: new Date(v.payDate), // Convert the string to a Date object
saleEmployee: v.saleEmployee,
jobDescription: v.jobDescription,
jobPositionEN: v.jobPositionEN,
jobPosition: v.jobPosition,
businessTypeEN: v.businessTypeEN,
businessType: v.businessType,
employmentOffice: v.employmentOffice,
telephoneNo: v.telephoneNo,
email: v.email,
addressEN: v.addressEN,
address: v.address,
workplaceEN: v.workplaceEN,
workplace: v.workplace,
status: v.status,
customerId: v.customerId,
citizenId: v.citizenId,
authorizedCapital: v.authorizedCapital,
registerDate: new Date(v.registerDate), // Convert the string to a Date object
registerNameEN: v.registerNameEN,
registerName: v.registerName,
legalPersonNo: v.legalPersonNo,
registerCompanyName: '',
statusSave: true,
file: undefined,
})); }));
currentFormData.value = structuredClone(resetFormData); currentFormData.value = structuredClone(resetFormData);
@ -164,34 +168,42 @@ export const useCustomerForm = defineStore('form-customer', () => {
currentFormData.value.customerBranch?.push({ currentFormData.value.customerBranch?.push({
id: '', id: '',
code: '', code: currentFormData.value.customerBranch?.[0].code,
branchNo: customerCode: '',
(currentFormData.value.customerBranch?.at(-1)?.branchNo || 0) + 1,
address: '',
addressEN: '',
provinceId: '', provinceId: '',
districtId: '', districtId: '',
subDistrictId: '', subDistrictId: '',
zipCode: '',
email: '',
telephoneNo: '',
name: '',
status: 'CREATED',
taxNo: '',
nameEN: '',
legalPersonNo: '',
registerName: '',
registerDate: new Date(),
authorizedCapital: '',
employmentOffice: '',
bussinessType: '',
bussinessTypeEN: '',
jobPosition: '',
jobPositionEN: '',
jobDescription: '',
saleEmployee: '',
payDate: new Date(),
wageRate: 0, wageRate: 0,
payDate: new Date(), // Convert the string to a Date object
saleEmployee: '',
jobDescription: '',
jobPositionEN: '',
jobPosition: '',
businessTypeEN: '',
businessType: '',
employmentOffice: '',
telephoneNo: '',
email: '',
addressEN: '',
address: '',
workplaceEN: '',
workplace: '',
status: 'CREATED',
customerId: '',
citizenId:
currentFormData.value.customerBranch?.[0].citizenId === null
? ''
: currentFormData.value.customerBranch?.[0].citizenId,
authorizedCapital: '',
registerDate: new Date(), // Convert the string to a Date object
registerNameEN: '',
registerName: '',
legalPersonNo:
currentFormData.value.customerBranch?.[0].legalPersonNo === null
? ''
: currentFormData.value.customerBranch?.[0].legalPersonNo,
registerCompanyName: '',
file: undefined,
}); });
state.value.branchIndex = state.value.branchIndex =
(currentFormData.value.customerBranch?.length || 0) - 1; (currentFormData.value.customerBranch?.length || 0) - 1;
@ -249,40 +261,43 @@ export const useCustomerForm = defineStore('form-customer', () => {
export const useCustomerBranchForm = defineStore('form-customer-branch', () => { export const useCustomerBranchForm = defineStore('form-customer-branch', () => {
const customerStore = useCustomerStore(); const customerStore = useCustomerStore();
const defaultFormData: CustomerBranchCreate = { const defaultFormData: CustomerBranchCreate & { id?: string } = {
id: '',
code: '', code: '',
branchNo: 1, customerCode: '',
address: '',
addressEN: '',
provinceId: '', provinceId: '',
districtId: '', districtId: '',
subDistrictId: '', subDistrictId: '',
zipCode: '',
email: '',
telephoneNo: '',
name: '',
status: 'CREATED',
taxNo: '',
nameEN: '',
legalPersonNo: '',
registerName: '',
registerDate: new Date(),
authorizedCapital: '',
employmentOffice: '',
bussinessType: '',
bussinessTypeEN: '',
jobPosition: '',
jobPositionEN: '',
jobDescription: '',
saleEmployee: '',
payDate: new Date(),
wageRate: 0, wageRate: 0,
payDate: new Date(), // Convert the string to a Date object
saleEmployee: '',
jobDescription: '',
jobPositionEN: '',
jobPosition: '',
businessTypeEN: '',
businessType: '',
employmentOffice: '',
telephoneNo: '',
email: '',
addressEN: '',
address: '',
workplaceEN: '',
workplace: '',
status: 'CREATED',
customerId: '',
citizenId: '',
authorizedCapital: '',
registerDate: new Date(), // Convert the string to a Date object
registerNameEN: '',
registerName: '',
legalPersonNo: '',
registerCompanyName: '',
statusSave: false,
file: undefined,
}; };
let resetFormData = structuredClone(defaultFormData); let resetFormData = structuredClone(defaultFormData);
const currentFormData = ref<CustomerBranchCreate>( const currentFormData = ref<CustomerBranchCreate & { id?: string }>(
structuredClone(defaultFormData), structuredClone(defaultFormData),
); );
@ -312,34 +327,37 @@ export const useCustomerBranchForm = defineStore('form-customer-branch', () => {
if (!_data) return; if (!_data) return;
resetFormData = { resetFormData = {
id: _data.id,
code: _data.code, code: _data.code,
branchNo: _data.branchNo, customerCode: '',
address: _data.address,
addressEN: _data.addressEN,
provinceId: _data.provinceId, provinceId: _data.provinceId,
districtId: _data.districtId, districtId: _data.districtId,
subDistrictId: _data.subDistrictId, subDistrictId: _data.subDistrictId,
zipCode: _data.zipCode,
email: _data.email,
telephoneNo: _data.telephoneNo,
name: _data.name,
status: undefined,
taxNo: _data.taxNo,
nameEN: _data.nameEN,
legalPersonNo: _data.legalPersonNo,
registerName: _data.registerName,
registerDate: new Date(_data.registerDate),
authorizedCapital: _data.authorizedCapital,
employmentOffice: _data.employmentOffice,
bussinessType: _data.bussinessType,
bussinessTypeEN: _data.bussinessTypeEN,
jobPosition: _data.jobPosition,
jobPositionEN: _data.jobPositionEN,
jobDescription: _data.jobDescription,
saleEmployee: _data.saleEmployee,
payDate: new Date(_data.payDate),
wageRate: _data.wageRate, wageRate: _data.wageRate,
payDate: new Date(_data.payDate), // Convert the string to a Date object
saleEmployee: _data.saleEmployee,
jobDescription: _data.jobDescription,
jobPositionEN: _data.jobPositionEN,
jobPosition: _data.jobPosition,
businessTypeEN: _data.businessTypeEN,
businessType: _data.businessType,
employmentOffice: _data.employmentOffice,
telephoneNo: _data.telephoneNo,
email: _data.email,
addressEN: _data.addressEN,
address: _data.address,
workplaceEN: _data.workplaceEN,
workplace: _data.workplace,
status: 'CREATED',
customerId: _data.customerId,
citizenId: _data.citizenId,
authorizedCapital: _data.authorizedCapital,
registerDate: new Date(), // Convert the string to a Date object
registerNameEN: _data.registerNameEN,
registerName: _data.registerName,
legalPersonNo: _data.legalPersonNo,
registerCompanyName: '',
statusSave: false,
file: undefined,
}; };
currentFormData.value = structuredClone(resetFormData); currentFormData.value = structuredClone(resetFormData);