// pages/order/index.js /*** * 订单查询 */ const app = getApp() import * as API_Order from '../../api/order.js' import * as Common from '../../utils/common.js' import { $wuxToptips, $wuxToast, $wuxLoading, $wuxDialog } from '../../wux/index.js' Page({ /** * 页面的初始数据 */ data: { pageParam: { page_size: 10, page_no: 1, order_status: 'ALL' }, finished: false, orderList: [], loading:true }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { const bool_o2o=app.globalData.authorInfo.boolO2o if(bool_o2o===0){ wx.redirectTo({ url:'/pages/noshop/index' }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function() { }, /** * 生命周期函数--监听页面显示 */ onShow: function() { //下拉刷新时,可能用户未登录,再返回此页时顶部会一直显示加载状态,这里首先隐藏加载状态 wx.hideNavigationBarLoading() this.setData({ ['pageParam.page_no']: 1, finished: false }) this.getOrderData() Common.getCurrentShopData().then(res => { this.getTabBar().init() }) }, /** * 生命周期函数--监听页面隐藏 */ onHide: function() { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function() { wx.showNavigationBarLoading() this.setData({ ['pageParam.page_no']: 1, finished: false, }) this.getOrderData().then(res => { wx.hideNavigationBarLoading() wx.stopPullDownRefresh() }).catch(error => { wx.hideNavigationBarLoading() wx.stopPullDownRefresh() }) }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function() { if (!this.data.finished) { this.setData({ ['pageParam.page_no']: this.data.pageParam.page_no + 1 }) this.getOrderData() } }, /** * 用户点击右上角分享 */ onShareAppMessage: function() { }, getOrderData() { return new Promise((resolve, reject) => { let that = this const authorInfo=app.globalData.authorInfo if(authorInfo===null||authorInfo===''){ //授权信息不存,不发起请求 return } if (authorInfo.boolO2o===0){ //非o2o店铺 不发起请求 return } $wuxLoading().show({ text: '加载中...', }) API_Order.getOrderList(that.data.pageParam).then(res => { const { data } = res let orders = [] if (that.data.orderList.length === 0 || that.data.pageParam.page_no === 1) { orders = [...data] } else { orders = that.data.orderList orders.push(...data) } if (data.length < 10) { that.setData({ finished: true }) } that.setData({ orderList: orders, loading:false }) $wuxLoading().hide() resolve(res) }).catch(error => { $wuxToptips().error({ icon: 'cancel', hidden: false, text: error?error.error:error.message, duration: 3000 }) that.setData({ loading: false }) reject(error) }) }) } })