feat(editReportingData): 优化编辑行数据功能
- 添加原始数据保存功能,以便取消编辑时恢复 - 新增行数据时添加 isNew 标志,用于区分新旧数据 - 优化取消编辑逻辑,根据不同情况处理数据
Showing
1 changed file
with
26 additions
and
8 deletions
| ... | @@ -784,8 +784,11 @@ | ... | @@ -784,8 +784,11 @@ |
| 784 | }, | 784 | }, |
| 785 | logtableType: true, | 785 | logtableType: true, |
| 786 | expandRowKeys:[], | 786 | expandRowKeys:[], |
| 787 | - isFold: false | 787 | + isFold: false, |
| 788 | - | 788 | + // 用于保存原始数据 |
| 789 | + originalDetailData: {}, | ||
| 790 | + // 当前编辑行的 gnum | ||
| 791 | + currentRowKey: null, | ||
| 789 | }; | 792 | }; |
| 790 | }, | 793 | }, |
| 791 | created() { | 794 | created() { |
| ... | @@ -870,7 +873,6 @@ | ... | @@ -870,7 +873,6 @@ |
| 870 | this.$router.go(-1); | 873 | this.$router.go(-1); |
| 871 | }, | 874 | }, |
| 872 | addNewItem() { | 875 | addNewItem() { |
| 873 | - console.log(this.detailData.at(-1)) | ||
| 874 | let orderNum = this.detailData.at(-1) === undefined ? 1 : this.detailData.at(-1).gnum + 1 | 876 | let orderNum = this.detailData.at(-1) === undefined ? 1 : this.detailData.at(-1).gnum + 1 |
| 875 | this.detailData.push({ | 877 | this.detailData.push({ |
| 876 | "gnum":orderNum, | 878 | "gnum":orderNum, |
| ... | @@ -890,7 +892,8 @@ | ... | @@ -890,7 +892,8 @@ |
| 890 | "qty": 0, | 892 | "qty": 0, |
| 891 | "remark": "", | 893 | "remark": "", |
| 892 | "totalPrice": 0, | 894 | "totalPrice": 0, |
| 893 | - "unit": "" | 895 | + "unit": "", |
| 896 | + "isNew": true // 添加 isNew 标志 | ||
| 894 | }) | 897 | }) |
| 895 | this.$nextTick(()=>{ | 898 | this.$nextTick(()=>{ |
| 896 | this.expandRowKeys = [orderNum] | 899 | this.expandRowKeys = [orderNum] |
| ... | @@ -899,6 +902,11 @@ | ... | @@ -899,6 +902,11 @@ |
| 899 | updateRow(row){ | 902 | updateRow(row){ |
| 900 | if (this.expandRowKeys.length > 0) return | 903 | if (this.expandRowKeys.length > 0) return |
| 901 | this.expandRowKeys = [row.gnum] | 904 | this.expandRowKeys = [row.gnum] |
| 905 | + this.currentRowKey = row.gnum; // 设置当前行的 gnum | ||
| 906 | + | ||
| 907 | + // 保存原始数据 | ||
| 908 | + this.originalDetailData[row.gnum] = { ...row }; | ||
| 909 | + | ||
| 902 | let obj = {} | 910 | let obj = {} |
| 903 | for (let key in row) { | 911 | for (let key in row) { |
| 904 | obj[key] = row[key] | 912 | obj[key] = row[key] |
| ... | @@ -942,10 +950,20 @@ | ... | @@ -942,10 +950,20 @@ |
| 942 | this.getTotalNumber() | 950 | this.getTotalNumber() |
| 943 | }) | 951 | }) |
| 944 | }, | 952 | }, |
| 945 | - cancelEditRowData(index){ | 953 | + cancelEditRowData(index) { |
| 946 | - this.expandRowKeys = [] | 954 | + this.expandRowKeys = []; |
| 947 | - if(index!==0){ | 955 | + if (index !== undefined) { |
| 948 | - this.detailData.splice(index) | 956 | + const gnum = this.detailData[index].gnum; |
| 957 | + if (this.detailData[index].isNew) { | ||
| 958 | + // 如果是新添加的项,则删除该项 | ||
| 959 | + this.detailData.splice(index, 1); | ||
| 960 | + } else { | ||
| 961 | + // 否则,恢复原始数据 | ||
| 962 | + if (this.originalDetailData[gnum]) { | ||
| 963 | + this.detailData[index] = { ...this.originalDetailData[gnum] }; | ||
| 964 | + delete this.originalDetailData[gnum]; // 删除保存的原始数据 | ||
| 965 | + } | ||
| 966 | + } | ||
| 949 | } | 967 | } |
| 950 | }, | 968 | }, |
| 951 | 969 | ... | ... |
-
Please register or login to post a comment