Selaa lähdekoodia

营业状态判定

allen 2 vuotta sitten
vanhempi
commit
efac47cc10
2 muutettua tiedostoa jossa 47 lisäystä ja 2 poistoa
  1. 46 1
      pages/store/index.js
  2. 1 1
      pages/store/index.wxml

+ 46 - 1
pages/store/index.js

@@ -4,6 +4,7 @@
  */
 import * as API_Shop from '../../api/shop.js'
 import * as Common from '../../utils/common.js'
+import * as Util from '../../utils/util.js'
 import * as API_Passport from '../../api/passport.js'
 const app = getApp()
 Page({
@@ -17,6 +18,7 @@ Page({
     shops: [],
     todayOrderNum: 0,
     todayOrderTotal: 0,
+    boolOnline: false,
     loaded:false,
       shopAdminMemberId: null,
       userId: null
@@ -199,12 +201,55 @@ Page({
 	      shopLogo: app.globalData.sellerShop.shop_logo,
 	      shopName: app.globalData.sellerShop.shop_name,
 	      startTime: app.globalData.sellerShop.start_time,
-	      endTime: app.globalData.sellerShop.end_time,
+          endTime: app.globalData.sellerShop.end_time,
+          business_date: app.globalData.sellerShop.business_date,
 	      shop_state: app.globalData.sellerShop.shop_state,
 	      bool_o2o: app.globalData.authorInfo.bool_o2o,
           shopAdminMemberId: app.globalData.sellerShop.member_id,
           userId: app.globalData.authorInfo.uid
       })
+        var curDate = new Date();
+        //星期几判定
+        let businessDateOpen = false;
+        let business_date = app.globalData.sellerShop.business_date
+        const checkcodes = business_date.split('')
+        const today = curDate.getDay();
+        let index = 0;
+        switch (today){
+            case 0: //星期日
+                index = 6
+                break;
+            default:
+                index = today - 1;
+                break;
+        }
+        if (checkcodes[index] === "1") {
+            businessDateOpen = true;
+        }
+        //营业时间判定
+        let seOpen = false;
+        //今天日期
+        const curDay = curDate.getFullYear() + "-" + (curDate.getMonth() + 1) + "-" + curDate.getDate();
+        const startDay = curDay + " " + app.globalData.sellerShop.start_time;
+        const endDay = curDay + " " + app.globalData.sellerShop.end_time;
+
+        var sd = new Date(Date.parse(startDay.replace(/-/g,"/")));
+        var ed = new Date(Date.parse(endDay.replace(/-/g,"/")));
+
+        if (curDate>sd && curDate<ed){
+            seOpen = true;
+        }
+
+        if (businessDateOpen && seOpen && app.globalData.sellerShop.shop_state === "1"){
+            that.setData({
+                boolOnline: true
+            });
+        } else {
+            that.setData({
+                boolOnline: false
+            });
+        }
+
       console.log('begininit')
 	    that.getTabBar().init()
 		//数据加载完成后1秒展现

+ 1 - 1
pages/store/index.wxml

@@ -38,7 +38,7 @@
         <view class="business-time" wx:if="{{startTime}}">营业时间:{{filter.timeFormat(startTime)}}-{{filter.timeFormat(endTime)}}</view>
       </van-col>
       <van-col span="5" class="shop-state">
-        <van-tag plain type="{{shop_state==='1'?'success':'danger'}}" size="large">{{shop_state==='1'?'营业中':'暂停营业'}}</van-tag>
+        <van-tag plain type="{{boolOnline?'success':'danger'}}" size="large">{{boolOnline?'营业中':'暂停营业'}}</van-tag>
         <view class="exchange-store" bind:tap="getO2OShops">
           <text>切换店铺</text>
           <van-icon name="exchange" />