// packageI/allowanceIndex/allowanceAchievement/allowanceAchievement.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    avatarInfo: {},
    list: [],
    page: 1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '业绩统计',
    });
    this.getData();
  },
  showGoodTap(e) {
    console.log(e);
    let item = e.currentTarget.dataset.item;
    let ind = e.currentTarget.dataset.ind;
    if (!item.moreShow) {
      this.setData({
        ['list[' + ind + '].moreShow']: true
      });
    }
  },
  goteam() {
    wx.navigateTo({
      url: '/packageI/allowanceIndex/allowanceTeam/allowanceTeam',
    });
  },
  toDetail() {
    wx.navigateTo({
      url: '/packageI/allowanceIndex/allowanceDetail/allowanceDetail',
    });
  },
  tapGetMoreGood(e) {
    let item = e.currentTarget.dataset.item;
    let index = e.currentTarget.dataset.index;
    console.log(item, index);
    console.log(this.data.list[index]);
    if (item.goodsShow) {
      this.data.list[index].goodsShow = false;
    } else {
      this.data.list[index].goodsShow = true;
    }
    this.setData({
      list: this.data.list
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

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

  },

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

  },

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

  },

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

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

  },
  getData() {
    let urlStr = app.getNetAddresss("plugin.agency-subsidy.frontend.controllers.performance.index");
    app._getNetWork({
      url: urlStr,
      data: {
        page: this.data.page
      },
      success: (resdata) => {
        var res = resdata.data;
        if (res.result != 1) return app.tips(res.msg);
        for (let i = 0; i < res.data.list.data.length; i++) {
          res.data.list.data[i].goodsShow = false;
        }
        this.setData({
          avatarInfo: res.data.info,
          list: res.data.list.data,
          current_page: res.data.list.current_page,
          last_page: res.data.list.last_page
        });
      }
    });
  },
  getMoreData() {
    let urlStr = app.getNetAddresss("plugin.agency-subsidy.frontend.controllers.performance.index");
    app._getNetWork({
      url: urlStr,
      data: {
        page: this.data.page
      },
      success: (resdata) => {
        var res = resdata.data;
        if (res.result != 1) return app.tips(res.msg);
        for (let i = 0; i < res.data.list.data.length; i++) {
          res.data.list.data[i].goodsShow = false;
        }
        let myData = res.data.list.data;
        this.data.list = this.data.list.concat(myData);
        this.setData({
          list: this.data.list,
          current_page: res.data.list.current_page,
          last_page: res.data.list.last_page
        });
      }
    });
  }
});