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

添加招标任务状态刷新

xiaodai2022 пре 3 година
родитељ
комит
f9139afc99
1 измењених фајлова са 72 додато и 26 уклоњено
  1. 72 26
      src/views/purchaseIn/workbench/detail.vue

+ 72 - 26
src/views/purchaseIn/workbench/detail.vue

@@ -172,10 +172,15 @@
               show-overflow-tooltip
             >
               <template slot-scope="scope">
-                <el-tag type="''" :size="'mini'" v-if="scope.row.bargain_status === '0'"
+                <el-tag
+                  type="''"
+                  :size="'mini'"
+                  v-if="scope.row.bargain_status === '0'"
                   >新建信息</el-tag
                 >
-                <el-tag type="danger" :size="'mini'" v-else>历史信息,需确认</el-tag>
+                <el-tag type="danger" :size="'mini'" v-else
+                  >历史信息,需确认</el-tag
+                >
               </template></el-table-column
             >
 
@@ -283,6 +288,8 @@ export default {
   },
   data() {
     return {
+      num: 60,
+      timer: null,
       loading: false,
       showModel: false,
       tableData: [],
@@ -308,7 +315,11 @@ export default {
   mounted() {
     this.initForm();
   },
-
+  beforeDestroy() {
+    if (this.timer) {
+      clearInterval(this.timer);
+    }
+  },
   methods: {
     async initForm() {
       this.editType = "wait";
@@ -324,41 +335,76 @@ export default {
     },
 
     async initData() {
-      this.loading = true;
       const { code, message, data } = await asyncRequest.detail({
         infoNo: this.queryId,
       });
-      this.loading = false;
       if (code === 0) {
-        this.sitem = JSON.parse(JSON.stringify(data));
-        const { status, can } = this.sitem;
-        if (can && can.length > 0) {
-          let can_name = "",
-            can_id_arr = [],
-            is_metal = false;
-          can.forEach((e, i) => {
-            can_name += i == 0 ? e.name : `_${e.name}`;
-            can_id_arr.push(e.id);
-            if (e.id === "6") {
-              is_metal = true;
-            }
-          });
-          this.sitem.is_metal = is_metal;
-          this.sitem.can_id_arr = can_id_arr;
-
-          this.sitem.can_name = can_name;
-        } else {
-          this.sitem.can_id_arr = [];
-          this.sitem.can_name = "";
-        }
+        const { status } = data;
         this.status = status;
+        this.sitem = JSON.parse(JSON.stringify(data));
+        const { can } = this.sitem;
+        this.sitem.is_metal = "";
+        this.sitem.can_id_arr = [];
+        this.sitem.can_name = "";
+        let can_name = "",
+          can_id_arr = [],
+          is_metal = false;
+        can.forEach((e, i) => {
+          can_name += i == 0 ? e.name : `_${e.name}`;
+          can_id_arr.push(e.id);
+          if (e.id === "6") {
+            is_metal = true;
+          }
+        });
+        this.sitem.is_metal = is_metal;
+        this.sitem.can_id_arr = can_id_arr;
+        this.sitem.can_name = can_name;
         this.getNewTime();
+        await this.well_timer();
       } else if (code >= 100 && code <= 104) {
         await this.logout();
       } else {
         this.$message.warning(message);
       }
     },
+    async well_timer() {
+      this.timer = setInterval(async () => {
+        if (this.num !== 0) {
+          this.num--;
+        } else {
+          if (this.timer) {
+            const { code, status, message } = await this.repeat_initData();
+            if (code === 0 && status === "1") {
+              this.num = 60;
+            } else if (code === 0 && status !== "1") {
+              this.status = status;
+              this.clearTime();
+            } else if (code >= 100 && code <= 104) {
+              this.clearTime();
+              await this.logout();
+            } else {
+              this.clearTime();
+              this.$message.warning(message);
+            }
+          }
+        }
+      }, 1000);
+    },
+    clearTime() {
+      if (this.timer) {
+        clearInterval(this.timer);
+        this.num = 0;
+      }
+    },
+    async repeat_initData() {
+      const { code, message, data } = await asyncRequest.detail({
+        infoNo: this.queryId,
+      });
+      const { status } = data;
+      const res = { code, status, message };
+
+      return res;
+    },
     getNewTime() {
       this.newTime = new Date().valueOf();
     },