// pages/home/index.js const app = getApp(); import QRCode from '../../utils/weapp-qrcode'; Page({ /** * 页面的初始数据 */ data: { height: app.globalData.height * 2 + 25, navbarData: { name: '节俭会', }, // 背景图片 background: '', // 热量占比 heat: 100, heatColor: { '0%': '#E1FFFF', '25%': '#00FF7F', '50%': '#191970', '75%': '#ee0a24', '100%': '#ff0000' }, // 微信运动 step: 0, // 用餐卡 // 餐类别 thrTitle: '', // 站点信息 tenant: '', // 餐列表 thrList: [], }, // 查看本周菜谱 reserveBtn: function () { wx.redirectTo({ url: '/pages/food/index', }); }, // 报餐:1,余菜打包:2,卡路里计算:3 twoBtn: function (e) { let type = e.currentTarget.dataset.smile; if (type == '1') { //报餐 wx.switchTab({ url: '/pages/reserve/index', }); } else if (type == '2') { //余菜打包 wx.showToast({ title: '暂未开通', }); } else { //卡路里计算 wx.showToast({ title: '暂未开通', }); } }, /** * 生命周期函数--监听页面加载 */ onLoad: async function (options) { await this.getMealCard(); // 获取背景图片,站点信息 const res = await app.$get('/config'); const logo = `${res.data.logo[0].url || ''}`; this.setData({ background: logo }); // wx.request({ // url: `${app.globalData.publicUrl}/api/st/system/tenant/getTenant/${app.globalData.tenant}`, // method: 'get', // data: {}, // success: (res) => { // const { data } = res.data; // this.setData({ background: `${app.globalData.fileUrl}` + data.img.home }); // this.setData({ tenant: data.name }); // }, // error: (err) => { // wx.showToast({ // title: err.msg, // icon: 'error', // }); // }, // }); // TODO:获取微信运动信息 // wx.getWeRunData({ // success: (res) => { // const app = getApp(); // const { encryptedData, iv } = res; // const session_key = app.globalData.wxInfo.session_key; // const data = { encryptedData, iv, session_key }; // wx.request({ // url: `${app.globalData.publicUrl}/st/api/weixin/decrypt`, // method: 'POST', // data, // success: (res) => { // const setpInfo = res.data?.data; // if (stepInfo) this.setData({ step: stepInfo.step }); // }, // }); // }, // }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () {}, /** * 生命周期函数--监听页面显示 */ onShow: function () { if (typeof this.getTabBar === 'function' && this.getTabBar()) { this.getTabBar().setData({ selected: 0, }); } }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () {}, /** * 生命周期函数--监听页面卸载 */ onUnload: function () {}, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () {}, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () {}, /** * 用户点击右上角分享 */ onShareAppMessage: function () {}, // 获取用餐卡 async getMealCard() { if(!app.globalData.wxInfo.openid) await app.toLogin(); const openid = app.globalData.wxInfo.openid; if (!openid) return; const res = await app.$post(`/order/mealCard/${openid}`); if (res.data.errcode === 0) { const { data } = res.data; if (!data) { this.setData({ thrList: [], }); return; } this.initQrCode(data.data._id); this.setData({ thrList: data.data.list || [], thrTitle: data.type, }); } // wx.request({ // url: `${app.globalData.publicUrl}/api/st/dining/order/mealCard/${openid}`, // method: 'POST', // success: (res) => { // if (res.data.errcode === 0) { // const { data } = res.data; // if (!data) { // this.setData({ // thrList: [], // }); // return; // } // this.initQrCode(data.data._id); // this.setData({ // thrList: data.data.list || [], // thrTitle: data.type, // }); // } // }, // error: (err) => { // console.error(err.data.errmsg); // }, // }); }, // 创建二维码 initQrCode(id) { const url = `${app.globalData.publicUrl}/st/api/order/useMeal/${id}`; // const url = `${app.globalData.publicUrl}/api/st/dining/order/useMeal/${id}`; var qrcode = new QRCode(`myQrcode`, { text: url, width: 100, height: 100, padding: 3, colorDark: '#000000', colorLight: '#ffffff', correctLevel: QRCode.CorrectLevel.L, }); }, });