// packageF/others/historyGroup/historyGroup.js
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    emptyImage: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/image.png",
    group_id: "",
    showGroup: false,
    showGroupMember: [],

    groupList: [],
    isLoadMore: true,
    page: 1,
    total_page: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      group_id: options.group_id,
    });
    this.getDetails();
  },

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

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

  openMore(e) {
    let item = e.target.dataset.item || e.currentTarget.dataset.item;
    this.setData({
      showGroupMember: item.has_many_team_member,
      showGroup: true,
    });
  },
  closeMore() {
    this.setData({
      showGroup: false,
    });
  },
  getDetails() {
    let url = app.getNetAddresss("plugin.fight-groups-lottery.frontend.fight-groups-lottery.get-team-list");
    app._postNetWork({
      url: url,
      data: {
        group_id: this.data.group_id,
        page: 1,
      },
      success: (res) => {
        let _data = res.data;
        console.log(_data);
        if (_data.result == 1) {
          this.setData({
            groupList: _data.data.data,
            total_page: _data.data.last_page,
          });
        } else {
          wx.showToast({
            title: _data.msg,
            duration: 1000,
            icon: "none",
          });
        }
      },
      fail: (err) => {
        console.log(err);
      },
    });
  },

  _getMoreDetails() {
    let urlStr = app.getNetAddresss("plugin.fight-groups-lottery.frontend.fight-groups-lottery.get-team-list");
    if (this.data.page >= this.data.total_page) {
      this.setData({
        isLoadMore: false,
      });
    } else {
      this.setData({
        page: this.data.page + 1,
      });
      app._postNetWork({
        url: urlStr,
        data: {
          group_id: this.data.group_id,
          page: this.data.page,
        },
        success: (res) => {
          let _data = res.data;
          if (_data.result == 1) {
            this.setData({
              isLoadMore: true,
              groupList: this.data.groupList.concat(_data.data.data),
            });
          } else {
            this.setData({
              page: this.data.page - 1,
              isLoadMore: false,
            });
          }
        },
        fail: (res) => {
          console.log(res);
        },
      });
    }
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.isLoadMore) {
      this._getMoreDetails();
    } else {
      console.log("没有更多数据");
    }
  },

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