// pages/store/index.js /** * 店铺管理 */ 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({ /** * 页面的初始数据 */ data: { shopLogo: '', changeShopShow: false, changeShopValue: '', shops: [], todayOrderNum: 0, todayOrderTotal: 0, saleOrderTotal: 0, boolOnline: false, loaded:false, shopAdminMemberId: null, userId: null }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { const that=this }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function() { }, attached:function(){ }, /** * 生命周期函数--监听页面显示 */ onShow: function() { console.log('onshow') let that = this that.getCurrentShopData() }, /** * 生命周期函数--监听页面隐藏 */ onHide: function() { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function() { }, /** * 用户点击右上角分享 */ onShareAppMessage: function() { }, gridClick(e) { const { name } = e.currentTarget.dataset switch (name) { case 'product': { wx.switchTab({ url: '/pages/goods/goods-list', }) break } case 'business': { wx.navigateTo({ url: '/pages/store/businessSetting', }) break } case 'orderquery': { wx.switchTab({ url: '/pages/order/index', }) break } case 'shopsetting': { wx.navigateTo({ url: '/pages/shop/shop-edit', }) break } case 'aftersale':{ wx.navigateTo({ url: '/pages/aftersale/index', }) break } case 'withdrawApply':{ wx.navigateTo({ url: '/pages/fund/withdrawApply', }) break } case 'withdrawAccount':{ wx.navigateTo({ url: '/pages/fund/withdrawAccount', }) break } case 'bill':{ wx.navigateTo({ url: '/pages/bill/index', }) } case 'statistic':{ wx.navigateTo({ url: '/pages/statistic/statisticNav', }) } } }, getO2OShops() { API_Shop.getO2OShops({ contains_current: 1 }).then(res => { this.setData({ shops: [...res], changeShopShow: true }) }) }, changeShopShowClose(e) { this.setData({ changeShopShow: false }) }, onChangeShop(e) { const { value } = e.detail this.setData({ changeShopValue: value }) const that = this API_Shop.changeLoginShop(value).then(res => { const { access_token, refresh_token, access_token_timeout, refresh_token_timeout } = res const authorInfo=app.globalData.authorInfo const now=Date.parse(new Date())/1000 app.globalData.authorInfo={...authorInfo, 'access_token':access_token, 'refresh_token':refresh_token,'refresh_token_timeout':now+refresh_token_timeout-1000,'access_token_timeout':now+access_token_timeout-1000} wx.setStorageSync('authorInfo', app.globalData.authorInfo) that.getCurrentShopData() that.setData({ changeShopShow: false }) }) }, /** 加载店铺信息 **/ getCurrentShopData(){ const that=this Common.getCurrentShopData().then(res => { console.log('res',res) that.setData({ shopLogo: app.globalData.sellerShop.shop_logo, shopName: app.globalData.sellerShop.shop_name, startTime: app.globalData.sellerShop.start_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 && curDate0||app.globalData.todayOrderTotal>0){ numDH() } function numDH() { clearTimeout() if (i < 20) { setTimeout(function () { that.setData({ todayOrderNum: i, todayOrderTotal: i, }) i++ numDH(); }, 20) } else { that.setData({ todayOrderNum: app.globalData.todayOrderNum, todayOrderTotal: app.globalData.todayOrderTotal, }) } } }, 1000); }).catch(err=>{ wx.showToast({ title:err.message, icon:'none' }) }) } })