Browse Source

feat: 定时刷新用户预约表

haopeng 2 years ago
parent
commit
64b0b7b42c
1 changed files with 19 additions and 6 deletions
  1. 19 6
      src/pages/home/detailList/index.vue

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

@@ -42,14 +42,15 @@ export default {
42
         { orderStatus: [3, 5], color: '#A3A3A3', backgroundColor: '#F0F0F0' },
42
         { orderStatus: [3, 5], color: '#A3A3A3', backgroundColor: '#F0F0F0' },
43
         { orderStatus: [2], color: '#FA7D22', backgroundColor: '#FEF4ED' },
43
         { orderStatus: [2], color: '#FA7D22', backgroundColor: '#FEF4ED' },
44
         { orderStatus: [0, 1], color: '#42D351', backgroundColor: '#F5FCF5' },
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
   mounted () {
55
   mounted () {
55
     if (this.$refs.row) {
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
   methods: {
68
   methods: {
69
+    async fetchOrderList () {
70
+      let resp = await api.reservedRecords()
71
+      if (resp.code === 200) {
72
+        this.orderList = resp.data
73
+      }
74
+    },
62
     getStyleByOrderStatus (orderSource) {
75
     getStyleByOrderStatus (orderSource) {
63
       let style = null
76
       let style = null
64
       // 订单状态,0已预约,未支付,1已支付,待使用,2正在使用,3已结算,5已取消
77
       // 订单状态,0已预约,未支付,1已支付,待使用,2正在使用,3已结算,5已取消