1
jyy
2021-01-16 37c344f7b5c767c6a87e08a0c8a9698d8610fbfc
pages/purchaseRecords/index.js
@@ -1,78 +1,136 @@
// pages/purchaseRecords/index.js
Page({
  /**
   * 页面的初始数据
   */
var util = require('../../utils/util.js');
Page({
  data: {
    currentIndex:0
    currentIndex: 0,
    orderList:[],
    limit:10,
    offset:0,
    refresh:false,
    orderShow:false,
    noMore:false,
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onUnload: function () {
    // wx.reLaunch({
    //   url: '../customerCenter/customerCenter'
    // })
  },
  onLoad: function (options) {
    var status = options.status;
    if (status!=undefined){
      this.setData({
        currentIndex: status
      })
    }
    this.getOrderInfo(this.data.currentIndex);
    this.goTap();
  },
  onShow:function(){
    if(this.data.refresh){
      this.getOrderInfo(this.data.currentIndex);
    }
  },
  //获取滚动条当前位置
  onPageScroll: function (e) {
    // console.log(e)
    if (e.scrollTop > 400) {
      this.setData({
        floorstatus: true
      });
    } else {
      this.setData({
        floorstatus: false
      });
    }
  },
  //一键回到顶部
  goTap(){
    util.goTap();
  },
  onTabsItemEvent(e){
    var index = e.currentTarget.dataset.index;
    this.setData({
      currentIndex:index,
      offset: 0
    })
    this.setData({
      noMore:false
    });
    this.getOrderInfo(index);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  // 根据状态获取订单信息
  getOrderInfo:function(status){
    var _this = this;
    var limit = _this.data.limit;
    var offset = _this.data.offset;
    util.request({
    api:"/wxapi/erpOrder/findUserOrderList",
    data: { "limit": limit, "orderStatus": status, "offset": offset},
    callback: function (data) {
      console.log("订单信息")
      console.log(data.rows)
      _this.setData({
        orderList: data.rows,
        currentIndex: status
      });
      var orderList = _this.data.orderList;
      console.log(orderList)
      if (orderList.length == 0) {
        _this.setData({
          orderShow: true,
        })
      } else {
        _this.setData({
          orderShow: false
        })
      }
    }});
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  toDetail(e){
    var id = e.currentTarget.dataset.id
    console.log(id)
    wx.navigateTo({
      url: '../purchaseRecords/detail?id='+id,
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  // 上拉加载
  onReachBottom: function () {
  },
    var _this = this;
    var offset = _this.data.offset;
    var limit = _this.data.limit;
    var orderList = _this.data.orderList;
    var status = _this.data.currentIndex;
    _this.setData({
      offset: offset + limit
    });
    offset = _this.data.offset;
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    util.request({api:"/wxapi/erpOrder/findUserOrderList",data: { "limit": limit, "orderStatus": status, "offset": offset },
    callback: function (data) {
  },
  onTabsItemEvent(e) {
    var index = e.currentTarget.dataset.index;
      if(data.rows.length>0){
        _this.setData({
          noMore:false
        });
      }else{
        _this.setData({
          noMore:true
        });
      }
    this.setData({
        currentIndex: index
    })
      for (var i = 0; i < data.rows.length; i++) {
        orderList.push(data.rows[i]);
      }
      _this.setData({
        orderList: orderList
      });
    }});
  },
  toDetail(){
    wx.navigateTo({
      url: '/pages/purchaseRecords/detail'
    })
  }
})
})