feat: customer branch function + add
This commit is contained in:
parent
aba1d61e01
commit
75246296ae
2 changed files with 95 additions and 2 deletions
|
|
@ -30,6 +30,7 @@ import {
|
||||||
Customer,
|
Customer,
|
||||||
CustomerUpdate,
|
CustomerUpdate,
|
||||||
CustomerBranch,
|
CustomerBranch,
|
||||||
|
CustomerBranchCreate,
|
||||||
} from 'stores/customer/types';
|
} from 'stores/customer/types';
|
||||||
import { onMounted } from 'vue';
|
import { onMounted } from 'vue';
|
||||||
import FormPerson from 'src/components/02_personnel-management/FormPerson.vue';
|
import FormPerson from 'src/components/02_personnel-management/FormPerson.vue';
|
||||||
|
|
@ -38,8 +39,15 @@ import FormEmployeeHealthCheck from 'src/components/03_customer-management/FormE
|
||||||
import { dialog } from 'src/stores/utils';
|
import { dialog } from 'src/stores/utils';
|
||||||
|
|
||||||
const userCustomer = useCustomerStore();
|
const userCustomer = useCustomerStore();
|
||||||
const { create, getStatsCustomer, fetchList, editById, fetchListById } =
|
const {
|
||||||
userCustomer;
|
create,
|
||||||
|
getStatsCustomer,
|
||||||
|
fetchList,
|
||||||
|
editById,
|
||||||
|
fetchListById,
|
||||||
|
createBranch,
|
||||||
|
deleteBranchById,
|
||||||
|
} = userCustomer;
|
||||||
const formData = ref<CustomerCreate>({
|
const formData = ref<CustomerCreate>({
|
||||||
status: 'CREATED',
|
status: 'CREATED',
|
||||||
customerType: 'CORP',
|
customerType: 'CORP',
|
||||||
|
|
@ -302,6 +310,14 @@ async function onSubmit() {
|
||||||
|
|
||||||
async function onSubmitCustomerBranch() {
|
async function onSubmitCustomerBranch() {
|
||||||
dialogInputCustomerBranchForm.value = false;
|
dialogInputCustomerBranchForm.value = false;
|
||||||
|
// await createBranch();
|
||||||
|
|
||||||
|
for (const item of formData.value.customerBranch || []) {
|
||||||
|
await createBranch({
|
||||||
|
...item,
|
||||||
|
customerId: currentCustomerId.value,
|
||||||
|
});
|
||||||
|
}
|
||||||
clearForm();
|
clearForm();
|
||||||
const result = await fetchListById(currentCustomerId.value);
|
const result = await fetchListById(currentCustomerId.value);
|
||||||
if (result) {
|
if (result) {
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import {
|
||||||
BranchAttachment,
|
BranchAttachment,
|
||||||
CustomerStats,
|
CustomerStats,
|
||||||
CustomerBranch,
|
CustomerBranch,
|
||||||
|
CustomerBranchCreate,
|
||||||
} from './types';
|
} from './types';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
|
|
@ -231,6 +232,79 @@ const useCustomerStore = defineStore('api-customer', () => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function createBranch(
|
||||||
|
data: CustomerBranchCreate & { customerId: string },
|
||||||
|
flow?: {
|
||||||
|
sessionId: string;
|
||||||
|
refTransactionId: string;
|
||||||
|
transactionId: string;
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
const res = await api.post<
|
||||||
|
Customer & {
|
||||||
|
branch: CustomerBranch[];
|
||||||
|
imageUrl: string;
|
||||||
|
imageUploadUrl: string;
|
||||||
|
}
|
||||||
|
>('/customer-branch', data, {
|
||||||
|
headers: {
|
||||||
|
'X-Session-Id': flow?.sessionId,
|
||||||
|
'X-Rtid': flow?.refTransactionId,
|
||||||
|
'X-Tid': flow?.transactionId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!res) return false;
|
||||||
|
|
||||||
|
return res.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function editBranchById(
|
||||||
|
id: string,
|
||||||
|
data: Partial<CustomerBranchCreate & { customerId: string }>,
|
||||||
|
flow?: {
|
||||||
|
sessionId: string;
|
||||||
|
refTransactionId: string;
|
||||||
|
transactionId: string;
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
const res = await api.put<
|
||||||
|
Customer & {
|
||||||
|
branch: CustomerBranch[];
|
||||||
|
}
|
||||||
|
>(`'/customer-branch'/${id}`, data, {
|
||||||
|
headers: {
|
||||||
|
'X-Session-Id': flow?.sessionId,
|
||||||
|
'X-Rtid': flow?.refTransactionId,
|
||||||
|
'X-Tid': flow?.transactionId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!res) return false;
|
||||||
|
|
||||||
|
return res.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteBranchById(
|
||||||
|
id: string,
|
||||||
|
flow?: {
|
||||||
|
sessionId: string;
|
||||||
|
refTransactionId: string;
|
||||||
|
transactionId: string;
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
const res = await api.delete<Customer>(`/customer-branch/${id}`, {
|
||||||
|
headers: {
|
||||||
|
'X-Session-Id': flow?.sessionId,
|
||||||
|
'X-Rtid': flow?.refTransactionId,
|
||||||
|
'X-Tid': flow?.transactionId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!res) return false;
|
||||||
|
if (res.status === 200) return res.data;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
async function addBranchAttachment(
|
async function addBranchAttachment(
|
||||||
branchId: string,
|
branchId: string,
|
||||||
payload: BranchAttachmentCreate,
|
payload: BranchAttachmentCreate,
|
||||||
|
|
@ -303,6 +377,9 @@ const useCustomerStore = defineStore('api-customer', () => {
|
||||||
create,
|
create,
|
||||||
editById,
|
editById,
|
||||||
deleteById,
|
deleteById,
|
||||||
|
createBranch,
|
||||||
|
editBranchById,
|
||||||
|
deleteBranchById,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue