my-order.js 1.5 KB
import {
  getBindtapData
} from '../../utils/util';

let app = getApp();
Page({
  data: {
    authorizeVisible: false,
    navIndex: 0,
    total: 0,
    page: 1,
    size: 10,
    dataList: [],
  },
  onShareAppMessage() {},
  showAuth() {
    this.setData({
      authorizeVisible: true
    })
  },
  onLoad(options) {
    let {
      navIndex
    } = options;
    if (navIndex) {
      this.setData({
        navIndex: navIndex
      })
    }
    this.initData();
  },

  initData() {
    this.queryOrder();
  },

  // 到达底部
  onReachBottom() {
    if (this.data.dataList.length < this.data.total) {
      this.setData({
        page: this.data.page + 1
      });
      this.queryOrder();
    }
  },

  /**
   * 订单状态
   */
  queryOrder() {
    return new Promise((resolve, reject) => {
      app.post({
        url: app.api.order,
        data: {
          page: this.data.page,
          size: this.data.size,
          orderStatus: ""
        }
      }).then((result) => {
        let dataList = result.list;
        dataList = this.data.dataList.concat(dataList);
        this.setData({
          dataList: dataList,
          total: result.total
        })
        resolve();
      })
    });
  },

  /**
   * 选择导航
   * @param {*} evt
   */
  onNavSelectHandler(evt) {
    let navIndex = this.data.navIndex;
    let curIndex = getBindtapData(evt, "index");
    console.log("curIndex:", curIndex);
    if (navIndex != curIndex) {
      this.setData({
        navIndex: curIndex
      })
    }
  },

})