Przeglądaj źródła

点餐逻辑变动

wangtao 2 lat temu
rodzic
commit
eb6c0fe856

+ 22 - 37
src/views/orderingFood/index.vue

@@ -11,8 +11,8 @@
     </van-row>
     <van-row class="top">
         <van-row class="timeType">
-            <van-col class="describe" v-if="hasFood">今日{{type}}菜品推荐:<span class="time">(点餐时间:{{time}})</span></van-col>
-            <van-col class="describe" v-if="!hasFood">明日早餐菜品推荐:<span class="time">(点餐时间:{{time}})</span></van-col>
+            <van-col class="describe" v-if="today">今日{{type}}菜品推荐:<span class="time">(点餐时间:{{time}})</span></van-col>
+            <van-col class="describe" v-if="!today">明日早餐菜品推荐:<span class="time">(点餐时间:{{time}})</span></van-col>
         </van-row>
         <van-row class="RecommendedDishes" gutter="43">
           <van-col  span="12" v-for="(item,index) in RecommendedDishes" :key="index" class="dishes" >
@@ -108,7 +108,7 @@ export default {
       open:false,
       orderDetails:{},
       dishes:[],
-      hasFood:undefined,
+      today:undefined,
       tjcp:false,
     };
   },
@@ -126,47 +126,38 @@ export default {
     axios.get(`https://smartpark.caih.com/dxapi/dreMenu/mDate`).then(res => { 
       let nowTime = undefined
       let nowF = undefined
-      let startTime = undefined
-      let endTime = undefined
       // 本地时间测试
         // nowTime = getNowTime().split(" ")[1].substring(0,2)
         // nowF = getNowTime().split(" ")[1].substring(3,5)
         // // nowTime  = "20"
         // // nowF  = 59
-        // startTime = getNowTime().split(" ")[0] + " 00:00:00"
-        // endTime = getNowTime().split(" ")[0] + " 18:59:59"
       // 服务器时间
+        let nowDay = new Date(Date.parse(res.data.data.split(" ")[0].replace(/-/g, '/'))).getTime() / 1000 //当天零点
+        let time1 = nowDay - 60*60*5 //前天19点
+        let time2 = nowDay + 60*60*19 - 1 //今天19点
+        let time3 = nowDay+ 60*60*43 -1 //明天19点
+        
         nowTime = res.data.data.split(" ")[1].substring(0,2)
         nowF = res.data.data.split(" ")[1].substring(3,5)
-        startTime = res.data.data.split(" ")[0] + " 00:00:00"
-        endTime = res.data.data.split(" ")[0] + " 18:59:59"
       if(0 <= nowTime && nowTime < 9){
         this.type = "早餐"
-        this.hasFood = true
+        this.today = true
         this.time = "00:00 - 09:00"
-        startTime = res.data.data.split(" ")[0] + " 00:00:00"
-        endTime = res.data.data.split(" ")[0] + " 18:59:59"
       }
       if(9<= nowTime  && nowTime < 13){
         this.type = "午餐"
-        this.hasFood = true
+        this.today = true
         this.time = "09:00 - 13:00"
-        startTime = res.data.data.split(" ")[0] + " 00:00:00"
-        endTime = res.data.data.split(" ")[0] + " 18:59:59"
       }
       if(13<= nowTime && nowTime < 19){
         this.type = "晚餐"
-        this.hasFood = true
+        this.today = true
         this.time = "13:00 - 19:00"
-        startTime = res.data.data.split(" ")[0] + " 00:00:00"
-        endTime = res.data.data.split(" ")[0] + " 18:59:59"
       }
-      if(19<= nowTime && nowF<=59){
+      if(19<= nowTime){
         this.type = "早餐"
-        this.hasFood = false
+        this.today = false
         this.time = "19:00 - 23:59"
-        startTime = res.data.data.split(" ")[0] + " 19:00:00"
-        endTime = res.data.data.split(" ")[0] + " 23:00:00"
       }
       if(this.$route.query.token){
         this.getToken()
@@ -176,24 +167,18 @@ export default {
         Toast("没有获取token信息")
       }
       //获取菜单
-      axios.get(`https://smartpark.caih.com/dxapi/dreMenu/list?current=1&size=500&type=${this.type}&isRecommend=1&status=0&startTime=${startTime}&endTime=${endTime}`).then(res => { 
+      axios.get(`https://smartpark.caih.com/dxapi/dreMenu/list?current=1&size=500&type=${this.type}&isRecommend=1&status=0`).then(res => { 
         const data = res.data.data.records
-        const arr = []
-        for(let i =0; i<data.length;i++){
-          if(startTime.split(" ")[0] == data[i].createTime.split(" ")[0]){
-            if(!this.hasFood){
-              if(data[i].createTime.split(" ")[1].split(":")[0] >= 19){
-                arr.push(data[i])
-              }
-            }else{
-              if(data[i].createTime.split(" ")[1].split(":")[0] < 19){
-                arr.push(data[i])
-              }
-            }
-            
+        let time4 = new Date(Date.parse(data[0].createTime.replace(/-/g, '/'))).getTime() / 1000//创建时间
+        if(!this.today){
+          if(time2<=time4 && time4 <= time3){
+            this.RecommendedDishes  = data
+          }
+        }else{
+          if(time1<=time4 && time4 <= time2){
+            this.RecommendedDishes  = data
           }
         }
-        this.RecommendedDishes  = arr
         if(this.RecommendedDishes.length == 0){
           this.tjcp = true
         }

+ 23 - 56
src/views/orderingFood/orderService/index.vue

@@ -43,14 +43,9 @@
               </van-col>
           </van-col>
           <van-col :span="24" class="typeList" v-for="(item,index) in typeList" :key="index" @click="change(item.name,index)">
-              <van-col :span="24" :class="index >= overTime  ? 'name' : 'noName'" v-if="day=='今日'">{{item.name}}</van-col>
-              <van-col :span="24" :class="index == 0  ? 'name' : 'noName'" v-if="day=='明日'">{{item.name}}</van-col>
+              <van-col :span="24" :class="index >= overTime  ? 'name' : 'noName'" >{{item.name}}</van-col>
+              <!-- <van-col :span="24" :class="index == 0  ? 'name' : 'noName'" v-if="day=='明日'">{{item.name}}</van-col> -->
           </van-col>
-          <!-- <van-col :span="24" class="typeList" v-for="(item,index) in typeList" :key="index" @click="change(item.name,index)">
-              <van-col :span="24" :class="overTime == 0 ? 'name' : 'noName'"  >早餐</van-col>
-              <van-col :span="24" :class="overTime == 1 ? 'name' : 'noName'"  >午餐</van-col>
-              <van-col :span="24" :class="overTime == 2 ? 'name' : 'noName'"  >晚餐</van-col>
-          </van-col> -->
         </van-popup>
       </van-row>
     </van-row>
@@ -130,6 +125,8 @@ export default {
       day:undefined,
       time1:undefined,
       time2:undefined,
+      time3:undefined,
+      time4:undefined,
       noData:false,
     };
   },
@@ -148,8 +145,6 @@ export default {
     axios.get(`https://smartpark.caih.com/dxapi/dreMenu/mDate`).then(res => {
       let nowTime = undefined
       let nowF = undefined
-      let startTime = undefined
-      let endTime = undefined
       //本地时间测试
         // nowTime = getNowTime().split(" ")[1].substring(0,2)
         // nowF = getNowTime().split(" ")[1].substring(3,5)
@@ -159,67 +154,51 @@ export default {
         // endTime = getNowTime().split(" ")[0] + " 18:59:59"
 
       //服务器时间
+        let nowDay  = new Date(Date.parse(res.data.data.split(" ")[0].replace(/-/g, '/'))).getTime() / 1000 //当天零点
         nowTime = res.data.data.split(" ")[1].substring(0,2)
         nowF = res.data.data.split(" ")[1].substring(3,5)
-        startTime = res.data.data.split(" ")[0] + " 00:00:00"
-        endTime = res.data.data.split(" ")[0] + " 18:59:59"
+        this.time1 = nowDay - 60*60*5 //前天19点
+        this.time2 = nowDay + 60*60*19 - 1 //今天19点
+        this.time3 = nowDay + 60*60*43 -1 //明天19点
       
       if(this.$store.state.canbie){
         this.typeValue = this.$store.state.canbie
         if(0<=nowTime  && nowTime < 9){
           this.overTime = 0
           this.day = "今日"
-          startTime = res.data.data.split(" ")[0] + " 00:00:00"
-          endTime = res.data.data.split(" ")[0] + " 18:59:59"
         }else if( 9<= nowTime  && nowTime < 13){
           this.overTime = 1
           this.day = "今日"
-          startTime = res.data.data.split(" ")[0] + " 00:00:00"
-          endTime = res.data.data.split(" ")[0] + " 18:59:59"
         }else if( 13<= nowTime && nowTime < 19){
           this.overTime = 2
           this.day = "今日"
-          startTime = res.data.data.split(" ")[0] + " 00:00:00"
-          endTime = res.data.data.split(" ")[0] + " 18:59:59"
         }else{
           this.overTime = 0
           this.day = "明日"
-          startTime = res.data.data.split(" ")[0] + " 19:00:00"
-          endTime = res.data.data.split(" ")[0] + " 23:59:59"
         }
       }else{
         if(nowTime < 9){
           this.typeValue = "早餐"
           this.overTime = 0
           this.day = "今日"
-          startTime = res.data.data.split(" ")[0] + " 00:00:00"
-          endTime = res.data.data.split(" ")[0] + " 18:59:59"
         }else if( 9<= nowTime  && nowTime < 13){
           this.typeValue = "午餐"
           this.overTime = 1
           this.day = "今日"
-          startTime = res.data.data.split(" ")[0] + " 00:00:00"
-         endTime = res.data.data.split(" ")[0] + " 18:59:59"
         }else if( 13<= nowTime && nowTime < 19){
           this.typeValue = "晚餐"
           this.overTime = 2
           this.day = "今日"
-          startTime = res.data.data.split(" ")[0] + " 00:00:00"
-         endTime = res.data.data.split(" ")[0] + " 18:59:59"
         }else{
           this.typeValue = "早餐"
           this.overTime = 0
           this.day = "明日"
-          startTime = res.data.data.split(" ")[0] + " 19:00:00"
-          endTime = res.data.data.split(" ")[0] + " 23:59:59"
         }
       }
-      this.time1 = startTime
-      this.time2 = endTime
       if(JSON.stringify(this.footStoreData) != '[]'){
           this.foodList = this.footStoreData
       }else{
-        this.foodMenu(this.typeValue,startTime,endTime)
+        this.foodMenu(this.typeValue)
       }
     })
     
@@ -279,25 +258,22 @@ export default {
       
     },
     /** 菜单 */
-    foodMenu(id,startTime,endTime){
+    foodMenu(id,startTime){
       this.foodList  = []
-      axios.get(`https://smartpark.caih.com/dxapi/dreMenu/list?current=1&size=500&type=${id}&status=0&status=0&startTime=${startTime}&endTime=${endTime}`).then(res => { 
-      //axios.get(`https://smartpark.caih.com/dxapi/dreMenu/list?current=1&size=500&type=${id}&status=0`).then(res => { 
+      axios.get(`https://smartpark.caih.com/dxapi/dreMenu/list?current=1&size=500&type=${id}&status=0&status=0`).then(res => { 
         const data = res.data.data.records
+        this.time4 = new Date(Date.parse(data[0].createTime.replace(/-/g, '/'))).getTime() / 1000//创建时间
         const arr = []
         for(let i =0; i<data.length;i++){
           data[i].num = 0
-          if(startTime.split(" ")[0] == data[i].createTime.split(" ")[0]){
-            if(this.day == "明日"){
-              if(data[i].createTime.split(" ")[1].split(":")[0] >= 19){
-                arr.push(data[i])
-              }
-            }else{
-              if(data[i].createTime.split(" ")[1].split(":")[0] < 19){
-                arr.push(data[i])
-              }
+          if(this.day == "明日"){
+            if(this.time2<=this.time4 && this.time4  <= this.time3){
+              arr.push(data[i])
+            }
+          }else{
+            if(this.time1<=this.time4 && this.time4  <= this.time2){
+              arr.push(data[i])
             }
-            
           }
         }
         this.foodList  = arr
@@ -309,20 +285,11 @@ export default {
     /** 餐别确定 */
     determine(){
       this.money = 0
-      if(this.day == "明日"){
-        if(this.typeColor != "早餐"){
-          Toast("请选择餐别")
-        }else{
-          this.determineShow()
-        }
+      if(this.typeColor == undefined){
+        Toast("请选择餐别")
       }else{
-        if(this.typeColor == undefined){
-          Toast("请选择餐别")
-        }else{
-          this.determineShow()
-        }
+        this.determineShow()
       }
-      
     },
     /** 餐别确认渲染 */
     determineShow(){
@@ -335,7 +302,7 @@ export default {
         }
       }
       this.typeSelect = this.typeValue
-      this.foodMenu(this.typeValue,this.time1,this.time2)
+      this.foodMenu(this.typeValue)
     },
     /** 餐别取消 */
     cancel(){