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

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

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

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

  // 重置页面列表 点击搜索条件时需要
  resetPage() {
    this.setData({
      page: 1,
      dataList: []
    })
  },

  /**
   * 订单状态
   */
  queryOrder() {
    return new Promise((resolve, reject) => {
      app.post({
        url: app.api.order,
        data: {
          page: this.data.page,
          size: this.data.size,
          orderStatus: this.data.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");
    if (navIndex != curIndex) {
      this.setData({
        navIndex: curIndex
      })
      this.refreshOrderStatus();
    }
  },
  /**
   * 更新状态
   */
  refreshOrderStatus() {
    let orderStatus = "";
    let navIndex = this.data.navIndex;
    switch (navIndex) {
      // 全部
      case "0":
        orderStatus = "";
        break;

        // 待审核
      case "1":
        orderStatus = "unaudited";
        break;

        // 已通过
      case "2":
        orderStatus = "pass";
        break;

        // 已发货
      case "3":
        orderStatus = "deliver";
        break;

        // 未通过
      case "4":
        orderStatus = "audit_faild";
        break;

      default:
        break;
    }
    this.setData({
      orderStatus: orderStatus
    })
    this.resetPage();
    this.queryOrder();
  },

  // 隐藏蒙层
  hideMask() {
    this.setData({
      authorizeVisible: false,
    })
  },
  // 子组件事件
  evtcomp(evt) {
    let {
      name,
      data
    } = evt.detail;
    switch (name) {

      // 隐藏弹窗
      case "_evt_hide_mask":
        this.hideMask();
        break;

      default:
        break;
    }
  },

})