rank.js 4.61 KB
import {
  getBindtapData
} from '../../utils/util';

let app = getApp();
Page({
  data: {
    authorizeVisible: false,
    navIndex: 0,
    status: "promotion",
    turnsIndex: 0, //轮次 0:本轮  1:历史
    rankInfo: {},

    historyRankInfoList: [],
    historyIndex: 0,
    isInit: false
  },
  onShareAppMessage() {},
  showAuth() {
    this.setData({
      authorizeVisible: true
    })
  },
  onLoad(options) {
    this.initData();
  },
  initData() {
    this.refreshStatus();
  },

  /**
   * 推广奖金排行
   */
  queryActivity() {
    this.setData({
      isInit: false
    })
    return new Promise((resolve, reject) => {
      let status = this.data.status;
      app.post({
        url: app.api.activity,
        data: {
          key: status
        }
      }).then((result) => {
        let rankInfo = this.formatRankInfo(result, status);
        this.setData({
          isInit: true,
          rankInfo: rankInfo
        });
        console.log("rankInfo 1:", rankInfo);
        resolve();
      })
    });
  },

  /**
   * 历史奖金排行
   */
  queryActivityHistory() {
    this.setData({
      isInit: false
    })
    return new Promise((resolve, reject) => {
      let status = this.data.status;
      app.post({
        url: app.api.activityHistory,
        data: {
          page: 1,
          size: 999999,
          key: this.data.status
        }
      }).then((result) => {
        let historyRankInfoList = result.list;
        this.setData({
          isInit: true,
          historyRankInfoList: historyRankInfoList
        })
        console.log("rankInfo 2 history:", historyRankInfoList);
        this.setHistory();
        resolve();
      })
    });
  },

  /**
   * 格式化
   */
  formatRankInfo(val, status) {
    let rankInfo = val;
    if (!rankInfo) return null;

    if (status == "promotion") {
      rankInfo.myMember.rank = rankInfo.myMember.promotionNo;
      rankInfo.myMember.points = rankInfo.myMember.promotionPoints;
      rankInfo.memberList.forEach(element => {
        element.rank = element.promotionNo;
        element.points = element.promotionPoints;
      });
    } else {
      rankInfo.myMember.rank = rankInfo.myMember.rankNo;
      rankInfo.myMember.points = rankInfo.myMember.rankPoints;
      rankInfo.memberList.forEach(element => {
        element.rank = element.rankNo;
        element.points = element.rankPoints;
      });
    }
    return rankInfo;
  },

  /**
   * 设置
   */
  setHistory() {
    let index = this.data.historyIndex;
    let status = this.data.status;
    let historyRankInfoList = this.data.historyRankInfoList
    let rankInfo = this.formatRankInfo(historyRankInfoList[index], status);
    this.setData({
      rankInfo
    })
    console.log("rankInfo:", rankInfo);
  },

  /**
   * 选择导航
   * @param {*} evt
   */
  onNavSelectHandler(evt) {
    let navIndex = this.data.navIndex;
    let curIndex = getBindtapData(evt, "index");
    if (navIndex != curIndex) {
      this.setData({
        navIndex: curIndex,
        turnsIndex: 0,
        historyIndex: 0,
      })
    }
    this.refreshStatus();
  },

  // 选择轮次 历史/本轮
  onChangeTurnsHandler(evt) {
    let turnsIndex = this.data.turnsIndex;
    let curIndex = getBindtapData(evt, "index");
    if (turnsIndex != curIndex) {
      this.setData({
        turnsIndex: curIndex
      });
      console.log("curIndex:", curIndex);
      if (curIndex == 0) {
        this.queryActivity();
      } else {
        this.queryActivityHistory();
      }
    }

  },

  /**
   * 拾取历史活动
   */
  bindHistoryChange(e) {
    let index = e.detail.value;
    this.setData({
      historyIndex: index,
    })
    this.setHistory()
  },

  /**
   * 刷新状态重新请求
   */
  refreshStatus() {
    let status = "";
    let navIndex = this.data.navIndex + "";
    switch (navIndex) {
      // 全部
      case "0":
        status = "promotion";
        break;

        // 购买奖金
      case "1":
        status = "rank";
        break;

      default:
        break;
    }
    this.setData({
      status: status
    })
    // this.resetPage();
    this.queryActivity();
  },


  /**
   * 排行榜奖励
   * @param {*} evt
   */
  onRankGiftHandler(evt) {
    app.router.push({
      path: "rankGift"
    })
  },

  // 滚动到底部 分页加载
  onRankScrolltolower(e) {

  },

  // 隐藏蒙层
  hideMask() {
    this.setData({
      authorizeVisible: false,
    })
  },
  // 子组件事件
  evtcomp(evt) {
    let {
      name,
      data
    } = evt.detail;
    switch (name) {

      // 隐藏弹窗
      case "_evt_hide_mask":
        this.hideMask();
        break;

      default:
        break;
    }
  },
})