order.js 1.4 KB
Newer Older
wanghuihui's avatar
wanghuihui committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');

Page({
  data: {
    orderList: [],
    showType: 0
  },
  onLoad: function(options) {
    if (options.tab) {
      this.setData({
        showType: options.tab
      });
    } else {
      // 页面初始化 options为页面跳转所带来的参数
      let that = this
      try {
        var tab = wx.getStorageSync('tab');

        this.setData({
          showType: tab
        });
      } catch (e) {}
    }

  },

  onPullDownRefresh() {
    wx.showNavigationBarLoading() //在标题栏中显示加载
    this.getOrderList();
    wx.hideNavigationBarLoading() //完成停止加载
    wx.stopPullDownRefresh() //停止下拉刷新
  },

  getOrderList() {
    let that = this;
    util.request(api.OrderList, {
      showType: that.data.showType
    }).then(function(res) {
      if (res.errno === 0) {
        console.log(JSON.stringify(res.data));
        that.setData({
          orderList: res.data.data
        });
      }
    });
  },
  switchTab: function(event) {
    let showType = event.currentTarget.dataset.index;
    this.setData({
      showType: showType
    });
    this.getOrderList();
  },
  onReady: function() {
    // 页面渲染完成
  },
  onShow: function() {
    // 页面显示
    this.getOrderList();
  },
  onHide: function() {
    // 页面隐藏
  },
  onUnload: function() {
    // 页面关闭
  }
})