admin
2020-12-22 28a4cfadc0a78d1bfec093e0694f420aaf3a725c
pages/join-statistic/join-statistic.js
@@ -1,15 +1,30 @@
var help = require('../../util/help.js');
var help = require('/util/help.js');
var api = require('/util/api.js');
var $this;
Page({
  data: {
    showStatistic: true,
    showStatistic: false,
    currentType: 1,
    showLoading: true,
    rankList: [{ rank: 1 }, { rank: 3 }, {}, {}, {}],
    joinerList: [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}],
    rankList: [],
    myRank: true,
    //参与者
    joinerList: [],
    page: 1,
    total: 0,
    joinerHasMore: true
  },
  onLoad() {
  onLoad(query) {
    $this = this;
    help.setPageNavBar("参与统计");
    this.setData({
      activityId: query.activityId
    });
    setTimeout(() => {
      $this.requestRank();
    });
  },
  changeNav(event) {
    var type = help.getEventParam(event, "type");
@@ -20,13 +35,135 @@
    this.setData({
      currentType: type
    });
    switch (type) {
      case 1:
        $this.requestRank();
        break;
      case 2:
        $this.requestJoinerList(1, true)
        break;
    }
  },
  onMoreJoiner() {
    console.log("加载更多参与者信息");
    $this.requestJoinerList($this.data.page + 1, false);
  },
  onStatisticClose() {
    this.setData({
      showStatistic: false
    });
  },
  onRankClick(event) {
    var data = help.getEventParam(event, "item");
    console.log(data);
    $this.requestProbability(data.user.uid);
  },
  requestRank() {
    api.getRankList({
      showErrorToast: true,
      showLoading: true,
      page: 1,
      activityId: $this.data.activityId,
      success: function (res) {
        if (res.code == 0) {
          var list = res.data.data;
          if (res.data.myRank) {
            res.data.myRank.myRank = true;
            list.unshift(res.data.myRank);
          }
          $this.setData({
            myRank: res.data.myRank != null,
            rankList: list
          });
          console.log("myRank:" + (res.data.myRank != null))
        }
      }
    });
  },
  requestProbability(uid) {
    api.getProbability({
      showErrorToast: true,
      showLoading: true,
      activityId: $this.data.activityId,
      targetUid: uid,
      success: function (res) {
        if (res.code == 0) {
          $this.setData({
            probability: res.data
          });
          setTimeout(() => {
            $this.setData({
              showStatistic: true
            });
          });
        }
      }
    })
  },
  requestJoinerList(page, first) {
    $this.setData({
      page: page,
      isRequesting: true,
      showEmptyDefault: false
    });
    api.getJoinerList({
      activityId: $this.data.activityId,
      page: page,
      showErrorToast: true,
      showLoading: first,
      success: function (res) {
        console.log(res)
        if (res.code == 0) {
          var list = res.data.data;
          //设置列表数据
          if (list != null && list.length > 0) {
            var totalList = $this.data.joinerList.concat(list);
            if (page == 1) {
              totalList = list;
            }
            $this.setData({
              total: res.data.count,
              joinerList: totalList,
              joinerHasMore: totalList.length < res.data.count
            })
          }
          //设置空列表默认显示
          if (page == 1 && (list == null || list.length == 0)) {
            $this.setData({
              showEmptyDefault: true
            })
          }
        }
      },
      fail: function () {
        //请求失败需要将页码减1
        if ($this.data.page > 1) {
          $this.setData({
            page: $this.data.page - 1
          });
        }
      },
      complete: function () {
        setTimeout(() => {
          $this.setData({
            isRequesting: false
          });
        }, 1000);
      }
    });
  }
});