import ProApi from '../../../../net/api/projectApi' const app = getApp() const deviceInfo = wx.getDeviceInfo() const screenInfo = wx.getWindowInfo(); const statusBarHeight = screenInfo.statusBarHeight; // 状态栏高度 const navBarHeight = deviceInfo.platform == 'IOS' ? 48 : 50; // 导航栏高度(iOS 为 44px,Android 为 48px) const windowHeight = screenInfo.windowHeight - navBarHeight - statusBarHeight; //可用内容高度 Page({ /** * 页面的初始数据 */ data: { couponsList: [], loadingStatus: 'loading', currentPage: 1, listRefreshTrig: false, currentStatus: 1, rows: 10, isLoadMore: false, //是否正在加载更多 height: windowHeight }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.doRefreshList() }, //tab切换 doChangeStatus(e) { const value = e.currentTarget.dataset.value this.setData({ currentStatus: value }) this.doRefreshList() }, //获取我的优惠卷 doGetMyCoupons(data) { const _self = this ProApi.doGetCouponseList(data) .then(res => { wx.stopPullDownRefresh() console.log('优惠卷') console.log(res) _self.setData({ loadingStatus: res.rows && res.rows.length > 0 ? 'success' : 'empty', couponsList: _self.data.couponsList.concat(res.rows), listRefreshTrig: false, isLoadMore: false }) }, err => { console.log(err) wx.stopPullDownRefresh() _self.setData({ couponsList: [], loadingStatus: 'error', listRefreshTrig: false, isLoadMore: false }) }) }, //构建请求参数 buildParams(value) { const _self = this console.log(value) var data = {} if (value == 1) { data.isEffective = 1 data.isUsed = 0 } else if (value == 2) { data.isEffective = '' data.isUsed = 1 } else { data.isEffective = 0 data.isUsed = 0 } data.rows = _self.data.rows return data }, //下拉刷新 doRefreshList() { const _self = this _self.setData({ currentPage: 1, listRefreshTrig: true, loadingStatus: 'loading' }) var data = _self.buildParams(_self.data.currentStatus) data.page = _self.data.currentPage _self.doGetMyCoupons(data) }, //加载更多 doLoadMore() { if (this.data.isLoadMore) { return } console.log('加载更多') const _self = this _self.setData({ currentPage: ++_self.data.currentPage, isLoadMore: true }) var data = _self.buildParams(_self.data.currentStatus) data.page = _self.data.currentPage _self.doGetMyCoupons(data) } })