Browse Source

提前1个小时能取消

zhangshuling 3 years ago
parent
commit
8c071fd955
1 changed files with 14 additions and 1 deletions
  1. 14 1
      pages/piano/piano.js

+ 14 - 1
pages/piano/piano.js

@@ -112,7 +112,7 @@ Page({
         let list = rs.list
         list.map(o => {
           o.visitDate = o.visitDate.substring(0, 10)
-          o.cancelFlag = true // 是否可以取消
+          o.cancelFlag = this.canCancel(o) // 是否可以取消
         })
         this.setData({
           'hasNextPage': rs.hasNextPage,
@@ -122,6 +122,19 @@ Page({
       })
     }
   },
+  canCancel(item) { // 判断是否能取消, 未到预约时间前都能取消,至少提前1个小时
+    let t = item.visitDate + ' ' + item.beginTime + ':00';
+ 
+
+    let vdt = new Date(t.replace(/-/g,'/'));
+    let tdt = new Date().getTime();
+    if (vdt < tdt) {
+      return false;
+    }
+    // const dayTime = 86400000;
+    const dayTime = 3600000;
+    return (vdt - tdt) >= dayTime
+  },
   doCancel: function (e) {
     let id = e.currentTarget.dataset.id
     let that = this