From 43533b549987b559761f02a6ce4fb8d88d698466 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 5 Oct 2025 10:30:48 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E3=80=90antd=E3=80=91=E3=80=90erp?= =?UTF-8?q?=20=E7=B3=BB=E7=BB=9F=E3=80=91finance/payment=20=E7=9A=84?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=202/4=EF=BC=88form=20=E9=83=A8=E5=88=86?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../erp/finance/payment/modules/form.vue | 11 ++- .../erp/finance/payment/modules/item-form.vue | 76 ++++++++++--------- 2 files changed, 48 insertions(+), 39 deletions(-) diff --git a/apps/web-antd/src/views/erp/finance/payment/modules/form.vue b/apps/web-antd/src/views/erp/finance/payment/modules/form.vue index c6caf1d84..97934ce28 100644 --- a/apps/web-antd/src/views/erp/finance/payment/modules/form.vue +++ b/apps/web-antd/src/views/erp/finance/payment/modules/form.vue @@ -86,9 +86,16 @@ const handleUpdateItems = ( ) => { formData.value.items = items; // 重新计算合计付款 - const totalPrice = items.reduce((prev, curr) => prev + curr.paymentPrice, 0); + const totalPrice = items.reduce( + (prev, curr) => prev + (curr.totalPrice || 0), + 0, + ); + const paymentPrice = items.reduce( + (prev, curr) => prev + (curr.paymentPrice || 0), + 0, + ); formData.value.totalPrice = totalPrice; - formData.value.paymentPrice = totalPrice - formData.value.discountPrice; + formData.value.paymentPrice = paymentPrice - formData.value.discountPrice; formApi.setValues({ items, totalPrice: formData.value.totalPrice, diff --git a/apps/web-antd/src/views/erp/finance/payment/modules/item-form.vue b/apps/web-antd/src/views/erp/finance/payment/modules/item-form.vue index b3b50d394..476b8e27a 100644 --- a/apps/web-antd/src/views/erp/finance/payment/modules/item-form.vue +++ b/apps/web-antd/src/views/erp/finance/payment/modules/item-form.vue @@ -114,7 +114,7 @@ const handleAddPurchaseIn = (rows: ErpPurchaseInApi.PurchaseIn[]) => { }; tableData.value.push(newItem); }); - emitUpdate(); + emit('update:items', [...tableData.value]); }; /** 添加采购退货单 */ @@ -140,7 +140,7 @@ const handleAddSaleReturn = (rows: ErpPurchaseReturnApi.PurchaseReturn[]) => { }; tableData.value.push(newItem); }); - emitUpdate(); + emit('update:items', [...tableData.value]); }; /** 删除行 */ @@ -150,47 +150,42 @@ const handleDelete = async (row: any) => { ); if (index !== -1) { tableData.value.splice(index, 1); - emitUpdate(); } -}; - -/** 发送更新事件 */ -const emitUpdate = () => { + // 通知父组件更新 emit('update:items', [...tableData.value]); }; -// TODO @AI:增加一个 handleRowChange 方法; - -// TODO @芋艿:待定! -/** 初始化行数据 */ -const initRow = (item: any) => { - if (!item.row_id) { - item.row_id = Date.now() + Math.random(); +/** 处理行数据变更 */ +const handleRowChange = (row: any) => { + const index = tableData.value.findIndex( + (item) => item.bizId === row.bizId && item.bizType === row.bizType, + ); + if (index === -1) { + tableData.value.push(row); + } else { + tableData.value[index] = row; } + emit('update:items', [...tableData.value]); }; -/** 校验表单 */ -// TODO @AI:一条有问题,就直接 throw -const validate = async () => { - const errors: string[] = []; +/** 初始化行数据 */ +const initRow = (item: any) => { + // 不需要特殊初始化 +}; +/** 表单校验 */ +const validate = () => { // 检查是否有明细 if (tableData.value.length === 0) { - errors.push('请添加付款明细'); - return errors; + throw new Error('请添加付款明细'); } - // 检查每行的付款金额 for (let i = 0; i < tableData.value.length; i++) { const item = tableData.value[i]; if (!item.paymentPrice || item.paymentPrice <= 0) { - errors.push(`第${i + 1}行的本次付款必须大于0`); + throw new Error(`第 ${i + 1} 行:本次付款必须大于0`); } } - - if (errors.length > 0) { - throw new Error(errors.join(';')); - } }; defineExpose({ validate }); @@ -205,7 +200,7 @@ defineExpose({ validate }); :disabled="disabled" :formatter="erpPriceInputFormatter" placeholder="请输入本次付款" - @change="emitUpdate" + @change="handleRowChange(row)" />