// pages/deliciousList.js import { imgUrl } from "../api/request" import { request, baseUrl } from "../api/canteen-request" Page({ /** * 页面的初始数据 */ data: { // 图片前缀 imgUrl: imgUrl, // 服务器地址 baseUrl: baseUrl + '/', // 默认选中 currentTab: 0, // 食堂列表 canteenList: [], isLoading: false }, getDeliciousList() { var that = this; this.setData({ isLoading: true }) request({ url: '/mini/canteen/getDeliciousList', method: 'GET' }).then(res => { if (res.result) { let temp = []; if (res.data.length < 0) { this.setData({ isLoading: false }) return; } res.data.forEach(element => { if (element.deliciousList.length > 0) { temp.push(element); } }) temp.forEach(element => { element.deliciousList.forEach(item => { if (item.dishesPic) { wx.getImageInfo({ src: this.data.baseUrl + item.dishesPic, fail() { item.dishesPic = ''; that.setData({ canteenList: temp }) } }); } }); }); this.setData({ isLoading: false, canteenList: temp }) } else { this.setData({ isLoading: false }) } }) }, // 切换食堂 tabNav(e) { let currentTab = e.currentTarget.dataset.index this.setData({ currentTab }) }, // 切换食堂 handleSwiper(e) { let { current, source } = e.detail if (source === 'autoplay' || source === 'touch') { const currentTab = current this.setData({ currentTab }) } }, // 查看评论 toComment: function (e) { wx.navigateTo({ url: '/pages/commentList/commentList?dishesId=' + e.currentTarget.dataset.data.dishesId + '&commentCount=' + e.currentTarget.dataset.data.commentCount + '&compliment=' + e.currentTarget.dataset.data.compliment + '&canteenId=' + this.data.canteenList[this.data.currentTab].id }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.getDeliciousList(); // 加载字体 // wx.loadFontFace({ // family: 'DOUYU', // source: 'url("https://www.cqna.gov.cn/mnazw/applet/font/douyu.ttf")', // success: function (e) { // console.log(e, '动态加载字体成功') // }, // fail: function (e) { // console.log(e, '动态加载字体失败') // }, // }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { if (this.data.loginReturnFlag) { this.setData({ loginReturnFlag: false }) this.onLoad() } }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { return { title: '菜品榜单' } } })