Blame view

src/pages/my-order/my-order.js 2.38 KB
simon committed
1 2 3 4
import {
  getBindtapData
} from '../../utils/util';

simon committed
5 6
let app = getApp();
Page({
simon committed
7 8
  data: {
    authorizeVisible: false,
simon committed
9 10 11 12 13
    navIndex: 0,
    total: 0,
    page: 1,
    size: 10,
    dataList: [],
simon committed
14
    orderStatus: ""
simon committed
15 16 17 18 19 20 21
  },
  onShareAppMessage() {},
  showAuth() {
    this.setData({
      authorizeVisible: true
    })
  },
simon committed
22 23 24 25 26 27 28 29 30
  onLoad(options) {
    let {
      navIndex
    } = options;
    if (navIndex) {
      this.setData({
        navIndex: navIndex
      })
    }
simon committed
31 32
    this.refreshOrderStatus();
    // this.initData();
simon committed
33
  },
simon committed
34 35

  initData() {
simon committed
36
    // this.queryOrder();
simon committed
37 38 39 40 41 42 43 44 45 46 47 48
  },

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

simon committed
49 50 51 52 53 54 55 56
  // 重置页面列表 点击搜索条件时需要
  resetPage() {
    this.setData({
      page: 1,
      dataList: []
    })
  },

simon committed
57 58 59 60 61 62 63 64 65 66
  /**
   * 订单状态
   */
  queryOrder() {
    return new Promise((resolve, reject) => {
      app.post({
        url: app.api.order,
        data: {
          page: this.data.page,
          size: this.data.size,
simon committed
67
          orderStatus: this.data.orderStatus
simon committed
68 69 70 71 72 73 74 75 76 77 78 79 80
        }
      }).then((result) => {
        let dataList = result.list;
        dataList = this.data.dataList.concat(dataList);
        this.setData({
          dataList: dataList,
          total: result.total
        })
        resolve();
      })
    });
  },

simon committed
81 82 83 84 85 86 87 88 89 90 91
  /**
   * 选择导航
   * @param {*} evt
   */
  onNavSelectHandler(evt) {
    let navIndex = this.data.navIndex;
    let curIndex = getBindtapData(evt, "index");
    if (navIndex != curIndex) {
      this.setData({
        navIndex: curIndex
      })
simon committed
92
      this.refreshOrderStatus();
simon committed
93 94
    }
  },
simon committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
  /**
   * 更新状态
   */
  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();
  }
simon committed
136

simon committed
137
})