diff --git a/src/pages/05_quotation/QuotationFormInfo.vue b/src/pages/05_quotation/QuotationFormInfo.vue index fe774254..061220e6 100644 --- a/src/pages/05_quotation/QuotationFormInfo.vue +++ b/src/pages/05_quotation/QuotationFormInfo.vue @@ -20,7 +20,7 @@ defineEmits<{ (e: 'changePayType', type: PayCondition): void; }>(); -const props = defineProps<{ +defineProps<{ readonly?: boolean; quotationNo?: string; installmentNo?: number[]; @@ -111,42 +111,42 @@ function calculateInstallments(param: { if (param.newCount !== null && param.oldCount !== null) { const totalAmount = summaryPrice.value.finalPrice; - if (param.newCount > param.oldCount) { - const installmentAmount = +(totalAmount / param.newCount).toFixed(2); + // if (param.newCount > param.oldCount) { + // const installmentAmount = +(totalAmount / param.newCount).toFixed(2); - // Update existing - paySplit.value.forEach((payment, i) => { - if (i !== param.customIndex) { - payment.amount = installmentAmount; - amount4Show.value[i] = installmentAmount.toString(); - } - }); + // // Update existing + // paySplit.value.forEach((payment, i) => { + // if (i !== param.customIndex) { + // payment.amount = installmentAmount; + // amount4Show.value[i] = installmentAmount.toString(); + // } + // }); - // Add - for (let i = param.oldCount; i < param.newCount; i++) { - paySplit.value.push({ - no: i + 1, - amount: installmentAmount, - }); - amount4Show.value.push(installmentAmount.toString()); - } - } else if (param.newCount < param.oldCount) { - // Remove extra - paySplit.value.splice(param.newCount, param.oldCount - param.newCount); - amount4Show.value.splice(param.newCount, param.oldCount - param.newCount); + // // Add + // for (let i = param.oldCount; i < param.newCount; i++) { + // paySplit.value.push({ + // no: i + 1, + // amount: installmentAmount, + // }); + // amount4Show.value.push(installmentAmount.toString()); + // } + // } else if (param.newCount < param.oldCount) { + // // Remove extra + // paySplit.value.splice(param.newCount, param.oldCount - param.newCount); + // amount4Show.value.splice(param.newCount, param.oldCount - param.newCount); - // Recalculate - const installmentAmount = +(totalAmount / param.newCount).toFixed(2); - paySplit.value.forEach((payment, i) => { - if (i !== param.customIndex) { - payment.amount = installmentAmount; - amount4Show.value[i] = installmentAmount.toString(); - } - }); - } else if (param.newCount === param.oldCount) { + // // Recalculate + // const installmentAmount = +(totalAmount / param.newCount).toFixed(2); + // paySplit.value.forEach((payment, i) => { + // if (i !== param.customIndex) { + // payment.amount = installmentAmount; + // amount4Show.value[i] = installmentAmount.toString(); + // } + // }); + if (param.newCount === param.oldCount) { if (param.customIndex !== undefined && param.customAmount !== undefined) { paySplit.value[param.customIndex].amount = param.customAmount; - amount4Show.value[param.customIndex] = param.customAmount.toString(); + // amount4Show.value[param.customIndex] = param.customAmount.toString(); } } @@ -159,8 +159,11 @@ function calculateInstallments(param: { const remainingAmount = totalAmount - totalPreviousPayments; paySplit.value[paySplit.value.length - 1].amount = +remainingAmount.toFixed(2); - amount4Show.value[amount4Show.value.length - 1] = - (+remainingAmount.toFixed(2)).toString(); + amount4Show.value[amount4Show.value.length - 1] = commaInput( + paySplit.value[paySplit.value.length - 1].amount.toString(), + ); + // amount4Show.value[amount4Show.value.length - 1] = + // (+remainingAmount.toFixed(2)).toString(); } } } @@ -180,6 +183,15 @@ function calculateInstallments(param: { // }, // { deep: true }, // ); + +watch( + () => paySplit.value, + () => { + amount4Show.value = paySplit.value.map((payment) => + commaInput(payment.amount.toString()), + ); + }, +);