保存的时候不能提交合计行:
/** 保存 */
const billSave = async () => {
contractData.formData.pmContract.process_status = 0;
if (contractData.dataSource.pmContractPayPlanList.length > 0) {
contractData.dataSource.pmContractPayPlanList =
contractData.dataSource.pmContractPayPlanList.filter((item: any) => {
return item.pay_plan != '合计';
});
}
添加一行时:
const addPlan = async (event: any) => {
if (stageDes.length != 0) {
(contractData.dataSource.pmContractPayPlanList as any).push({
// pay_plan: contractData.dataSource.pmContractPayPlanList.length + 1,
stage_msg: stageDes[0].value,
});
addPlanSum();
}
}
/** 添加付款计划合计行 */
const addPlanSum = () => {
let pay_percentage = 0;
let contract_amount = 0;
let payable_money = 0;
let amount_paid = 0;
//先把合计那行清除
contractData.dataSource.pmContractPayPlanList =
contractData.dataSource.pmContractPayPlanList.filter((item: any) => {
return item.pay_plan != '合计';
});
contractData.dataSource.pmContractPayPlanList.forEach((item: any, index: number) => {
item.pay_plan = ++index;
pay_percentage += Number(item.pay_percentage || 0);
contract_amount += Number(item.contract_amount || 0);
payable_money += Number(item.payable_money || 0);
amount_paid += Number(item.amount_paid || 0);
// contract_amount = contract_amount + Number(item.contract_amount || 0);
//从数据库取出时可能是 undefined (定义后没赋值)
//Number(undefined) 为 NaN undefined||0 是 0
});
if (contractData.dataSource.pmContractPayPlanList.length > 0) {
(contractData.dataSource.pmContractPayPlanList as any).push({
noEditor: true,
isDelete: false,
stage_msg: '',
pay_date: '',
pay_plan: '合计',
pay_percentage: pay_percentage,
contract_amount: contract_amount,
payable_money: payable_money,
amount_paid: amount_paid,
});
}
};
实时结算:
有一个监听事件:tableFormChange
/** 监听表格的输入框变化事件 */
const tableFormChange = (column: any, record: any, val: any) => {
if (
column.dataIndex === 'pay_percentage' ||
column.dataIndex === 'contract_amount' ||
column.dataIndex === 'payable_money' ||
column.dataIndex === 'amount_paid'
) {
addPlanSum();
}
};
加一条数据时
const addRow = (dataSource: any, getAttribute: any) => {
if (contractData.formData.baseContractDTO.payment_type) {
//取id
let id = '';
paymentTypeList.value.forEach((item: any) => {
if (contractData.formData.baseContractDTO.payment_type == item.code) {
id = item.id;
}
});
addPlan(id);
} else {
message.info('请选择支付形式');
}
};
减一条数据时
const deleteRow = (index: any, record: any, dataSource: any) => {
dataSource.splice(index, 1);
addPlanSum();
};
回显
if (res.data.baseContractPayplanDTOS) {
let pay_percentage = 0;
let contract_amount = 0;
let payable_money = 0;
let amount_paid = 0;
contractData.dataSource.baseContractPayplanDTOS = res.data.baseContractPayplanDTOS.map(
(item: any, index: number) => {
item.pay_plan = ++index;
item.isDelete = false;
pay_percentage += Number(item.pay_percentage || 0);
contract_amount += Number(item.contract_amount || 0);
payable_money += Number(item.payable_money || 0);
amount_paid += Number(item.amount_paid || 0);
return item;
},
);
if (contractData.dataSource.baseContractPayplanDTOS.length > 0) {
(contractData.dataSource.baseContractPayplanDTOS as any).push({
noEditor: true,
isDelete: false,
stage_msg: '',
pay_date: '',
pay_plan: '合计',
pay_percentage: pay_percentage,
contract_amount: contract_amount,
payable_money: payable_money,
amount_paid: amount_paid,
});
}
}