002201 2 年 前
コミット
837b2491fd

+ 39 - 12
src/views/purchase/apply/add/index.vue

@@ -4,8 +4,7 @@ import useData from "../hooks/data";
 import useDicts from "../hooks/dicts";
 import useWatch from "../hooks/watch";
 import useMethods from "../hooks/function";
-import useTable from "../hooks/table-function";
-import { SAVE } from "@/api/business/purchase/apply";
+import { ITEM, SAVE } from "@/api/business/purchase/apply";
 const { watchPuOrgName } = useWatch();
 
 export default {
@@ -29,28 +28,56 @@ export default {
       await fetchRefer({ _this: this, prop, type, source });
     },
     //
-    async open(prop) {
-      this.visible = true;
-      this.tabName = this.tabColumns[0].key;
-      if (prop) {
-        const { fetchItem } = useMethods();
-        this.params = await fetchItem({ _this: this, prop });
+    async fetchItem(prop) {
+      try {
+        // try
+        this.loading = true;
+        const { code, data } = await ITEM(prop);
+        if (code === 200) {
+          this.params = data;
+          return true;
+        } else {
+          return false;
+        }
+      } catch (err) {
+        // catch
+        console.error(err);
+      } finally {
+        // finally
+        this.loading = false;
       }
     },
     //
+    async open(prop) {
+      this.visible = prop ? await this.fetchItem(prop) : true;
+    },
+    //
     async hide() {
       this.visible = false;
       this.params = this.resetParams();
+      this.tabName = this.tabColumns[0].key;
     },
     //
     async useRowAdd(prop) {
-      const { add } = useTable();
-      await add({ _this: this, prop });
+      const {
+        $notify,
+        params: { tabColumns, puOrgName, supplierName },
+      } = this;
+      if (!supplierName) {
+        return $notify.info("请选择供应商");
+      }
+      if (!puOrgName) {
+        return $notify.info("请选择采购组织");
+      }
+      const { tableColumns } = tabColumns.find(
+        (element) => element.key === prop
+      );
+      this.params[prop].push(initParams(tableColumns));
     },
     //
     async useRowRemove(prop, scope) {
-      const { remove } = useTable();
-      await remove({ _this: this, prop, scope, type: "ADD" });
+      const { $index } = scope;
+      this.params[prop].splice($index, 1);
     },
     //
     async useSubmit(prop) {

+ 42 - 10
src/views/purchase/apply/edit/index.vue

@@ -4,8 +4,7 @@ import useData from "../hooks/data";
 import useDicts from "../hooks/dicts";
 import useWatch from "../hooks/watch";
 import useMethods from "../hooks/function";
-import useTable from "../hooks/table-function";
-import { SAVE } from "@/api/business/purchase/apply";
+import { ITEM, SAVE } from "@/api/business/purchase/apply";
 const { watchPuOrgName, watchPriceApplyOrgs, watchPriceApplyItems } =
   useWatch();
 
@@ -36,26 +35,59 @@ export default {
       await fetchRefer({ _this: this, prop, type, source });
     },
     //
+    async fetchItem(prop) {
+      try {
+        // try
+        this.loading = true;
+        const { code, data } = await ITEM(prop);
+        if (code === 200) {
+          this.params = data;
+          return true;
+        } else {
+          return false;
+        }
+      } catch (err) {
+        // catch
+        console.error(err);
+      } finally {
+        // finally
+        this.loading = false;
+      }
+    },
+    //
     async open(prop) {
-      this.visible = true;
-      this.tabName = this.tabColumns[0].key;
-      const { fetchItem } = useMethods();
-      this.params = await fetchItem({ _this: this, prop });
+      this.visible = await this.fetchItem(prop);
     },
     //
     async hide() {
       this.visible = false;
       this.params = this.resetParams();
+      this.tabName = this.tabColumns[0].key;
     },
     //
     async useRowAdd(prop) {
-      const { add } = useTable();
-      await add({ _this: this, prop });
+      const {
+        $notify,
+        params: { tabColumns, puOrgName, supplierName },
+      } = this;
+      if (!supplierName) {
+        return $notify.info("请选择供应商");
+      }
+      if (!puOrgName) {
+        return $notify.info("请选择采购组织");
+      }
+      const { tableColumns } = tabColumns.find(
+        (element) => element.key === prop
+      );
+      this.params[prop].push(initParams(tableColumns));
     },
     //
     async useRowRemove(prop, scope) {
-      const { remove } = useTable();
-      await remove({ _this: this, prop, scope, type: "EDIT" });
+      const { $index } = scope;
+      this.params[prop] = this.params[prop].map((item, index) => ({
+        ...item,
+        delFlag: index === $index ? "2" : item.delFlag,
+      }));
     },
     //
     async useSubmit(prop) {

+ 1 - 1
src/views/purchase/apply/hooks/function.js

@@ -1,6 +1,6 @@
+import { ITEM } from "@/api/business/purchase/apply";
 import { REFER } from "@/components/popover-select/api";
 import { EXIST } from "@/api/business/purchase/catalogue";
-import { ITEM } from "@/api/business/purchase/apply";
 
 const fetchTax = async (prop) => {
   try {

+ 0 - 32
src/views/purchase/apply/hooks/table-function.js

@@ -1,32 +0,0 @@
-import { initParams } from "@/utils/init";
-
-export default function useTable() {
-  // 新 增
-  const add = ({ _this, prop }) => {
-    const { puOrgName, supplierName } = _this.params;
-    if (!supplierName) {
-      return _this.$notify.info("请选择供应商");
-    }
-    if (!puOrgName) {
-      return _this.$notify.info("请选择采购组织");
-    }
-    const { tableColumns } = _this.tabColumns.find(
-      (element) => element.key === prop
-    );
-    _this.params[prop].push(initParams(tableColumns));
-  };
-  // 删 除
-  const remove = ({ _this, prop, scope, type }) => {
-    const { $index } = scope;
-    if (type === "ADD") {
-      _this.params[prop].splice($index, 1);
-    } else {
-      _this.params[prop] = _this.params[prop].map((item, index) => ({
-        ...item,
-        delFlag: index === $index ? "2" : item.delFlag,
-      }));
-    }
-  };
-
-  return { add, remove };
-}

+ 1 - 6
src/views/purchase/contract/add/index.vue

@@ -88,13 +88,8 @@ export default {
     //
     async hide() {
       this.visible = false;
+      this.params = resetParams();
       this.tabName = this.tabColumns[0].key;
-      this.params = initParams(FormColumns);
-      this.params.contractItemList = [];
-      this.params.contractClauseList = [];
-      this.params.contractExpenseList = [];
-      this.params.contractApplyOrgList = [];
-      this.params.contractAgreementList = [];
     },
     //
     async useRowAdd(prop) {

+ 9 - 0
src/views/purchase/contract/hooks/data.js

@@ -18,6 +18,14 @@ export default function useData(prop) {
   };
   const tabColumns = TabColumns;
   const tabName = "contractItemList";
+  const resetParams = () => ({
+    contractItemList: [],
+    contractClauseList: [],
+    contractExpenseList: [],
+    contractApplyOrgList: [],
+    contractAgreementList: [],
+    ...initParams(FormColumns),
+  });
   return {
     size,
     width,
@@ -28,5 +36,6 @@ export default function useData(prop) {
     params,
     tabColumns,
     tabName,
+    resetParams,
   };
 }

+ 1 - 6
src/views/purchase/contract/record/index.vue

@@ -89,13 +89,8 @@ export default {
     //
     async hide() {
       this.visible = false;
+      this.params = resetParams();
       this.tabName = this.tabColumns[0].key;
-      this.params = initParams(FormColumns);
-      this.params.contractItemList = [];
-      this.params.contractClauseList = [];
-      this.params.contractExpenseList = [];
-      this.params.contractApplyOrgList = [];
-      this.params.contractAgreementList = [];
     },
     //
     async useRowAdd(prop) {