Browse Source

采购需求单-新增-需求日期根据需求计划改变

002390 1 year ago
parent
commit
919cb903ef
2 changed files with 79 additions and 58 deletions
  1. 12 1
      src/api/purchase/purchaseDemand.js
  2. 67 57
      src/views/purchase/PurchaseDemandList/add.vue

+ 12 - 1
src/api/purchase/purchaseDemand.js

@@ -108,4 +108,15 @@ export function saveDemandWindow(data) {
     method: 'POST',
     data: data
   })
-}
+}
+
+
+// 需求计划设置需求日期
+// /pu/setting/demandDate?planType=JJXQ
+export function SetdemandDate(params) {
+  return request({
+    url: `/pu/setting/demandDate`,
+    method: 'get',
+    params,
+  })
+}

+ 67 - 57
src/views/purchase/PurchaseDemandList/add.vue

@@ -1369,6 +1369,7 @@ import {
   queryMan,
   toOA,
   confirmSubmit,
+  SetdemandDate,
 } from "@/api/purchase/purchaseDemand.js";
 // 用于回显参照框数据
 import { getRefer } from "@/api/purchase/basic.js";
@@ -1637,67 +1638,75 @@ export default {
   },
   methods: {
     // 默认需求日期根据当天星期几判断
-    dafaultDate() {
-      // 获取当前时间
-      let date = new Date();
-      //获取当前时间的年份转为字符串
-      let year = date.getFullYear().toString();
-      //获取月份,由于月份从0开始,此处要加1,判断是否小于10,如果是在字符串前面拼接'0'
-      let month =
-        date.getMonth() + 1 < 10
-          ? "0" + (date.getMonth() + 1).toString()
-          : (date.getMonth() + 1).toString(); //'04'
-      //获取天,判断是否小于10,如果是在字符串前面拼接'0'
-      let da =
-        date.getDate() < 10
-          ? "0" + date.getDate().toString()
-          : date.getDate().toString(); //'12'
-      let today = year + "-" + month + "-" + da;
-      // console.log("今天日期", today);
-      let weekDay = date.getDay();
-      // console.log("今天星期几", weekDay);
-      // 改变需求计划的判断写这里面了
-      if (this.basicForm.planType == "JJXQ") {
-        this.basicForm.demandDate = today;
-      } else {
-        if (weekDay == 0) {
-          this.basicForm.demandDate = this.getNextDate(today, 2);
-        } else if (weekDay == 1) {
-          this.basicForm.demandDate = this.getNextDate(today, 1);
-        } else if (weekDay == 2) {
-          this.basicForm.demandDate = today;
-        } else if (weekDay == 3) {
-          this.basicForm.demandDate = this.getNextDate(today, 6);
-        } else if (weekDay == 4) {
-          this.basicForm.demandDate = this.getNextDate(today, 5);
-        } else if (weekDay == 5) {
-          this.basicForm.demandDate = this.getNextDate(today, 4);
-        } else if (weekDay == 6) {
-          this.basicForm.demandDate = this.getNextDate(today, 3);
+    async dafaultDate() {
+      try {
+        let { planType, demandDate } = this.basicForm;
+        console.log();
+        let { code, data } = await SetdemandDate({ planType });
+        if (code == 200) {
+          this.basicForm.demandDate = new Date(data).Format("yyyy-MM-dd");
         }
-        // console.log(this.getNextDate(today, 2))
-      }
+      } catch (error) {}
+
+      // // 获取当前时间
+      // let today = new Date().Format("yyyy-MM-dd");
+      // // //获取当前时间的年份转为字符串
+      // // let year = date.getFullYear().toString();
+      // // //获取月份,由于月份从0开始,此处要加1,判断是否小于10,如果是在字符串前面拼接'0'
+      // // let month =
+      // //   date.getMonth() + 1 < 10
+      // //     ? "0" + (date.getMonth() + 1).toString()
+      // //     : (date.getMonth() + 1).toString(); //'04'
+      // // //获取天,判断是否小于10,如果是在字符串前面拼接'0'
+      // // let da =
+      // //   date.getDate() < 10
+      // //     ? "0" + date.getDate().toString()
+      // //     : date.getDate().toString(); //'12'
+      // // let today = year + "-" + month + "-" + da;
+      // // console.log("今天日期", today);
+      // let weekDay = new Date(today).getDay();
+      // // 改变需求计划的判断写这里面了
+      // if (this.basicForm.planType == "JJXQ") {
+      //   this.basicForm.demandDate = today;
+      // } else {
+      //   if (weekDay == 0) {
+      //     this.basicForm.demandDate = this.getNextDate(today, 2);
+      //   } else if (weekDay == 1) {
+      //     this.basicForm.demandDate = this.getNextDate(today, 1);
+      //   } else if (weekDay == 2) {
+      //     this.basicForm.demandDate = today;
+      //   } else if (weekDay == 3) {
+      //     this.basicForm.demandDate = this.getNextDate(today, 6);
+      //   } else if (weekDay == 4) {
+      //     this.basicForm.demandDate = this.getNextDate(today, 5);
+      //   } else if (weekDay == 5) {
+      //     this.basicForm.demandDate = this.getNextDate(today, 4);
+      //   } else if (weekDay == 6) {
+      //     this.basicForm.demandDate = this.getNextDate(today, 3);
+      //   }
+      //   // console.log(this.getNextDate(today, 2))
+      // }
     },
     // 获取某天日期的下一天,默认为第二天 默认输出格式为yyyy-mm-dd
-    getNextDate(date, day = 1, format = "{y}-{m}-{d}") {
-      if (date) {
-        date = date.match(/\d+/g).join("-"); // 格式为2022年09月19日处理
-        const nDate = new Date(date);
-        nDate.setDate(nDate.getDate() + day);
+    // getNextDate(date, day = 1, format = "{y}-{m}-{d}") {
+    //   if (date) {
+    //     date = date.match(/\d+/g).join("-"); // 格式为2022年09月19日处理
+    //     const nDate = new Date(date);
+    //     nDate.setDate(nDate.getDate() + day);
 
-        const formatObj = {
-          y: nDate.getFullYear(),
-          m: nDate.getMonth() + 1,
-          d: nDate.getDate(),
-        };
-        return format.replace(/{([ymd])+}/g, (result, key) => {
-          const value = formatObj[key];
-          return value.toString().padStart(2, "0");
-        });
-      } else {
-        console.log("date格式不正确");
-      }
-    },
+    //     const formatObj = {
+    //       y: nDate.getFullYear(),
+    //       m: nDate.getMonth() + 1,
+    //       d: nDate.getDate(),
+    //     };
+    //     return format.replace(/{([ymd])+}/g, (result, key) => {
+    //       const value = formatObj[key];
+    //       return value.toString().padStart(2, "0");
+    //     });
+    //   } else {
+    //     console.log("date格式不正确");
+    //   }
+    // },
     // 改变需求计划改变需求日期
     changeplanType(val) {
       this.dafaultDate();
@@ -1709,6 +1718,7 @@ export default {
           this.basicForm.billType = "";
         }
       }
+
       if (val == "JJXQ" && this.basicForm.puDemandItemList.length != 0) {
         this.basicForm.puDemandItemList.forEach((item) => {
           item.isUrgency = "Y";