feat: remember selected worker for product

This commit is contained in:
Methapon Metanipat 2024-10-11 11:11:16 +07:00
parent a31d95e496
commit 98c10c2fa1
2 changed files with 28 additions and 28 deletions

View file

@ -40,13 +40,6 @@ const rows = defineModel<
Required<QuotationPayload['productServiceList'][number]>[] Required<QuotationPayload['productServiceList'][number]>[]
>('rows', { required: true }); >('rows', { required: true });
const groupList = ref<
{
title: string;
product: QuotationPayload['productServiceList'][number][];
}[]
>([{ title: '', product: [] }]);
const finalDiscount = defineModel<number>('finalDiscount', { default: 0 }); const finalDiscount = defineModel<number>('finalDiscount', { default: 0 });
const summaryPrice = defineModel<{ const summaryPrice = defineModel<{
@ -181,7 +174,7 @@ function openEmployeeTable(title: string, index: number) {
!currentBtnOpen.value[0].opened[index]; !currentBtnOpen.value[0].opened[index];
} }
function groupByServiceId() { function groupByServiceId(data: typeof rows.value) {
const groupedItems: { const groupedItems: {
title: string; title: string;
product: QuotationPayload['productServiceList'][number][]; product: QuotationPayload['productServiceList'][number][];
@ -191,7 +184,7 @@ function groupByServiceId() {
let currentServiceName: string | null = null; let currentServiceName: string | null = null;
let serviceFlag: boolean = false; let serviceFlag: boolean = false;
rows.value.forEach((item) => { data.forEach((item) => {
if (item.service) { if (item.service) {
if (noServiceGroup.length > 0) { if (noServiceGroup.length > 0) {
// console.log('push p changmode'); // console.log('push p changmode');
@ -244,7 +237,7 @@ function groupByServiceId() {
}); });
} }
groupList.value = groupedItems; return groupedItems;
} }
function handleCheck( function handleCheck(
@ -259,13 +252,6 @@ function handleCheck(
} }
} }
watch(
() => rows.value,
() => {
if (rows.value.length > 0) groupByServiceId();
},
);
watch( watch(
() => summary.value, () => summary.value,
() => { () => {
@ -289,7 +275,11 @@ watch(
<template> <template>
<div class="column"> <div class="column">
<div class="full-width"> <div class="full-width">
<section v-for="(item, i) in groupList" :key="i" class="q-pb-md"> <section
v-for="(item, i) in groupByServiceId(rows)"
:key="i"
class="q-pb-md"
>
<div <div
v-if="item.title && !item.title.includes('_product')" v-if="item.title && !item.title.includes('_product')"
class="q-py-sm q-px-md bordered" class="q-py-sm q-px-md bordered"

View file

@ -401,7 +401,8 @@ function triggerProductServiceDialog() {
} }
function toggleDeleteProduct(index: number) { function toggleDeleteProduct(index: number) {
deleteItem(productServiceList.value, index); productServiceList.value.splice(index, 1);
console.log(productServiceList.value);
} }
async function assignWorkerToSelectedWorker() { async function assignWorkerToSelectedWorker() {
if (quotationFormData.value.customerBranchId) { if (quotationFormData.value.customerBranchId) {
@ -440,22 +441,31 @@ function convertToTable(nodes: Node[]) {
} }
function convertEmployeeToTable() { function convertEmployeeToTable() {
productServiceList.value.map((v) => { productServiceList.value.forEach((v) => {
if (selectedWorker.value.length === 0 && v.amount === 1) v.amount -= 1; if (selectedWorker.value.length === 0 && v.amount === 1) v.amount -= 1;
v.amount = Math.max( v.amount = Math.max(
v.amount + preSelectedWorker.value.length - selectedWorker.value.length, v.amount + preSelectedWorker.value.length - selectedWorker.value.length,
1, 1,
); );
for ( const oldWorkerId: string[] = [];
let i = 0; const newWorkerIndex: number[] = [];
i < preSelectedWorker.value.length - selectedWorker.value.length;
i++ selectedWorker.value.forEach((item, i) => {
) { if (v.workerIndex.includes(i)) oldWorkerId.push(item.id);
v.workerIndex.push(selectedWorker.value.length + i); });
} preSelectedWorker.value.forEach((item, i) => {
return v; if (selectedWorker.value.find((n) => item.id === n.id)) return;
newWorkerIndex.push(i);
});
v.workerIndex = oldWorkerId
.map((id) => preSelectedWorker.value.findIndex((item) => item.id === id))
.filter((idx) => idx !== -1)
.concat(newWorkerIndex);
}); });
refSelectZoneEmployee.value?.assignSelect( refSelectZoneEmployee.value?.assignSelect(
selectedWorker.value, selectedWorker.value,
preSelectedWorker.value, preSelectedWorker.value,