002201 2 år sedan
förälder
incheckning
57ee91baa9

+ 1 - 1
src/api/business/purchase/contract.js

@@ -79,7 +79,7 @@ export function TABLELIST(params, name) {
 
 export function TABLEADD(data, name) {
   return request({
-    url: `${switchUrl(name)}/add`,
+    url: `${switchUrl(name)}`,
     method: "POST",
     data: data,
   });

+ 46 - 7
src/views/purchase/contract/add/index.vue

@@ -1,7 +1,12 @@
 <script>
 import { Columns, TabColumns } from "../column";
 import { REFER } from "@/components/popover-select/api";
-import { ADD, CODE } from "@/api/business/purchase/contract";
+import {
+  ADD,
+  CODE,
+  TABLEADD,
+  TABLEROMOVE,
+} from "@/api/business/purchase/contract";
 import { initDicts, initRules, initParams } from "@/utils/init";
 
 export default {
@@ -112,8 +117,37 @@ export default {
       this.params[prop].push(initParams(tab.tableColumns));
     },
     //
-    rowDelete(prop, index) {
-      prop.splice(index, 1);
+    async rowDelete(prop, { row: { id }, $index }) {
+      if (id) {
+        try {
+          this.loading = true;
+          const { code } = await TABLEROMOVE(id, prop);
+          if (code === 200) {
+            this.fetchTable(this.params.code, prop);
+          }
+        } catch (err) {
+          // catch
+        } finally {
+          // finally
+          this.loading = false;
+        }
+      } else {
+        this.params[prop].splice($index, 1);
+      }
+    },
+    //
+    async rowSubmit(prop, { row }) {
+      try {
+        this.loading = true;
+        const { code } = this.params;
+        await TABLEADD({ ...row, contractId: code }, prop);
+      } catch (err) {
+        // catch
+        console.error(err);
+      } finally {
+        // finally
+        this.loading = false;
+      }
     },
     //
     submit(prop) {
@@ -331,7 +365,7 @@ export default {
                   <span v-else> {{ scope.row[cColumn.key] }}</span>
                 </template>
               </el-table-column>
-              <el-table-column fixed="right" label="操作" width="75">
+              <el-table-column fixed="right" label="操作" width="100">
                 <template slot="header" slot-scope="scope">
                   <el-button
                     circle
@@ -344,11 +378,16 @@ export default {
                 <template slot-scope="scope">
                   <el-button
                     circle
+                    icon="el-icon-check"
+                    :size="size"
+                    @click.native.prevent="rowSubmit(tabName, scope)"
+                  >
+                  </el-button>
+                  <el-button
+                    circle
                     icon="el-icon-minus"
                     :size="size"
-                    @click.native.prevent="
-                      rowDelete(params[tabName], scope.$index)
-                    "
+                    @click.native.prevent="rowDelete(tabName, scope)"
                   >
                   </el-button>
                 </template>

+ 29 - 26
src/views/purchase/contract/edit/index.vue

@@ -53,22 +53,23 @@ export default {
           this.tabColumns = TabColumns;
         }
         this.tabName = this.tabColumns[0].key;
+        this.fetchTable(this.params.code, this.tabName);
       },
       immediate: true,
     },
-    "params.contractItemList": {
-      handler: function (newProp, oldProp) {
-        console.log(newProp, oldProp);
-        if (newProp.length === oldProp.length) {
-          const index = newProp.findIndex(
-            (item, index) =>
-              JSON.stringify(item) === JSON.stringify(oldProp[index])
-          );
-          console.log(index);
-        }
-      },
-      deep: true,
-    },
+    // "params.contractItemList": {
+    //   handler: function (newProp, oldProp) {
+    //     console.log(newProp, oldProp);
+    //     if (newProp.length === oldProp.length) {
+    //       const index = newProp.findIndex(
+    //         (item, index) =>
+    //           JSON.stringify(item) === JSON.stringify(oldProp[index])
+    //       );
+    //       console.log(index);
+    //     }
+    //   },
+    //   deep: true,
+    // },
   },
   methods: {
     //
@@ -89,8 +90,6 @@ export default {
         const { code, data } = await ITEM(prop);
         if (code === 200) {
           this.params = data;
-          this.tabName = this.tabColumns[0].key;
-          this.fetchTable(this.params.code, this.tabName);
         }
       } catch (err) {
         // catch
@@ -145,18 +144,22 @@ export default {
       this.params[prop].push(initParams(tab.tableColumns));
     },
     //
-    async rowDelete(prop, { row: { id } }) {
-      try {
-        this.loading = true;
-        const { code } = await TABLEROMOVE(id, prop);
-        if (code === 200) {
-          this.fetchTable(this.params.code, this.tabName);
+    async rowDelete(prop, { row: { id }, $index }) {
+      if (id) {
+        try {
+          this.loading = true;
+          const { code } = await TABLEROMOVE(id, prop);
+          if (code === 200) {
+            this.fetchTable(this.params.code, prop);
+          }
+        } catch (err) {
+          // catch
+        } finally {
+          // finally
+          this.loading = false;
         }
-      } catch (err) {
-        // catch
-      } finally {
-        // finally
-        this.loading = false;
+      } else {
+        this.params[prop].splice($index, 1);
       }
     },
     //