var WxParse = require('../../../../utils/wxParse/wxParse.js'); const app = getApp(); let self = null; Page({ /** * 页面的初始数据 */ data: { list: null, isLoading: false, // 检测是否已经发送请求,防止重复发送请求 noMore: false, // 检测是否有更多数据,true为没有更多数据,false为还有数据 pageNum: 1, // 当前页数 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { self = this; wx.setNavigationBarTitle({ title: "新手必看", }); // 判断会员是否授权登录, // 没有登录则跳转到登录页, // 已登录则设置已登录状态,请求加载数据 // isLogin记录登录状态 app.isLogin().then(function(data) { // console.log('data', data); // 1.登录成功 self.setData({ isLogin: true, userInfo: data, // currentQuery: { // store_id: app.globalData.setting.stoid, // user_id: app.globalData.user_id, // }, }); // 2.请求数据 self.get('/api/weshop/storeDistribut/get', { store_id: app.globalData.setting.stoid, }); }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { if(app.globalData.userInfo instanceof Object) { this.setData({ userInfo: app.globalData.userInfo, imghost: app.globalData.setting.imghost, }); // 检测从登录页返回后的登录状态 if(this.data.isLogin) { // 初次就授权登录 return; } else { // 初次未授权登录,过后才授权 this.setData({ isLogin: true }); // 请求数据 this.get('/api/weshop/storeDistribut/get', { store_id: app.globalData.setting.stoid, }); }; }; }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, /** * get请求数据 */ get(url, data) { app.request.get(url + '/' + data.store_id, { success: function(res) { if(res.data.code == 0){ console.log('success~~~~~~~~~~~',res); self.setData({ content: res.data.data.distriRule, }); /** * WxParse.wxParse(bindName , type, data, target,imagePadding) * 1.bindName绑定的数据名(必填) * 2.type可以为html或者md(必填) * 3.data为传入的具体数据(必填) * 4.target为Page对象,一般为this(必填) * 5.imagePadding为当图片自适应是左右的单一padding(默认为0,可选) */ WxParse.wxParse('content', 'html', self.data.content, self); }else{ wx.showToast({ title: "网络繁忙,请重试", icon: 'none', duration: 2000 }) } }, fail: function() {}, }); }, /** * 请求数据 */ // getData: function(isInit, url, data) { // app.request.promiseGet(url, { // data: data, // isShowLoading: true, // }) // .then(function(res) { // // console.log('1121', res.data.code); // if(res.data.code == 0) { // self.setData({ // isLoading: false // }); // if(isInit) {// 第一次加载 // self.setData({ // list: res.data.data // }); // } else { // self.setData({ // 'list.pageData': self.data.list.pageData.concat(res.data.data.pageData) // }); // }; // if((res.data.data.pageData.length == 0) || (res.data.data.pageSize * res.data.data.page >= res.data.data.total)) { // self.setData({ // noMore: true // }); // }; // } else { // self.setData({ // 'list.pageData': [] // }); // }; // }) // .catch(function(err) { // console.log('出错拉!!!!',err); // self.setData({ // 'list.pageData': [] // }); // }); // }, /** * 上拉加载 */ // scrollToLower(url, requestData) { // // 数据总量 // let total = this.data.list.total; // // 单页最大数据量 // let pageSize = this.data.list.pageSize; // // 如果数据总量不为0且小于或等于单页最大数据量,说明数据已全部加载,显示‘没有更多了’ // if((total != 0)&&(total <= pageSize)) { // this.setData({ // noMore: true // }); // }; // if(!this.data.isLoading && !this.data.noMore) { // this.setData({ // isLoading: true, // pageNum: this.data.pageNum + 1 // }); // requestData.page = this.data.pageNum; // this.getData(false, url, requestData); // }; // }, })