if (form.value.dataList !== undefined && form.value.dataList !== null && form.value.dataList.length > 0) { const totalDeductCommission = countTotal(form.value.refundList, 'deductCommission') // 重新计算退保扣款金额 if (props.statementType === 'Receivables') { const receivablesCommission = form.value.d.commission = countTotal(form.value.dataList, 'totalCommission') - totalDeductCommission // 初始化应收金额 const receivablesGrossProfit = receivablesCommission - countTotal(form.value.dataList, 'rebatePremium') // 初始化毛利金额 if (receivablesCommission === 0 && receivablesGrossProfit === 0) { ElNotification.error('请先完成应收对账后,再次尝试提交!') } } else if (props.statementType === 'Payables') { const payablesCommission = form.value.d.commission = countTotal(form.value.dataList, 'totalChannelCommission') - totalDeductCommission // 初始化应付金额 if (payablesCommission === 0) { ElNotification.error('请先完成应付对账后,再次尝试提交!') } } else { const postData = { policy: form.value.dataList, statement: form.value.d, refund: form.value.refundList } api.post('/statement/saveStatement', postData).then(() => { ElNotification.success('对账单保存成功') resolve() }).catch(() => { }) } } else { ElNotification.error('暂无对账单明细,请添加待对账保单!') }优化这段代码使判断通过后执行post
时间: 2023-05-26 20:03:31 浏览: 116
&& form.value.dataList.length > 0) {
// perform validation on datalist
// example: check if all objects have required fields
const requiredFields = ["name", "email", "phone"];
const hasAllRequiredFields = form.value.dataList.every(obj =>
requiredFields.every(field => obj.hasOwnProperty(field))
);
if (!hasAllRequiredFields) {
// show error message
return { valid: false, errorMsg: "All objects in datalist must have name, email, and phone fields" };
}
// additional validation checks can be added here
} else {
// show error message if datalist is empty
return { valid: false, errorMsg: "Datalist cannot be empty" };
}
阅读全文