Explorar o código

feat(业务组件): 完善业务组件表单的增删改功能

liujt hai 8 meses
pai
achega
d3869360e3

+ 14 - 3
src/BIZComponents/processSubmitDialog/components/businessComponent.vue

@@ -335,7 +335,8 @@ export default {
             endPlace: '',
             transportationWay: '',
             price: '',
-            remark: ''
+            remark: '',
+            type: 'add'
         }
         return {
             form: {},
@@ -421,6 +422,7 @@ export default {
             });
         },
         addRow() {
+            this.type = 'add';
             this.visible = true;
 
         },
@@ -428,11 +430,15 @@ export default {
             this.visible = false;
         },
         editRow(row, index) {
+            this.type = 'edit';
             console.log('编辑行', row, index);
             this.currentItem = row;
             this.currentIndex = index;
             this.visible = true;
-            // this.form = JSON.parse(JSON.stringify(row));
+            this.form = JSON.parse(JSON.stringify(row));
+        },
+        delRow(index) {
+            this.tableData.splice(index, 1);
         },
         async save() {
             try {
@@ -440,7 +446,12 @@ export default {
                 console.log('表单验证通过');
                 // 深拷贝form对象,避免引用问题
                 const newForm = JSON.parse(JSON.stringify(this.form));
-                this.tableData.push(newForm);
+                if(this.type === 'add') {
+                    this.tableData.push(newForm);
+                } else {
+                    this.tableData[this.currentIndex] = newForm;
+                }
+                
                 this.handleClose(); // 保存后关闭弹窗
                 // 重置form
                 this.form = {};