保存校验数据不能为空
// 表单提交
getDataList(code) {
let tip = this.formValidate()//校验函数
if (tip) {
this.$alert('数据校验未通过:<br/>' + tip, '提示', {
dangerouslyUseHTMLString: true,
type: 'error'
})
return false
}
this.loading = true;
this.$http({
url: this.$http.adornUrl(
"/tsubjecttotalamountapply/tsubjecttotalamountapply/totalapply"
),
method: "post",
data: this.$http.adornData({
entity: this.dataForm,
// 集中项目申请明细数据
params1: this.dataList,
params2: this.fileList,
}),
}).then(({ data }) => {
console.log(data);
if (data && data.code === 0) {
// 取消loading加载
this.loading = false;
this.$message({
message: "保存成功,请提交",
type: "success",
duration: 2000,
onClose: () => {
// this.visible = false;
},
});
this.saveFHid = data.entity.id;
console.log(this.saveFHid);
if(code===1){
this.seate()
}
} else {
this.$message.error({
message: data.msg,
onClose: () => {
this.saveFHid = "";
this.loading = false;
},
});
}
});
},
formValidate () {
let tip = ''
let start = '<font size="3" color="red">'
let end = '</font><br/>'
let detail = this.dataList
let detailLength = detail.length
let reimbursementDept = this.dataForm.isreimbursementdept
let budgetDept = this.dataForm.isbudgetdept
if (reimbursementDept && !budgetDept) {
if (detailLength) {
tip += `${start}只勾选报账部门时,预算科目信息只能为空${end}`
return tip
}
} else {
if (!detailLength) {
tip += `${start}预算科目信息不能为空${end}`
return tip
}
}
//二选一
if (!(reimbursementDept || budgetDept)) {
tip += `${start}预算责任部门、预算报账部门至少选一个${end}`
return tip
}
let detailTip = ''
for (let i = 0; i < detailLength; i++) {
let data = detail[i]
if (!data.yearmonth) {
detailTip += `${start}第${i + 1}行预算年月不能为空${end}`
}
}
let moneyTip = ''
if (budgetDept) {
for (let i = 0; i < detailLength; i++) {
let data = detail[i]
if (+data.adjustauthcostamount === 0) {
moneyTip += `${start}第${i + 1}行金额不能为0${end}`
}
}
}
return tip + detailTip + moneyTip
},