002201 2 anni fa
parent
commit
24b66a6b83

+ 4 - 13
src/views/purchase/contract/delete/index.vue

@@ -1,5 +1,6 @@
 <script>
-import { REMOVE } from "@/api/business/purchase/contract";
+import useMethods from "../hooks/use-methods";
+
 export default {
   name: "DeleteDialog",
   data() {
@@ -16,18 +17,8 @@ export default {
         type: "info",
       })
         .then(async () => {
-          try {
-            const { msg, code } = await REMOVE(prop);
-            if (code === 200) {
-              this.$emit("success");
-              this.$notify.success(msg);
-            }
-          } catch (err) {
-            // catch
-            console.error(err);
-          } finally {
-            // finally
-          }
+          const { remove } = useMethods();
+          await remove({ _this: this, prop });
         })
         .catch((err) => {
           console.error(err);

+ 10 - 3
src/views/purchase/contract/edit/index.vue

@@ -6,8 +6,7 @@ import useTable from "../hooks/use-table";
 import useWatch from "../hooks/use-watch";
 import useMethods from "../hooks/use-methods";
 const { watchContractType } = useWatch();
-const { add, submit: tableSubmit, remove } = useTable();
-const { open, hide, submit, fetchItem, fetchRefer } = useMethods();
+
 export default {
   name: "EditDrawer",
   dicts: useDicts(Column),
@@ -24,31 +23,39 @@ export default {
   methods: {
     //
     async fetchRefer(prop, type, source) {
+      const { fetchRefer } = useMethods();
       await fetchRefer({ _this: this, prop, type, source });
     },
     //
     async open(prop) {
+      const { open, fetchItem } = useMethods();
       await open({ _this: this });
       await fetchItem({ _this: this, prop });
     },
     //
     async hide() {
+      const { hide } = useMethods();
       await hide({ _this: this });
     },
     //
     async useRowAdd(prop) {
+      const { add } = useTable();
+
       await add({ _this: this, prop });
     },
     //
     async useRowRemove(prop, scope) {
+      const { remove } = useTable();
       await remove({ _this: this, prop, scope });
     },
     //
     async useRowSubmit(prop, scope) {
-      await tableSubmit({ _this: this, prop, scope });
+      const { submit } = useTable();
+      await submit({ _this: this, prop, scope });
     },
     //
     async useSubmit(prop) {
+      const { submit } = useMethods();
       await submit({ _this: this, prop, type: "EDIT" });
     },
   },

+ 48 - 2
src/views/purchase/contract/hooks/use-methods.js

@@ -1,5 +1,12 @@
 import { REFER } from "@/components/popover-select/api";
-import { ADD, EDIT, ITEM, CODE } from "@/api/business/purchase/contract";
+import {
+  ADD,
+  EDIT,
+  ITEM,
+  CODE,
+  REMOVE,
+  TERMINATION,
+} from "@/api/business/purchase/contract";
 
 export default function useMethods() {
   const fetchCode = async ({ _this }) => {
@@ -98,5 +105,44 @@ export default function useMethods() {
       }
     });
   };
-  return { fetchCode, fetchItem, open, hide, submit, fetchRefer };
+  const remove = async ({ _this, prop }) => {
+    try {
+      // try
+      const { msg, code } = await REMOVE(prop);
+      if (code === 200) {
+        _this.$emit("success");
+        _this.$notify.success(msg);
+      }
+    } catch (err) {
+      // catch
+      console.error(err);
+    } finally {
+      // finally
+    }
+  };
+  const termination = async ({ _this, prop }) => {
+    try {
+      // try
+      const { code } = await TERMINATION({ id: prop });
+      if (code === 200) {
+        _this.$emit("success");
+        _this.$notify.success(msg);
+      }
+    } catch (err) {
+      // catch
+      console.error(err);
+    } finally {
+      // finally
+    }
+  };
+  return {
+    open,
+    hide,
+    submit,
+    remove,
+    termination,
+    fetchRefer,
+    fetchCode,
+    fetchItem,
+  };
 }

+ 23 - 2
src/views/purchase/contract/record/index.vue

@@ -5,9 +5,8 @@ import useDicts from "../hooks/use-dicts";
 import useTable from "../hooks/use-table";
 import useWatch from "../hooks/use-watch";
 import useMethods from "../hooks/use-methods";
-const { add, remove } = useTable();
 const { watchContractType } = useWatch();
-const { open, hide, submit, fetchCode, fetchRefer } = useMethods();
+
 export default {
   name: "RecordDrawer",
   dicts: useDicts(Column),
@@ -25,28 +24,50 @@ export default {
   methods: {
     //
     async fetchRefer(prop, type, source) {
+      const { fetchRefer } = useMethods();
       await fetchRefer({ _this: this, prop, type, source });
     },
     //
     async open() {
+      const { open, fetchCode } = useMethods();
       await open({ _this: this });
       await fetchCode({ _this: this });
+      const {
+        user: {
+          deptId: puDept,
+          deptName: puDeptName,
+          name: buyer,
+          nickName: buyerName,
+          orgId: puOrg,
+          orgName: puOrgName,
+        },
+      } = this.$store.state;
+      this.params.puOrg = puOrg;
+      this.params.puOrgName = puOrgName;
+      this.params.buyer = buyer;
+      this.params.buyerName = buyerName;
+      this.params.puDept = puDept;
+      this.params.puDeptName = puDeptName;
       this.params.source = "期初补录";
     },
     //
     async hide() {
+      const { hide } = useMethods();
       await hide({ _this: this });
     },
     //
     async useRowAdd(prop) {
+      const { add } = useTable();
       await add({ _this: this, prop });
     },
     //
     async useRowRemove(prop, scope) {
+      const { remove } = useTable();
       await remove({ _this: this, prop, scope });
     },
     //
     async useSubmit(prop) {
+      const { submit } = useMethods();
       await submit({ _this: this, prop, type: "ADD" });
     },
   },

+ 2 - 1
src/views/purchase/contract/see/index.vue

@@ -3,7 +3,6 @@ import Column from "../add/column";
 import useData from "../hooks/use-data";
 import useDicts from "../hooks/use-dicts";
 import useMethods from "../hooks/use-methods";
-const { open, hide, fetchItem } = useMethods();
 
 export default {
   name: "SeeDrawer",
@@ -21,11 +20,13 @@ export default {
   methods: {
     //
     async open(prop) {
+      const { open, fetchItem } = useMethods();
       await open({ _this: this });
       await fetchItem({ _this: this, prop });
     },
     //
     async hide() {
+      const { hide } = useMethods();
       await hide({ _this: this });
     },
   },

+ 4 - 14
src/views/purchase/contract/termination/index.vue

@@ -1,5 +1,6 @@
 <script>
-import { TERMINATION } from "@/api/business/purchase/contract";
+import useMethods from "../hooks/use-methods";
+
 export default {
   name: "TerminationDialog",
   data() {
@@ -16,19 +17,8 @@ export default {
         type: "info",
       })
         .then(async () => {
-          try {
-            // try
-            const { code } = await TERMINATION({ id: prop });
-            if (code === 200) {
-              this.$emit("success");
-              this.$notify.success(msg);
-            }
-          } catch (err) {
-            // catch
-            console.error(err);
-          } finally {
-            // finally
-          }
+          const { termination } = useMethods();
+          await termination({ _this: this, prop });
         })
         .catch((err) => {
           console.error(err);