shiy 1 жил өмнө
parent
commit
e87e57ee6b

+ 177 - 174
src/views/purchase/apply/add/index.vue

@@ -1,189 +1,192 @@
 <script>
-import useColumns from "./columns";
-import { EXIST } from "@/api/business/purchase/catalogue";
-import { SAVE } from "@/api/business/purchase/apply";
-import { tax, unit, currency } from "@/components/popover-select-v2/fetch";
+  import useColumns from "./columns";
+  import {EXIST} from "@/api/business/purchase/catalogue";
+  import {SAVE} from "@/api/business/purchase/apply";
+  import {tax, unit, currency} from "@/components/popover-select-v2/fetch";
 
-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
-  }
-};
+  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 {
-  name: "AddDrawer",
-  props: {
-    dict: {
-      type: Object,
+  export default {
+    name: "AddDrawer",
+    props: {
+      dict: {
+        type: Object,
+      },
     },
-  },
-  components: {
-    ElSuperForm: () => import("@/components/super-form/index.vue"),
-    ElSuperTable: () => import("@/components/super-table/index.vue"),
-    ElPopoverSelectV2: () => import("@/components/popover-select-v2/index.vue"),
-  },
-  data() {
-    const {
-      TabColumns,
-      TableColumns,
-      TabColumns: [
-        {
-          item: { key: tabName },
-        },
-      ],
-    } = useColumns();
-    const rules = this.$init.rules([...TabColumns, ...TableColumns]);
-    const params = this.$init.params([...TabColumns, ...TableColumns]);
-    return {
-      title: "新 增",
-      width: "100%",
-      visible: false,
-      loading: false,
-      rules: rules,
-      params: params,
-      tabName: tabName,
-      TabColumns: TabColumns,
-      TableColumns: TableColumns,
-    };
-  },
-  computed: {},
-  watch: {},
-  methods: {
-    //
-    async changeMaterialName(prop) {
-      const { selectData } = prop;
-      const {
-        puOrg,
-        customer,
-        supplier,
-        currency,
-        currencyCode,
-        currencyName,
-      } = this.params;
-      const { nickName: createByName } = this.$store.state.user;
-      if (selectData.length) {
-        this.params[this.tabName].splice(-1);
-      }
-      for (const item of selectData) {
-        this.loading = true;
-        const { tax: taxName, unitName, code: materialCode } = item;
-        // task 1
-        const { ntaxrate } = await tax(taxName);
-        // task 2
-        const {
-          id: puUnit,
-          code: puUnitCode,
-          name: puUnitName,
-        } = await unit(unitName);
-        // task 3
-        const {
-          recentlyPrice = "0",
-          isApprovalFirst = "N",
-          isPriceAdjustment = "N",
-        } = await fetchExist({ puOrg, customer, supplier, materialCode });
-        this.loading = false;
-        await this.onRowAdd(this.tabName, {
-          ...item,
-          currency: currency,
-          currencyCode: currencyCode,
-          currencyName: currencyName,
-          unit: puUnit,
-          unitCode: puUnitCode,
-          unitName: puUnitName,
-          puUnit: puUnit,
-          puUnitCode: puUnitCode,
-          puUnitName: puUnitName,
-          recentlyPrice,
-          isApprovalFirst,
-          isPriceAdjustment,
-          tax: Number(ntaxrate === "0E-8" ? 0 : ntaxrate),
-          createByName: createByName,
-          updateByName: createByName,
-          id: null,
-        });
-      }
+    components: {
+      ElSuperForm: () => import("@/components/super-form/index.vue"),
+      ElSuperTable: () => import("@/components/super-table/index.vue"),
+      ElPopoverSelectV2: () => import("@/components/popover-select-v2/index.vue"),
     },
-    //
-    async onOpen() {
-      this.visible = true;
+    data() {
       const {
-        deptId: puDept,
-        deptName: puDeptName,
-        name: buyer,
-        nickName: buyerName,
-      } = this.$store.state.user;
-      const { id, code, name } = await currency("人民币");
-      this.params.currency = id;
-      this.params.currencyCode = code;
-      this.params.currencyName = name;
-      this.params.buyer = buyer;
-      this.params.buyerName = buyerName;
-      this.params.puDept = puDept;
-      this.params.puDeptName = puDeptName;
+        TabColumns,
+        TableColumns,
+        TabColumns: [
+          {
+            item: {key: tabName},
+          },
+        ],
+      } = useColumns();
+      const rules = this.$init.rules([...TabColumns, ...TableColumns]);
+      const params = this.$init.params([...TabColumns, ...TableColumns]);
+      return {
+        title: "新 增",
+        width: "100%",
+        visible: false,
+        loading: false,
+        rules: rules,
+        params: params,
+        tabName: tabName,
+        TabColumns: TabColumns,
+        TableColumns: TableColumns,
+      };
     },
-    //
-    async onHide() {
-      const { TabColumns, TableColumns } = useColumns();
-      this.visible = false;
-      this.params = this.$init.params([...TabColumns, ...TableColumns]);
-    },
-    //
-    async onRowAdd(prop, pushParams = {}) {
-      this.$refs.superForm.validate(async (valid) => {
-        if (valid) {
-          const { TabColumns } = this;
-          const { TableColumns } = TabColumns.find(
-            ({ item: { key } }) => key === prop
-          );
-          this.params[prop].push({
-            delFlag: "0",
-            ...this.$init.params(TableColumns),
-            ...pushParams,
+    computed: {},
+    watch: {},
+    methods: {
+      //
+      async changeMaterialName(prop) {
+        const {selectData} = prop;
+        const {
+          puOrg,
+          customer,
+          supplier,
+          currency,
+          currencyCode,
+          currencyName,
+        } = this.params;
+        const {nickName: createByName} = this.$store.state.user;
+        if (selectData.length) {
+          this.params[this.tabName].splice(-1);
+        }
+        for (const item of selectData) {
+          this.loading = true;
+          const {tax: taxName, unitName, code: materialCode} = item;
+          // task 1
+          const {ntaxrate} = await tax(taxName);
+          // task 2
+          const {
+            id: puUnit,
+            code: puUnitCode,
+            name: puUnitName,
+          } = await unit(unitName);
+          // task 3
+          const {
+            recentlyPrice = "0",
+            isApprovalFirst = "N",
+            isPriceAdjustment = "N",
+          } = await fetchExist({puOrg, customer, supplier, materialCode, customerName: ""});
+          this.loading = false;
+          await this.onRowAdd(this.tabName, {
+            ...item,
+            currency: currency,
+            currencyCode: currencyCode,
+            currencyName: currencyName,
+            unit: puUnit,
+            unitCode: puUnitCode,
+            unitName: puUnitName,
+            puUnit: puUnit,
+            puUnitCode: puUnitCode,
+            puUnitName: puUnitName,
+            recentlyPrice,
+            isApprovalFirst,
+            isPriceAdjustment,
+            tax: Number(ntaxrate === "0E-8" ? 0 : ntaxrate),
+            createByName: createByName,
+            updateByName: createByName,
+            id: null,
           });
         }
-      });
-    },
-    //
-    async onRowRemove(prop, scope) {
-      const { $index } = scope;
-      this.params[prop].splice($index, 1);
-    },
-    //
-    async useSubmit(prop) {
-      this.$refs[prop].validate(async (valid) => {
-        if (valid) {
-          try {
-            this.loading = true;
-            const { msg, code } = await SAVE(this.params);
-            if (code === 200) {
-              this.onHide();
-              this.$emit("success");
-              this.$notify.success(msg);
+      },
+      //
+      async onOpen() {
+        this.visible = true;
+        const {
+          deptId: puDept,
+          deptName: puDeptName,
+          name: buyer,
+          nickName: buyerName,
+        } = this.$store.state.user;
+        const {id, code, name} = await currency("人民币");
+        this.params.currency = id;
+        this.params.currencyCode = code;
+        this.params.currencyName = name;
+        this.params.buyer = buyer;
+        this.params.buyerName = buyerName;
+        this.params.puDept = puDept;
+        this.params.puDeptName = puDeptName;
+      },
+      //
+      async onHide() {
+        const {TabColumns, TableColumns} = useColumns();
+        this.visible = false;
+        this.params = this.$init.params([...TabColumns, ...TableColumns]);
+      },
+      //
+      async onRowAdd(prop, pushParams = {}) {
+        // this.$refs.superForm.validate(async (valid) => {
+        //   if (valid) {
+            const {TabColumns} = this;
+            const {TableColumns} = TabColumns.find(
+              ({item: {key}}) => key === prop
+            );
+            this.params[prop].push({
+              delFlag: "0",
+              ...this.$init.params(TableColumns),
+              ...pushParams,
+            });
+        //   }
+        // });
+      },
+      //
+      async onRowRemove(prop, scope) {
+        const {$index} = scope;
+        this.params[prop].splice($index, 1);
+      },
+      //
+      async useSubmit(prop) {
+        this.$refs[prop].validate(async (valid) => {
+          if (valid) {
+            try {
+              this.loading = true;
+              const {msg, code} = await SAVE(this.params);
+              if (code === 200) {
+                this.onHide();
+                this.$emit("success");
+                this.$notify.success(msg);
+              }
+            } catch (err) {
+              // catch
+              console.error(err);
+            } finally {
+              // finally
+              this.loading = false;
             }
-          } catch (err) {
-            // catch
-            console.error(err);
-          } finally {
-            // finally
-            this.loading = false;
+          } else {
+            return false;
           }
-        } else {
-          return false;
-        }
-      });
+        });
+      },
+    },
+    created() {
+    },
+    mounted() {
+    },
+    destroyed() {
     },
-  },
-  created() {},
-  mounted() {},
-  destroyed() {},
-};
+  };
 </script>
 <template>
   <el-button v-bind="$attrs" v-on="$listeners" @click="onOpen">

+ 247 - 239
src/views/purchase/apply/edit/index.vue

@@ -1,257 +1,264 @@
 <script>
-import useColumns from "./columns";
-import { EXIST } from "@/api/business/purchase/catalogue";
-import { ITEM, SAVE } from "@/api/business/purchase/apply";
-import { tax, unit, currency } from "@/components/popover-select-v2/fetch";
+  import useColumns from "./columns";
+  import {EXIST} from "@/api/business/purchase/catalogue";
+  import {ITEM, SAVE} from "@/api/business/purchase/apply";
+  import {tax, unit, currency} from "@/components/popover-select-v2/fetch";
 
-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
-  }
-};
+  const fetchExist = async (prop) => {
+    try {
+      debugger
+      // try
+      const {code, data} = await EXIST(prop);
+      if (code === 200) return data;
+    } catch (err) {
+      // catch
+      console.error(err);
+    } finally {
+      // finally
+    }
+  };
 
-export default {
-  name: "EditDrawer",
-  props: {
-    dict: {
-      type: Object,
+  export default {
+    name: "EditDrawer",
+    props: {
+      dict: {
+        type: Object,
+      },
+      selectData: {
+        type: [Array],
+        require: true,
+      },
     },
-    selectData: {
-      type: [Array],
-      require: true,
+    components: {
+      ElSuperForm: () => import("@/components/super-form/index.vue"),
+      ElSuperTable: () => import("@/components/super-table/index.vue"),
+      ElPopoverSelectV2: () => import("@/components/popover-select-v2/index.vue"),
     },
-  },
-  components: {
-    ElSuperForm: () => import("@/components/super-form/index.vue"),
-    ElSuperTable: () => import("@/components/super-table/index.vue"),
-    ElPopoverSelectV2: () => import("@/components/popover-select-v2/index.vue"),
-  },
-  data() {
-    const {
-      TabColumns,
-      TableColumns,
-      TabColumns: [
-        {
-          item: { key: tabName },
+    data() {
+      const {
+        TabColumns,
+        TableColumns,
+        TabColumns: [
+          {
+            item: {key: tabName},
+          },
+        ],
+      } = useColumns();
+      const rules = this.$init.rules([...TabColumns, ...TableColumns]);
+      const params = this.$init.params([...TabColumns, ...TableColumns]);
+      return {
+        title: "编 辑",
+        width: "100%",
+        visible: false,
+        loading: false,
+        rules: rules,
+        params: params,
+        tabName: tabName,
+        TabColumns: TabColumns,
+        TableColumns: TableColumns,
+      };
+    },
+    computed: {
+      disabled: {
+        get() {
+          const {
+            selectData,
+            selectData: [{status} = {}],
+          } = this.$props;
+          if (selectData.length !== 1) {
+            return true;
+          }
+          if (selectData.length === 1 && status === "1") {
+            return true;
+          }
+          if (selectData.length === 1 && status === "2") {
+            return true;
+          }
+        },
+        set() {
         },
-      ],
-    } = useColumns();
-    const rules = this.$init.rules([...TabColumns, ...TableColumns]);
-    const params = this.$init.params([...TabColumns, ...TableColumns]);
-    return {
-      title: "编 辑",
-      width: "100%",
-      visible: false,
-      loading: false,
-      rules: rules,
-      params: params,
-      tabName: tabName,
-      TabColumns: TabColumns,
-      TableColumns: TableColumns,
-    };
-  },
-  computed: {
-    disabled: {
-      get() {
+      },
+      priceApply: {
+        get() {
+          this.params.priceApplyItems = this.params.priceApplyItems.map(
+            (item, index) => ({
+              ...item,
+              $index: index,
+            })
+          );
+          return {
+            priceApplyItems: this.params.priceApplyItems.filter(
+              ({delFlag}) => delFlag !== "2"
+            ),
+          };
+        },
+        set() {
+        },
+      },
+    },
+    watch: {},
+    methods: {
+      //
+      async changeMaterialName(prop) {
+        console.log('prop', prop);
+        const {selectData} = prop;
         const {
-          selectData,
-          selectData: [{ status } = {}],
-        } = this.$props;
-        if (selectData.length !== 1) {
-          return true;
+          puOrg,
+          customer,
+          customerName,
+          supplier,
+          currency,
+          currencyCode,
+          currencyName,
+        } = this.params;
+        console.log('selectData', selectData)
+        const {nickName: createByName} = this.$store.state.user;
+        if (selectData.length) {
+          this.params[this.tabName].splice(-1);
         }
-        if (selectData.length === 1 && status === "1") {
-          return true;
-        }
-        if (selectData.length === 1 && status === "2") {
-          return true;
+        for (const item of selectData) {
+          console.log('item', item)
+          this.loading = true;
+          const {tax: taxName, unitName, code: materialCode} = item;
+          // task 1
+          const {ntaxrate} = await tax(taxName);
+          // task 2
+          const {
+            id: puUnit,
+            code: puUnitCode,
+            name: puUnitName,
+          } = await unit(unitName);
+          // task 3
+          const {
+            recentlyPrice = "0",
+            isApprovalFirst = "N",
+            isPriceAdjustment = "N",
+          } = await fetchExist({puOrg, customer, supplier, materialCode, customerName: ""});
+          this.loading = false;
+          await this.onRowAdd(this.tabName, {
+            ...item,
+            currency: currency,
+            currencyCode: currencyCode,
+            currencyName: currencyName,
+            unit: puUnit,
+            unitCode: puUnitCode,
+            unitName: puUnitName,
+            puUnit: puUnit,
+            puUnitCode: puUnitCode,
+            puUnitName: puUnitName,
+            recentlyPrice,
+            isApprovalFirst,
+            isPriceAdjustment,
+            tax: Number(ntaxrate === "0E-8" ? 0 : ntaxrate),
+            createByName: createByName,
+            updateByName: createByName,
+            id: null,
+          });
         }
       },
-      set() {},
-    },
-    priceApply: {
-      get() {
-        this.params.priceApplyItems = this.params.priceApplyItems.map(
-          (item, index) => ({
-            ...item,
-            $index: index,
-          })
-        );
-        return {
-          priceApplyItems: this.params.priceApplyItems.filter(
-            ({ delFlag }) => delFlag !== "2"
-          ),
-        };
+      //
+      async fetchItem(prop) {
+        try {
+          // try
+          this.loading = true;
+          const {tabName, TabColumns} = this;
+          const {TableColumns} = TabColumns.find(
+            ({item: {key}}) => key === tabName
+          );
+          const {code, data} = await ITEM(prop);
+          if (code === 200) {
+            this.params = data;
+            this.params.priceApplyItems = data.priceApplyItems.map((item) => ({
+              ...this.$init.params(TableColumns),
+              ...item,
+            }));
+            return true;
+          } else {
+            return false;
+          }
+        } catch (err) {
+          // catch
+          console.error(err);
+        } finally {
+          // finally
+          this.loading = false;
+        }
       },
-      set() {},
-    },
-  },
-  watch: {},
-  methods: {
-    //
-    async changeMaterialName(prop) {
-      console.log('prop',prop);
-      const { selectData } = prop;
-      const {
-        puOrg,
-        customer,
-        supplier,
-        currency,
-        currencyCode,
-        currencyName,
-      } = this.params;
-      console.log('selectData', selectData)
-      const { nickName: createByName } = this.$store.state.user;
-      if (selectData.length) {
-        this.params[this.tabName].splice(-1);
-      }
-      for (const item of selectData) {
-        console.log('item', item)
-        this.loading = true;
-        const { tax: taxName, unitName, code: materialCode } = item;
-        // task 1
-        const { ntaxrate } = await tax(taxName);
-        // task 2
+      //
+      async onOpen() {
         const {
-          id: puUnit,
-          code: puUnitCode,
-          name: puUnitName,
-        } = await unit(unitName);
-        // task 3
+          selectData: [{id}],
+        } = this.$props;
+        this.visible = await this.fetchItem(id);
+      },
+      //
+      async onHide() {
+        const {TabColumns, TableColumns} = useColumns();
+        this.visible = false;
+        this.params = this.$init.params([...TabColumns, ...TableColumns]);
+      },
+      //
+      async onRowAdd(prop, pushParams = {}) {
+        this.$refs.superForm.validate(async (valid) => {
+          if (valid) {
+            const {TabColumns} = this;
+            const {TableColumns} = TabColumns.find(
+              ({item: {key}}) => key === prop
+            );
+            this.params[prop].push({
+              delFlag: "0",
+              ...this.$init.params(TableColumns),
+              ...pushParams,
+            });
+          }
+        });
+      },
+      //
+      async onRowRemove(prop, scope) {
         const {
-          recentlyPrice = "0",
-          isApprovalFirst = "N",
-          isPriceAdjustment = "N",
-        } = await fetchExist({ puOrg, customer, supplier, materialCode });
-        this.loading = false;
-        await this.onRowAdd(this.tabName, {
+          row: {$index},
+        } = scope;
+        this.params[prop] = this.params[prop].map((item, index) => ({
           ...item,
-          currency: currency,
-          currencyCode: currencyCode,
-          currencyName: currencyName,
-          unit: puUnit,
-          unitCode: puUnitCode,
-          unitName: puUnitName,
-          puUnit: puUnit,
-          puUnitCode: puUnitCode,
-          puUnitName: puUnitName,
-          recentlyPrice,
-          isApprovalFirst,
-          isPriceAdjustment,
-          tax: Number(ntaxrate === "0E-8" ? 0 : ntaxrate),
-          createByName: createByName,
-          updateByName: createByName,
-          id: null,
+          delFlag: index === $index ? "2" : item.delFlag,
+        }));
+      },
+      //
+      async useSubmit(prop) {
+        this.$refs[prop].validate(async (valid) => {
+          console.log(this.params);
+          if (valid) {
+            try {
+              this.loading = true;
+              this.params.priceApplyItems = this.params.priceApplyItems.filter(
+                (item) => item.materialName
+              );
+              const {msg, code} = await SAVE(this.params);
+              if (code === 200) {
+                this.onHide();
+                this.$emit("success");
+                this.$notify.success(msg);
+              }
+            } catch (err) {
+              // catch
+              console.error(err);
+            } finally {
+              // finally
+              this.loading = false;
+            }
+          } else {
+            return false;
+          }
         });
-      }
-    },
-    //
-    async fetchItem(prop) {
-      try {
-        // try
-        this.loading = true;
-        const { tabName, TabColumns } = this;
-        const { TableColumns } = TabColumns.find(
-          ({ item: { key } }) => key === tabName
-        );
-        const { code, data } = await ITEM(prop);
-        if (code === 200) {
-          this.params = data;
-          this.params.priceApplyItems = data.priceApplyItems.map((item) => ({
-            ...this.$init.params(TableColumns),
-            ...item,
-          }));
-          return true;
-        } else {
-          return false;
-        }
-      } catch (err) {
-        // catch
-        console.error(err);
-      } finally {
-        // finally
-        this.loading = false;
-      }
-    },
-    //
-    async onOpen() {
-      const {
-        selectData: [{ id }],
-      } = this.$props;
-      this.visible = await this.fetchItem(id);
+      },
     },
-    //
-    async onHide() {
-      const { TabColumns, TableColumns } = useColumns();
-      this.visible = false;
-      this.params = this.$init.params([...TabColumns, ...TableColumns]);
+    created() {
     },
-    //
-    async onRowAdd(prop, pushParams = {}) {
-      this.$refs.superForm.validate(async (valid) => {
-        if (valid) {
-          const { TabColumns } = this;
-          const { TableColumns } = TabColumns.find(
-            ({ item: { key } }) => key === prop
-          );
-          this.params[prop].push({
-            delFlag: "0",
-            ...this.$init.params(TableColumns),
-            ...pushParams,
-          });
-        }
-      });
+    mounted() {
     },
-    //
-    async onRowRemove(prop, scope) {
-      const {
-        row: { $index },
-      } = scope;
-      this.params[prop] = this.params[prop].map((item, index) => ({
-        ...item,
-        delFlag: index === $index ? "2" : item.delFlag,
-      }));
+    destroyed() {
     },
-    //
-    async useSubmit(prop) {
-      this.$refs[prop].validate(async (valid) => {
-        console.log(this.params);
-        if (valid) {
-          try {
-            this.loading = true;
-            this.params.priceApplyItems = this.params.priceApplyItems.filter(
-              (item) => item.materialName
-            );
-            const { msg, code } = await SAVE(this.params);
-            if (code === 200) {
-              this.onHide();
-              this.$emit("success");
-              this.$notify.success(msg);
-            }
-          } catch (err) {
-            // catch
-            console.error(err);
-          } finally {
-            // finally
-            this.loading = false;
-          }
-        } else {
-          return false;
-        }
-      });
-    },
-  },
-  created() {},
-  mounted() {},
-  destroyed() {},
-};
+  };
 </script>
 <template>
   <el-button
@@ -303,7 +310,8 @@ export default {
           :label="item.title"
           :name="item.key"
           lazy
-          ><div v-loading="loading" style="height: 600px; display: flex">
+        >
+          <div v-loading="loading" style="height: 600px; display: flex">
             <el-super-table
               v-model="priceApply[item.key]"
               :dict="dict"
@@ -345,7 +353,7 @@ export default {
 </template>
 
 <style scoped>
-::v-deep .el-table__row.is-hidden {
-  display: none;
-}
+  ::v-deep .el-table__row.is-hidden {
+    display: none;
+  }
 </style>