123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- // 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: function (options) {
- // 登录,获取用户openid,sessonkey
- app.toLogin().then(res => {
- this.getMealCard();
- });
- // 获取背景图片,站点信息
- wx.request({
- url: `${app.globalData.publicUrl}/api/st/system/tenant/getTenant/${app.globalData.tenant}`,
- method: "get",
- header: { 'x-tenant': app.globalData.tenant },
- 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'
- })
- }
- })
- // 获取微信运动信息
- 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}/api/st/system/weixin/decrypt`,
- method: "POST",
- data,
- header: {
- 'x-tenant': app.globalData.tenant
- },
- success: (res) => {
- const { stepInfo } = 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 () {
- },
- // 获取用餐卡
- getMealCard() {
- const openid = app.globalData.wxInfo.openid;
- if (!openid) return;
- wx.request({
- url: `${app.globalData.publicUrl}/api/st/dining/order/mealCard/${openid}`,
- method: "POST",
- header: {
- 'x-tenant': app.globalData.tenant
- },
- 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}/api/st/dining/order/useMeal/${id}?_tenant=${app.globalData.tenant}`;
- var qrcode = new QRCode(`myQrcode`, {
- text: url,
- width: 100,
- height: 100,
- padding: 3,
- colorDark: "#000000",
- colorLight: "#ffffff",
- correctLevel: QRCode.CorrectLevel.L,
- });
- }
- })
|