@@ -151,6 +158,37 @@ watch(
+ (code = v)"
+ />
+ (code = v)"
+ />
{
const branchStore = useMyBranch();
const defaultFormData: CustomerCreate = {
+ code: '',
status: 'CREATED',
personName: '',
customerType: 'CORP',
@@ -106,6 +107,7 @@ export const useCustomerForm = defineStore('form-customer', () => {
state.value.customerImageUrl = `${apiBaseUrl}/customer/${id}/image`;
resetFormData.registeredBranchId = data.registeredBranchId;
+ resetFormData.code = data.code;
resetFormData.status = data.status;
resetFormData.customerType = data.customerType;
resetFormData.customerName = data.customerName;
@@ -190,7 +192,11 @@ export const useCustomerForm = defineStore('form-customer', () => {
if (state.value.dialogType === 'info') return;
if (state.value.dialogType === 'create') {
- return await customerStore.create(currentFormData.value);
+ const _data = await customerStore.create(currentFormData.value);
+
+ if (_data) await assignFormData(_data.id);
+
+ return;
}
if (!state.value.editCustomerId) {
@@ -199,8 +205,10 @@ export const useCustomerForm = defineStore('form-customer', () => {
);
}
+ const { code: _, ...payload } = currentFormData.value;
+
const _data = await customerStore.editById(state.value.editCustomerId, {
- ...currentFormData.value,
+ ...payload,
status:
currentFormData.value.status !== 'CREATED'
? currentFormData.value.status
diff --git a/src/stores/customer/index.ts b/src/stores/customer/index.ts
index 5c12e578..d0b50eb2 100644
--- a/src/stores/customer/index.ts
+++ b/src/stores/customer/index.ts
@@ -182,11 +182,6 @@ const useCustomerStore = defineStore('api-customer', () => {
const attachment = payload.customerBranch?.map((v) => v.file);
- payload.customerBranch = payload.customerBranch?.map((v) => {
- delete v['code'];
- return { ...v };
- });
-
if (payload.customerBranch?.length) {
for (let i = 0; i < payload.customerBranch?.length; i++) {
delete payload.customerBranch[i].file;
@@ -240,7 +235,7 @@ const useCustomerStore = defineStore('api-customer', () => {
const attachment = payload.customerBranch?.map((v) => v.file);
payload.customerBranch = payload.customerBranch?.map((v) => {
- const { code, ...rest } = v;
+ const { code: _code, ...rest } = v;
return { ...rest };
});
diff --git a/src/stores/customer/types.ts b/src/stores/customer/types.ts
index 1995bf7b..9268e52d 100644
--- a/src/stores/customer/types.ts
+++ b/src/stores/customer/types.ts
@@ -96,6 +96,7 @@ export type CustomerBranchCreate = {
};
export type CustomerCreate = {
+ code: string;
customerBranch?: (CustomerBranchCreate & { id?: string })[];
taxNo?: string | null;
customerNameEN: string;