/* * 手太欠 * 愿这世界都如故事里一样 美好而动人~ */ Page({ /** * 页面的初始数据 */ data: { needBase : '', // 是否需要完善资料 baseState : false,// 完善资料弹出 Drink : '', // 饮用量数值 Element : '', // 摄入成分 type : 'normal', // 默认普通饮用水 scale : '10', // 默认饮用量 number : 100, // 默认饮用量值 seeNumber : 100, // 弹出默认饮用量值 waterState : false,// 选择饮用量 isFixedTop : 0, barHeight : getApp().globalData.statusBarHeight, // 状态栏高度 }, /** * 生命周期函数--监听页面加载 */ onLoad(options) {}, /** * 生命周期函数--监听页面显示 */ onShow() { // 获取登录状态 if(wx.getStorageSync("token")){ // 获取初始化 this.initInfo(); } }, /** * 初始化 */ initInfo () { wx.$api.water.Init().then(res => { let {drink, element, need_tongue} = res.data if(this.data.type == 'normal') { this.setData({ Drink : drink.normal }) } else { this.setData({ Drink : drink.sykl }) } this.setData({ Element : element, needBase: need_tongue }) }).catch(err => {}) }, /** * 滑动选择器 */ slider3change(e) { this.setData({ number: e.detail.value, scale: (e.detail.value / 10) }) }, /** * 兑换券数量加减 */ scaleNumber(e){ let num = this.data.number, val = e.currentTarget.dataset.type if (val == 'plus'){ num = num + 10; }else{ if (num > 100){ num = num - 10; } this.setData({ number: num }) } this.setData({ number: num, scale: num / 10 }) }, /** * 选择饮品 */ drinkSelect(e) { this.setData({ type : e.currentTarget.dataset.type }) // 获取登录状态 if(wx.getStorageSync("token")){ // 获取初始化 this.initInfo(); } }, /** * 喝水打卡 */ drinkTap() { // 获取登录状态 if(wx.getStorageSync("token")){ // 是否需要完善资料 if(this.data.needBase) { this.setData({ baseState: true }) return } this.setData({ waterState : true, number : 100, scale : 100 / 10 }) return } // 去登录 wx.navigateTo({ url: "/pages/login/index" }) }, /** * 关闭选择饮品弹窗 */ drinkCancel() { this.setData({ waterState : false }) }, /** * 确认饮用量 */ drinkSure() { wx.$api.water.Drink({ type: this.data.type, ml : this.data.number }).then(res => { this.setData({ waterState: false }) // 获取初始化 this.initInfo(); }).catch(err => {}) }, /** * 关闭完善资料弹出 */ establish() { this.setData({ baseState: false }) }, /** * 完善资料跳转 */ perfect() { this.setData({ baseState: false }) wx.switchTab({ url: '/pages/record/index' }) } })