feat: also get installment no from preset data

This commit is contained in:
Methapon Metanipat 2024-10-29 10:42:34 +07:00
parent 810b8b96ba
commit 640aac51e2
3 changed files with 26 additions and 2 deletions

View file

@ -137,7 +137,10 @@ const agentPrice = ref(false);
function getPrice(
list: typeof productServiceList.value,
filterHook?: (arg: (typeof productServiceList.value)[number]) => boolean,
filterHook?: (
item: (typeof productServiceList.value)[number],
index?: number,
) => boolean,
) {
if (filterHook) list = list.filter(filterHook);
@ -492,6 +495,23 @@ function convertToTable(nodes: Node[]) {
});
productServiceList.value = list;
quotationFormData.value.paySplitCount = Math.max(
...list.map((v) => v.installmentNo || 0),
);
quotationFormData.value.paySplit = Array.apply(
null,
new Array(quotationFormData.value.paySplitCount),
).map((_, i) => ({
no: i + 1,
amount: getPrice(list, (v) => {
return (
v.installmentNo === i + 1 ||
(i + 1 === quotationFormData.value.paySplitCount && !v.installmentNo)
);
}).finalPrice,
}));
pageState.productServiceModal = false;
}

View file

@ -95,6 +95,10 @@ function calculateInstallments(param: {
newCount: number;
oldCount: number;
}) {
if (payType.value !== 'SplitCustom' && payType.value !== 'BillSplitCustom') {
return;
}
if (param.newCount !== null && param.oldCount !== null) {
const totalAmount = summaryPrice.value.finalPrice;

View file

@ -346,7 +346,7 @@ export type QuotationPayload = {
_count: { worker: number };
discount?: number;
payBillDate?: Date | null;
paySplit: { no: number; date: string | Date; amount: number }[];
paySplit: { no: number; amount: number }[];
paySplitCount?: number | null; // int
payCondition:
| 'Full'