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