
var app = getApp()
var that;
Page({
  data: {
    month: app.globalData.month,

    showRuleTwo: false,//显示规则组件
    ruleVal: "规则分类",

    isPx: true,
    id: '',
    page:1,
  },
  onLoad(e) {
    that = this;
    if (e.id) {
      this.setData({ id: e.id });
      dd.setNavigationBar({ title: e.name });
      this.getData();
    }
  },
  getData(is) {
    var data = {
      month: that.data.month,
      page: that.data.page,
      page_size: 10,
      pt_id: app.getTypesItem('BF').id,
      sort: that.data.isPx ? 'DESC' : 'ASC',
      type: 'all',
      group_id: that.data.id,
      rule_id: that.data.rule_id
    }
    app.$get('api/integral/statistics/ranking', data, 'application/vnd.test.v2+json').then((res) => {
      var data = res.data.data.list;
      if (is) {
        if (data.length == 0) {
          app.globalData.showToast("已无更多咯");
          return;
        }
        var list = that.data.list;
        this.setData({
          list: list.concat(data)
        })
      } else {
        this.setData({
          list: data
        })
      }
    })
  },
  //上啦加载
  onScrollToLower() {
    this.setData({ page: ++that.data.page })
    this.getData(true);
  },
  selectDay() {
    dd.datePicker({
      format: 'yyyy-MM',
      currentDate: this.data.month,
      success: (res) => {
        this.setData({
          month: res.date,
        })
        this.getData();
      },
    });
  },
    //显示规则组件
  selectRule() {
    this.setData({
      showRuleTwo: true
    })
  },
  selectIsPx() {
    this.setData({
      isPx: !this.data.isPx,
      page: 1
    })
    this.getData();
  },
  //打开兴趣
  openDetail(e) {
    var item = e.target.dataset.item;
    dd.navigateTo({
      url: '../prizeBuckleDetail/prizeBuckleDetail?item=' + item
    })
  },
  //关闭弹窗
  onClose() {
    this.setData({
      showRuleTwo: false
    })
  },
  //选择规则
  onConfirmRule(data) {
    this.setData({ rule_id: data.join(','), page: 1 })
    this.getData();
  },
});
