123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- // 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)
- })
- })
- }
- })
|