Commit 9ba539d81ceaf6c81ac6492adc613ba65d472dc5

Authored by pengye
1 parent e8ba8844

提前点餐:判断当前时间是否在当前预订的餐段时间内,过期不可下单

@@ -34,6 +34,7 @@ Page({ @@ -34,6 +34,7 @@ Page({
34 themeColor:'', 34 themeColor:'',
35 textColor:'', 35 textColor:'',
36 navColor:'', 36 navColor:'',
  37 + isOrder:false,// 是否可以下单(超过该预订的餐段截止时间,不可以下单)(true 超过了 false 在时间内,可以预订)
37 }, 38 },
38 /** 39 /**
39 * 生命周期函数--监听页面加载 40 * 生命周期函数--监听页面加载
@@ -56,8 +57,7 @@ Page({ @@ -56,8 +57,7 @@ Page({
56 console.log('options', { 57 console.log('options', {
57 ...obj 58 ...obj
58 }); 59 });
59 - this.getCheckCookList(obj)  
60 - this.getDetail() 60 + this.getDetail(obj)
61 }, 61 },
62 // 获取点菜列表 62 // 获取点菜列表
63 getCheckCookList(options) { 63 getCheckCookList(options) {
@@ -74,7 +74,7 @@ Page({ @@ -74,7 +74,7 @@ Page({
74 }) 74 })
75 }) 75 })
76 }, 76 },
77 - getDetail() { 77 + getDetail(obj) {
78 App.Reserve.Detail({ 78 App.Reserve.Detail({
79 openid: getApp().openid, 79 openid: getApp().openid,
80 rid: this.data.options.rid 80 rid: this.data.options.rid
@@ -97,18 +97,49 @@ Page({ @@ -97,18 +97,49 @@ Page({
97 } else { 97 } else {
98 dateSmart = util.unixtoTime(reserev.ddate, this.data.tpls[this.data.current].timeStr) 98 dateSmart = util.unixtoTime(reserev.ddate, this.data.tpls[this.data.current].timeStr)
99 } 99 }
  100 + let daily=reserev.seller.daily;
  101 + let time;
  102 + switch (reserev.ddate_solt) {
  103 + case '1':
  104 + time=daily.morning.split("-")[1];
  105 + break;
  106 + case '2':
  107 + time=daily.noon.split("-")[1];
  108 + break;
  109 + case '3':
  110 + time=daily.night.split("-")[1];
  111 + break;
  112 + }
  113 + let timeHour=time.split(":")[0];//预订日期--预订餐段的截止时间--小时
  114 + let timeMinute=time.split(":")[1];//预订日期--预订餐段的截止时间--分钟
  115 + const date = new Date(reserev.ddate*1000);
  116 + const year = date.getFullYear();
  117 + const month = date.getMonth() + 1;
  118 + const day = date.getDate();
  119 + // 是否可以下单(超过该预订的餐段截止时间,不可以下单)
  120 + let isOrder=this.isCurrentTimeGreaterThan(year,month,day,timeHour*1,timeMinute*1)
100 this.setData({ 121 this.setData({
101 seller: { 122 seller: {
102 soltName: reserev.soltName, 123 soltName: reserev.soltName,
103 date: dateSmart, 124 date: dateSmart,
104 tableNum, 125 tableNum,
105 tablesText 126 tablesText
106 - } 127 + },
  128 + isOrder
107 }) 129 })
  130 + setTimeout(() => {
  131 + this.getCheckCookList(obj)
  132 + },100)
108 }).catch(res => { 133 }).catch(res => {
109 console.log(res, '详情请求失败'); 134 console.log(res, '详情请求失败');
110 }) 135 })
111 }, 136 },
  137 + // 判断是否超过该预订的餐段截止时间
  138 + isCurrentTimeGreaterThan(year, month, day, hour, minute) {
  139 + const currentTime = new Date();
  140 + const targetTime = new Date(year, month - 1, day, hour, minute);
  141 + return currentTime > targetTime;
  142 + },
112 // 过滤数据 143 // 过滤数据
113 formatCookList(list) { 144 formatCookList(list) {
114 // 获取所有的规格 145 // 获取所有的规格
@@ -312,7 +343,7 @@ Page({ @@ -312,7 +343,7 @@ Page({
312 console.log(cookbooklist); 343 console.log(cookbooklist);
313 this.setData({ 344 this.setData({
314 cookbooklist, 345 cookbooklist,
315 - noData:(num*1)>0?false:true, 346 + noData:((num*1)>0 && !this.data.isOrder)?false:true,//菜品数量大于0 && 在当前预订的餐段时间内
316 probablyPrice, 347 probablyPrice,
317 vipProbablyPrice 348 vipProbablyPrice
318 }) 349 })