// pages/ourCanteen/index.js import { imgUrl, baseUrl } from "../api/request" import { getCanteenList } from "../api/user-api"; Page({ /** * 页面的初始数据 */ data: { imgUrl: imgUrl, baseUrl: baseUrl + '/', tab: 0, item: '', canteenList: [], }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { // this.islogin(); this.canteenList(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.setData({ item: 0 }) if (this.data.loginReturnFlag) { this.setData({ loginReturnFlag: false }) this.onLoad() } }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, imageError(e) { let temp = this.data.canteenList; temp[e.currentTarget.dataset.index].canteenPhotoPath = ''; this.setData({ canteenList: temp }) }, changeItem: function (e) { if (e.currentTarget.dataset.item == 1) { wx.navigateTo({ url: '/pages/deliciousList/deliciousList' }) } else { this.setData({ item: e.currentTarget.dataset.item }) } }, changeTab: function (e) { this.setData({ tab: e.detail.current }) }, toMenu: function (e) { var canteenId = e.currentTarget.dataset.item; var canteenName = e.currentTarget.dataset.name; if (canteenId && canteenId != '') { wx.navigateTo({ url: `/pagesPublic/pages/menu/menu?canteenId=${canteenId}&canteenName=${canteenName}` }) } }, // 阻止手动拖动 catchTouchMove: function (res) { return true }, islogin() { let userid = wx.getStorageSync('userId'); if (userid === null || userid === '') { this.showDialog(); } }, showDialog() { wx.showModal({ title: '未授权', content: '您登录授权已过期,请重新录授权', showCancel: false, confirmText: '登录', success: function (res) { wx.navigateTo({ url: '/pages/login/login', }); }, }); }, back() { wx.navigateBack({ delta: 1, }) }, canteenList() { getCanteenList().then(res => { if (res.result) { let data = res.data for (let i = 0; i < data.length; i++) { const element = data[i]; var timeFrame = ""; var timeFrameinfo = []; var supplyTime = element.supplyTimeMaps.sort((a, b) => { return a.timeNode - b.timeNode }) for (let j = 0; j < supplyTime.length; j++) { const childElement = supplyTime[j]; switch (childElement.timeNode) { case 1: timeFrame += "早"; childElement.timeNode = "早上"; break case 2: timeFrame += "中"; childElement.timeNode = "中午"; break case 3: timeFrame += "晚"; childElement.timeNode = "晚上"; break case 4: timeFrame += "外卖"; childElement.timeNode = "外卖"; break } if (j != supplyTime.length - 1) { timeFrame += "/" } timeFrameinfo.push(childElement) } data[i].timeFrame = timeFrame; data[i].timeFrameinfo = timeFrameinfo; } this.setData({ canteenList: data }) } }) } })