refactor: assign worker to selectedWorker

This commit is contained in:
Thanaphon Frappet 2024-10-08 16:42:17 +07:00
parent 4e736a2c96
commit d5c8ce85b6
3 changed files with 62 additions and 7 deletions

View file

@ -85,6 +85,7 @@ const {
currentFormState: quotationFormState,
newWorkerList,
fileItemNewWorker,
quotationFull,
} = storeToRefs(quotationForm);
const refSelectZoneEmployee = ref<InstanceType<typeof SelectZone>>();
@ -94,6 +95,7 @@ const selectedCustomer = ref('');
const toggleWorker = ref(true);
const rows = ref<Node[]>([]);
const branchId = ref('');
const currentQuotationId = ref<string | undefined>(undefined);
const date = ref();
const preSelectedWorker = ref<Employee[]>([]);
@ -317,7 +319,14 @@ function triggerProductServiceDialog() {
function toggleDeleteProduct(index: number) {
deleteItem(productServiceList.value, index);
console.log(index);
}
async function assignWorkerToSelectedWorker() {
quotationFormData.value.worker.forEach((value, i) => {
const tempValue: Employee | undefined = workerList.value.find(
(v) => v.id === value.id,
);
if (tempValue !== undefined) selectedWorker.value.push(tempValue);
});
}
function convertToTable(nodes: Node[]) {
@ -432,6 +441,8 @@ onMounted(async () => {
date.value = Date.now();
currentQuotationId.value = urlParams.get('quotationId') || undefined;
quotationFormData.value.customerBranchId =
urlParams.get('customerBranchId') || '';
@ -456,7 +467,18 @@ onMounted(async () => {
const retEmp = await customerStore.fetchBranchEmployee(
quotationFormData.value.customerBranchId,
);
if (retEmp) workerList.value = workerList.value = retEmp.data.result;
if (retEmp) workerList.value = retEmp.data.result;
}
if (
currentQuotationId.value !== undefined &&
quotationFormState.value.mode !== 'create'
) {
await quotationForm.assignFormData(
currentQuotationId.value,
quotationFormState.value.mode,
);
await assignWorkerToSelectedWorker();
}
pageState.isLoaded = true;