// packageE/others/cloudwarehouse/cloudRelease/cloudRelease.js
const app = getApp();
Page({

  /**
     * 页面的初始数据
     */
  data: {
    active: 0,
    page: 1,
    current_page: 1,
    last_page: 1
  },

  /**
     * 生命周期函数--监听页面加载
     */
  onLoad: function (options) {
    this.init();
    this.getData();
  },
  init() {
    this.page = 1;
    this.total_page = 0;
    this.setData({
      page: 1,
      current_page: 1,
      last_page: 1
    });
  },
  tapDetail(e){
    console.log(e);
    let id = e.currentTarget.dataset.id;
    let item = e.currentTarget.dataset.item;
    let active = this.data.active;
    if(active == 1){
      console.log(item.total_buy_log);
      if(item.total_buy_log == 0){
        wx.showToast({
          icon: 'none',
          title: "没有待释放记录",
          duration: 1500
        });
        return;
      }
    }
    wx.navigateTo({
      url: '/packageE/others/cloudwarehouse/cloudReleaseLog/cloudReleaseLog?id='+id+'&active='+active,
    });
  },
  /**
     * 生命周期函数--监听页面初次渲染完成
     */
  onReady: function () {

  },

  /**
     * 生命周期函数--监听页面显示
     */
  onShow: function () {

  },

  /**
     * 生命周期函数--监听页面隐藏
     */
  onHide: function () {

  },

  /**
     * 生命周期函数--监听页面卸载
     */
  onUnload: function () {

  },

  /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
  onPullDownRefresh: function () {

  },

  /**
     * 页面上拉触底事件的处理函数
     */
  onReachBottom: function () {
    console.log(this.data.current_page,this.data.last_page);
    if (this.data.current_page >= this.data.last_page) {
      return;
    } else {
      let pages = this.data.page + 1;
      this.setData({
        page: pages
      });
      this.getMore();
    }
  },

  /**
     * 用户点击右上角分享
     */
  onShareAppMessage: function () {

  },
  getData() {
    let that = this;
    let url = "plugin.cloud-warehouse.frontend.dividend.index";
    let urlStr = app.getNetAddresss(url);
    app._getNetWork({
      url: urlStr,
      data: {
        page: that.data.page
      },
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          console.log(res);
          that.setData({
            info: res.data,
            member: res.data.member,
            list: res.data.list.data
          });
        } else {
          wx.showToast({
            icon: 'none',
            title: res.msg,
            duration: 1500
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },
  tabChange(e) {
    console.log(e);
    this.setData({
      active: e.detail.index
    });
    let that = this;
    let url;
    if (this.data.active == 1) {
      url = 'plugin.cloud-warehouse.frontend.dividend.wait-dividend-goods';
    } else if (this.data.active == 0) {
      url = 'plugin.cloud-warehouse.frontend.dividend.dividend-list';
    }
    let urlStr = app.getNetAddresss(url);
    app._getNetWork({
      url: urlStr,
      data: {
        page: that.data.page
      },
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          console.log(res);
          that.setData({
            list: res.data.data,
            current_page: res.data.current_page,
            last_page: res.data.last_page
          });
        } else {
          wx.showToast({
            icon: 'none',
            title: res.msg,
            duration: 1500
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },
  getMore() {
    let that = this;
    let url;
    if (this.data.active == 0) {
      url = 'plugin.cloud-warehouse.frontend.dividend.wait-dividend-goods';
    } else if (this.data.active == 1) {
      url = 'plugin.cloud-warehouse.frontend.dividend.dividend-list';
    }
    let urlStr = app.getNetAddresss(url);
    app._getNetWork({
      url: urlStr,
      data: {
        page: that.data.page
      },
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          console.log(res);
          that.setData({
            list: that.data.list.concat(res.data.data),
            current_page: res.data.current_page,
            last_page: res.data.last_page
          });
        } else {
          wx.showToast({
            icon: 'none',
            title: res.msg,
            duration: 1500
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  }
});