feat:【antd】【erp 系统】finance/payment 的迁移 2/4(form 部分)

This commit is contained in:
YunaiV
2025-10-05 10:30:48 +08:00
parent af29a0e29b
commit 43533b5499
2 changed files with 48 additions and 39 deletions

View File

@@ -86,9 +86,16 @@ const handleUpdateItems = (
) => { ) => {
formData.value.items = items; 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.totalPrice = totalPrice;
formData.value.paymentPrice = totalPrice - formData.value.discountPrice; formData.value.paymentPrice = paymentPrice - formData.value.discountPrice;
formApi.setValues({ formApi.setValues({
items, items,
totalPrice: formData.value.totalPrice, totalPrice: formData.value.totalPrice,

View File

@@ -114,7 +114,7 @@ const handleAddPurchaseIn = (rows: ErpPurchaseInApi.PurchaseIn[]) => {
}; };
tableData.value.push(newItem); tableData.value.push(newItem);
}); });
emitUpdate(); emit('update:items', [...tableData.value]);
}; };
/** 添加采购退货单 */ /** 添加采购退货单 */
@@ -140,7 +140,7 @@ const handleAddSaleReturn = (rows: ErpPurchaseReturnApi.PurchaseReturn[]) => {
}; };
tableData.value.push(newItem); tableData.value.push(newItem);
}); });
emitUpdate(); emit('update:items', [...tableData.value]);
}; };
/** 删除行 */ /** 删除行 */
@@ -150,47 +150,42 @@ const handleDelete = async (row: any) => {
); );
if (index !== -1) { if (index !== -1) {
tableData.value.splice(index, 1); tableData.value.splice(index, 1);
emitUpdate();
} }
}; // 通知父组件更新
/** 发送更新事件 */
const emitUpdate = () => {
emit('update:items', [...tableData.value]); emit('update:items', [...tableData.value]);
}; };
// TODO @AI增加一个 handleRowChange 方法; /** 处理行数据变更 */
const handleRowChange = (row: any) => {
// TODO @芋艿:待定! const index = tableData.value.findIndex(
/** 初始化行数据 */ (item) => item.bizId === row.bizId && item.bizType === row.bizType,
const initRow = (item: any) => { );
if (!item.row_id) { if (index === -1) {
item.row_id = Date.now() + Math.random(); tableData.value.push(row);
} else {
tableData.value[index] = row;
} }
emit('update:items', [...tableData.value]);
}; };
/** 校验表单 */ /** 初始化行数据 */
// TODO @AI一条有问题就直接 throw const initRow = (item: any) => {
const validate = async () => { // 不需要特殊初始化
const errors: string[] = []; };
/** 表单校验 */
const validate = () => {
// 检查是否有明细 // 检查是否有明细
if (tableData.value.length === 0) { if (tableData.value.length === 0) {
errors.push('请添加付款明细'); throw new Error('请添加付款明细');
return errors;
} }
// 检查每行的付款金额 // 检查每行的付款金额
for (let i = 0; i < tableData.value.length; i++) { for (let i = 0; i < tableData.value.length; i++) {
const item = tableData.value[i]; const item = tableData.value[i];
if (!item.paymentPrice || item.paymentPrice <= 0) { 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 }); defineExpose({ validate });
@@ -205,7 +200,7 @@ defineExpose({ validate });
:disabled="disabled" :disabled="disabled"
:formatter="erpPriceInputFormatter" :formatter="erpPriceInputFormatter"
placeholder="请输入本次付款" placeholder="请输入本次付款"
@change="emitUpdate" @change="handleRowChange(row)"
/> />
</template> </template>
<template #remark="{ row }"> <template #remark="{ row }">
@@ -213,7 +208,7 @@ defineExpose({ validate });
v-model:value="row.remark" v-model:value="row.remark"
:disabled="disabled" :disabled="disabled"
placeholder="请输入备注" placeholder="请输入备注"
@change="emitUpdate" @change="handleRowChange(row)"
/> />
</template> </template>
<template #actions="{ row }"> <template #actions="{ row }">
@@ -251,15 +246,22 @@ defineExpose({ validate });
</div> </div>
</div> </div>
</div> </div>
<!-- TODO @AI换成 TableAction --> <TableAction
<div v-if="!disabled" class="mt-4 flex justify-center space-x-2"> v-if="!disabled"
<a-button type="primary" @click="handleOpenPurchaseIn"> class="mt-2 flex justify-center"
+ 添加采购入库单 :actions="[
</a-button> {
<a-button type="primary" @click="handleOpenSaleReturn"> label: '添加采购入库单',
+ 添加采购退货单 type: 'default',
</a-button> onClick: handleOpenPurchaseIn,
</div> },
{
label: '添加采购退货单',
type: 'default',
onClick: handleOpenSaleReturn,
},
]"
/>
</template> </template>
</Grid> </Grid>