Преглед изворни кода

Merge branch 'purchaseDev' of http://172.16.100.139/new-business/drp-web into purchaseDev

002390 пре 2 година
родитељ
комит
dfbcf0e7bc

+ 26 - 2
src/views/purchase/apply/add/index.vue

@@ -24,8 +24,32 @@ export default {
   methods: {
     //
     async fetchRefer(prop, type, source) {
-      const { fetchRefer } = useMethods();
-      await fetchRefer({ _this: this, prop, type, source });
+      const { fetchTax, fetchUnit, fetchExist } = useMethods();
+      if (type === "MATERIAL_PARAM") {
+        const { puOrg, customer, supplier } = this.params;
+        const { rateCode, unitIdName, code: materialCode } = prop;
+        // task 1
+        fetchTax(rateCode).then(({ ntaxrate }) => {
+          source.tax = ntaxrate === "0E-8" ? "0.00000000" : ntaxrate;
+        });
+        // task 2
+        fetchUnit(unitIdName).then(({ id, code, name }) => {
+          source.unit = id;
+          source.unitCode = code;
+          source.unitName = name;
+          source.puUnit = id;
+          source.puUnitCode = code;
+          source.puUnitName = name;
+        });
+        // task 3
+        fetchExist({ puOrg, customer, supplier, materialCode }).then(
+          ({ recentlyPrice, isApprovalFirst, isPriceAdjustment }) => {
+            source.recentlyPrice = recentlyPrice;
+            source.isApprovalFirst = isApprovalFirst;
+            source.isPriceAdjustment = isPriceAdjustment;
+          }
+        );
+      }
     },
     //
     async fetchItem(prop) {

+ 26 - 2
src/views/purchase/apply/edit/index.vue

@@ -31,8 +31,32 @@ export default {
   methods: {
     //
     async fetchRefer(prop, type, source) {
-      const { fetchRefer } = useMethods();
-      await fetchRefer({ _this: this, prop, type, source });
+      const { fetchTax, fetchUnit, fetchExist } = useMethods();
+      if (type === "MATERIAL_PARAM") {
+        const { puOrg, customer, supplier } = this.params;
+        const { rateCode, unitIdName, code: materialCode } = prop;
+        // task 1
+        fetchTax(rateCode).then(({ ntaxrate }) => {
+          source.tax = ntaxrate === "0E-8" ? "0.00000000" : ntaxrate;
+        });
+        // task 2
+        fetchUnit(unitIdName).then(({ id, code, name }) => {
+          source.unit = id;
+          source.unitCode = code;
+          source.unitName = name;
+          source.puUnit = id;
+          source.puUnitCode = code;
+          source.puUnitName = name;
+        });
+        // task 3
+        fetchExist({ puOrg, customer, supplier, materialCode }).then(
+          ({ recentlyPrice, isApprovalFirst, isPriceAdjustment }) => {
+            source.recentlyPrice = recentlyPrice;
+            source.isApprovalFirst = isApprovalFirst;
+            source.isPriceAdjustment = isPriceAdjustment;
+          }
+        );
+      }
     },
     //
     async fetchItem(prop) {

+ 34 - 82
src/views/purchase/apply/hooks/function.js

@@ -1,103 +1,55 @@
-import { ITEM } from "@/api/business/purchase/apply";
 import { REFER } from "@/components/popover-select/api";
 import { EXIST } from "@/api/business/purchase/catalogue";
 
-const fetchTax = async (prop) => {
-  try {
-    // try
-    const { code, rows } = await REFER({
-      search: prop,
-      type: "TAX_RATE_PARAM",
-    });
-    if (code === 200) {
-      return rows[0] || {};
-    }
-  } catch (err) {
-    // catch
-    console.error(err);
-  } finally {
-    // finally
-  }
-};
-
-const fetchUnit = async (prop) => {
-  try {
-    // try
-    const { code, rows } = await REFER({
-      search: prop,
-      type: "UNIT_PARAM",
-    });
-    if (code === 200) {
-      return rows[0] || {};
-    }
-  } catch (err) {
-    // catch
-    console.error(err);
-  } finally {
-    // finally
-  }
-};
-
-const fetchExist = async (prop) => {
-  try {
-    // try
-    const { code, data } = await EXIST(prop);
-    if (code === 200) return data;
-  } catch (err) {
-    // catch
-    console.error(err);
-  } finally {
-    // finally
-  }
-};
-
 export default function useMethods() {
-  const fetchItem = async ({ _this, prop }) => {
+  const fetchTax = async (prop) => {
     try {
       // try
-      _this.loading = true;
-      const { code, data } = await ITEM(prop);
+      const { code, rows } = await REFER({
+        search: prop,
+        type: "TAX_RATE_PARAM",
+      });
       if (code === 200) {
-        return data;
+        return rows[0] || {};
       }
     } catch (err) {
       // catch
       console.error(err);
     } finally {
       // finally
-      _this.loading = false;
     }
   };
-  const fetchRefer = async ({ _this, prop, type, source }) => {
-    if (type === "MATERIAL_PARAM") {
-      const { puOrg, customer, supplier } = _this.params;
-      const { rateCode, unitIdName, code: materialCode } = prop;
-      // task 1
-      fetchTax(rateCode).then(({ ntaxrate }) => {
-        source.tax = ntaxrate === "0E-8" ? "0.00000000" : ntaxrate;
-      });
-      // task 2
-      fetchUnit(unitIdName).then(({ id, code, name }) => {
-        source.unit = id;
-        source.unitCode = code;
-        source.unitName = name;
-        source.puUnit = id;
-        source.puUnitCode = code;
-        source.puUnitName = name;
+
+  const fetchUnit = async (prop) => {
+    try {
+      // try
+      const { code, rows } = await REFER({
+        search: prop,
+        type: "UNIT_PARAM",
       });
-      // task 3
-      fetchExist({ puOrg, customer, supplier, materialCode }).then(
-        ({ recentlyPrice, isApprovalFirst, isPriceAdjustment }) => {
-          source.recentlyPrice = recentlyPrice;
-          source.isApprovalFirst = isApprovalFirst;
-          source.isPriceAdjustment = isPriceAdjustment;
-        }
-      );
+      if (code === 200) {
+        return rows[0] || {};
+      }
+    } catch (err) {
+      // catch
+      console.error(err);
+    } finally {
+      // finally
     }
   };
 
-  return {
-    fetchItem,
-    fetchRefer,
+  const fetchExist = async (prop) => {
+    try {
+      // try
+      const { code, data } = await EXIST(prop);
+      if (code === 200) return data;
+    } catch (err) {
+      // catch
+      console.error(err);
+    } finally {
+      // finally
+    }
   };
+
+  return { fetchTax, fetchUnit, fetchExist };
 }

+ 42 - 31
src/views/purchase/apply/see/index.vue

@@ -3,6 +3,7 @@ import Column from "../add/column";
 import useData from "../hooks/data";
 import useDicts from "../hooks/dicts";
 import useMethods from "../hooks/function";
+import { ITEM } from "@/api/business/purchase/apply";
 
 export default {
   name: "SeeDrawer",
@@ -15,49 +16,59 @@ export default {
     };
   },
   computed: {
-    hasPowerEdit: function () {
-      return this.$parent.$parent.hasPowerEdit;
-    },
-    hasPowerSubmit: function () {
-      return this.$parent.$parent.hasPowerSubmit;
+    root: function () {
+      return this.$parent.$parent;
     },
   },
   watch: {},
   methods: {
     //
+    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 useDelete(prop) {
-      const { useDelete } = this.$parent.$parent;
-      await useDelete(prop).then(() => this.hide());
-    },
-    //
-    async useCopy(prop) {
-      const { useCopy } = this.$parent.$parent;
-      await useCopy(prop);
-    },
-    //
-    async useEdit(prop) {
-      const { useEdit } = this.$parent.$parent;
-      await useEdit(prop);
+      await this.root
+        .useDelete(prop)
+        .then(() => {
+          this.hide();
+        })
+        .catch(() => {});
     },
     //
     async useSubmit(prop) {
-      const { useSubmit } = this.$parent.$parent;
-      await useSubmit(prop).then(() => {
-        const { id } = this.params;
-        const { fetchItem } = useMethods();
-        fetchItem({ _this: this, prop: id });
-      });
+      await this.root
+        .useSubmit(prop)
+        .then(() => {
+          this.fetchItem(this.params.id);
+        })
+        .catch(() => {});
     },
   },
   created() {},
@@ -98,11 +109,11 @@ export default {
             :size="size"
             circle
             icon="el-icon-document-copy"
-            @click="useCopy([params])"
+            @click="root.useCopy([params])"
           ></el-button>
         </el-tooltip>
         <el-tooltip
-          v-if="hasPowerEdit([params])"
+          v-if="root.hasPowerEdit([params])"
           class="item"
           effect="dark"
           content="编 辑"
@@ -112,11 +123,11 @@ export default {
             :size="size"
             circle
             icon="el-icon-edit"
-            @click="useEdit([params])"
+            @click="root.useEdit([params])"
           ></el-button>
         </el-tooltip>
         <el-tooltip
-          v-if="hasPowerSubmit([params])"
+          v-if="root.hasPowerSubmit([params])"
           class="item"
           effect="dark"
           content="审 核"