jiaxing.zhou

feat(editReportingData): 优化新增商品的校验逻辑

- 添加 lastItemValid 状态,用于记录上一次新增项是否通过校验
- 在添加新商品前,检查 lastItemValid 状态,若未通过校验则不允许新增
- 调用 RowDataEditForm 组件的 validate 方法进行校验,并更新 lastItemValid 状态
- 优化了用户体验,确保每次新增的商品信息都是完整的
......@@ -367,6 +367,17 @@
this.tableRowformData = {}
this.$emit('cancelEditRowData',this.rowDatas.row.gnum-1)
},
validate() {
return this.$refs.editRowForm.validate((valid)=>{
if(valid){
console.log("tg2")
this.$emit('updateLastItemValid', true);
}else {
console.log("wtg2")
this.$emit('updateLastItemValid', false); // 通知父组件校验未通过
}
});
},
},
};
</script>
......
......@@ -501,6 +501,7 @@
:rowDatas="props"
@cancelEditRowData="cancelEditRowData"
@rowFormDataSave="rowFormDataSave"
@updateLastItemValid="handleUpdateLastItemValid"
/>
</template>
<template v-slot:destinationCountryRegionCode="scope">
......@@ -789,6 +790,7 @@
originalDetailData: {},
// 当前编辑行的 gnum
currentRowKey: null,
lastItemValid: true, // 默认值为 true,表示没有新增项或上一次新增项通过了校验
};
},
created() {
......@@ -872,32 +874,59 @@
back() {
this.$router.go(-1);
},
addNewItem() {
let orderNum = this.detailData.at(-1) === undefined ? 1 : this.detailData.at(-1).gnum + 1
this.detailData.push({
"gnum":orderNum,
"accountBookMaterialNumber": "",
"barCode": "",
"currency": "",
"destinationCountryRegionCode": "",
"enterpriseProductCode": "",
"enterpriseProductDescribe": "",
"enterpriseProductName": "",
"legalQty": 0,
"model": "",
"netWeight": 0,
"price": 0,
"productCode": "",
"productName": "",
"qty": 0,
"remark": "",
"totalPrice": 0,
"unit": "",
"isNew": true // 添加 isNew 标志
})
this.$nextTick(()=>{
this.expandRowKeys = [orderNum]
})
//添加新商品
async addNewItem() {
// 如果上一次新增的 item 没有通过校验,则不允许新增
if (!this.lastItemValid) {
this.$message.warning('请先完善新增的商品信息');
return;
}
// 获取最后一个 item 的引用
const lastItem = this.detailData[this.detailData.length - 1];
// 如果存在上一次新增的 item,则进行校验
if (lastItem) {
// 获取 RowDataEditForm 组件的引用
const rowEditForm = this.$refs.rowEditForm;
if (rowEditForm) {
// 调用校验方法
const isValid = await rowEditForm.validate();
if (!isValid) {
this.lastItemValid = false; // 标记上一次新增的 item 未通过校验
this.$message.warning('请先完善新增的商品信息');
return;
}
}
}
// 校验通过,允许新增 item
let orderNum = this.detailData.at(-1) === undefined ? 1 : this.detailData.at(-1).gnum + 1;
this.detailData.push({
"gnum":orderNum,
"accountBookMaterialNumber": "",
"barCode": "",
"currency": "",
"destinationCountryRegionCode": "",
"enterpriseProductCode": "",
"enterpriseProductDescribe": "",
"enterpriseProductName": "",
"legalQty": 0,
"model": "",
"netWeight": 0,
"price": 0,
"productCode": "",
"productName": "",
"qty": 0,
"remark": "",
"totalPrice": 0,
"unit": "",
"isNew": true // 添加 isNew 标志
});
this.$nextTick(() => {
this.expandRowKeys = [orderNum];
console.log("next:",this.lastItemValid)
this.lastItemValid = true; // 重置标志位
});
},
updateRow(row){
if (this.expandRowKeys.length > 0) return
......@@ -951,6 +980,7 @@
})
},
cancelEditRowData(index) {
this.lastItemValid = true; // 重置标志位
this.expandRowKeys = [];
if (index !== undefined) {
const gnum = this.detailData[index].gnum;
......@@ -966,7 +996,10 @@
}
}
},
// 更新 lastItemValid
handleUpdateLastItemValid(isValid) {
this.lastItemValid = isValid;
},
//提交更新数据
submitEditedReportDatas(){
this.$refs.editForm.validate((valid) => {
......