fix: select worker does not update select product worker

This commit is contained in:
Methapon2001 2025-01-06 10:41:26 +07:00
parent 724ef84ed6
commit 8c80cf036d

View file

@ -212,34 +212,43 @@ function handleCheck(
index: number, index: number,
data: QuotationPayload['productServiceList'][number], data: QuotationPayload['productServiceList'][number],
) { ) {
const equals = data.amount === data.workerIndex.length;
const target = data.workerIndex.indexOf(index); const target = data.workerIndex.indexOf(index);
if (target > -1) { if (target > -1) {
data.amount -= 1;
data.workerIndex.splice(target, 1); data.workerIndex.splice(target, 1);
if (equals) data.amount -= 1;
} else { } else {
data.workerIndex.push(index); data.workerIndex.push(index);
data.amount += 1; if (equals) data.amount += 1;
} }
data.amount = Math.max(data.workerIndex.length, data.amount);
} }
watch( watch(
() => props.employeeRows, () => props.employeeRows,
(a, b) => { (current, before) => {
if (a === undefined || b === undefined) return; if (current === undefined || before === undefined) return;
const removed = b.findIndex( rows.value.forEach((items) => {
(c) => !a.find((d) => JSON.stringify(c) === JSON.stringify(d)), const mapping = items.workerIndex.map((v) => before[v]);
); const incoming = current.filter(
(lhs) =>
!before.find((rhs) => {
console.log(lhs, rhs);
return JSON.stringify(lhs) === JSON.stringify(rhs);
}),
);
const selected = mapping.concat(incoming);
if (a.length < b.length) { items.workerIndex = selected
rows.value.forEach((p) => { .map((lhs) =>
const maxValue = Math.max(...p.workerIndex); current.findIndex((rhs) => {
if (removed !== -1) { return JSON.stringify(lhs) === JSON.stringify(rhs);
p.workerIndex = p.workerIndex.map((i) => (i > removed ? i - 1 : i)); }),
} )
p.workerIndex = p.workerIndex.filter((i) => i !== maxValue); .filter((v) => v !== -1);
}); items.amount = items.workerIndex.length;
} });
}, },
); );