Sfoglia il codice sorgente

feat: 定时刷新用户预约表

haopeng 2 anni fa
parent
commit
64b0b7b42c
1 ha cambiato i file con 19 aggiunte e 6 eliminazioni
  1. 19 6
      src/pages/home/detailList/index.vue

+ 19 - 6
src/pages/home/detailList/index.vue

@@ -42,14 +42,15 @@ export default {
42 42
         { orderStatus: [3, 5], color: '#A3A3A3', backgroundColor: '#F0F0F0' },
43 43
         { orderStatus: [2], color: '#FA7D22', backgroundColor: '#FEF4ED' },
44 44
         { orderStatus: [0, 1], color: '#42D351', backgroundColor: '#F5FCF5' },
45
-      ]
45
+      ],
46
+      timer: null
46 47
     };
47 48
   },
48
-  async created () { 
49
-    let resp = await api.reservedRecords()
50
-    if (resp.code === 200) {
51
-      this.orderList = resp.data
52
-    }
49
+  created () {
50
+    this.fetchOrderList()
51
+    this.timer = setInterval(() => {
52
+      this.fetchOrderList()
53
+    }, 10000)
53 54
   },
54 55
   mounted () {
55 56
     if (this.$refs.row) {
@@ -58,7 +59,19 @@ export default {
58 59
       })
59 60
     }
60 61
   },
62
+  destroyed () {
63
+    if (this.timer) {
64
+      clearInterval(this.timer)
65
+      this.timer = null
66
+    }
67
+  },
61 68
   methods: {
69
+    async fetchOrderList () {
70
+      let resp = await api.reservedRecords()
71
+      if (resp.code === 200) {
72
+        this.orderList = resp.data
73
+      }
74
+    },
62 75
     getStyleByOrderStatus (orderSource) {
63 76
       let style = null
64 77
       // 订单状态,0已预约,未支付,1已支付,待使用,2正在使用,3已结算,5已取消