// 验证数组数据 对象数据
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.adjustamount === 0) {
moneyTip += `${start}第${i + 1}行金额不能为0${end}`
}
}
}
return tip + detailTip + moneyTip
},
// 保存
saveAuthDetail () {
// 判断数据是否通过验证
let tip = this.formValidate()
if (tip) {
this.$alert('数据校验未通过:<br/>' + tip, '提示', {
dangerouslyUseHTMLString: true,
type: 'error'
})
return false
}
/**
* 验证通过
* 发送数据
**/
this.dataForm.datas = this.dataList
this.$emit('newAuthDetail', this.dataForm)
}