
var app = getApp()
var that;
Page({
  data: {
    showRuleTwo: false,//显示规则组件
    ruleVal: "规则分类",
    page: 1,
  },
  onLoad(e) {
    that = this;
    dd.setNavigationBar({ title: "排名" });
    if (e.item) {
      this.setData({
        item: JSON.parse(e.item)
      })
      this.setData({
        item_obj: that.data.item.item
      })
      this.getData();
    }
  },
  //上啦加载
  onScrollToLower() {
    if (!that.data.isData) {
      this.setData({ page: ++that.data.page })
      this.getData(true);
    }
  },
  getData(is) {
    var item = this.data.item;
    console.log(item);
    //条件选择 0-全部 1-迟到 2-早退 6-准时打卡 20-上班缺卡 21-下班缺卡 16-加班 10-缺勤
    // type-1 总分，type-2早到，type-3迟到，4-加班, 8-早退， 9-缺卡，10-缺勤 6-奖分 7-扣分
    switch (item.type) {
      case 0:
        item.type = 1;
        break
      case 1:
        item.type = 3;
        break
      case 2:
        item.type = 8;
        break
      case 6:
        item.type = 2;
        break
      case 20:
        item.type = 9;
        break
      case 21:
        item.type = 12;
        break
      case 16:
        item.type = 4;
        break
      case 10:
        item.type = 10;
      break    
    }
    item.page = this.data.page;
    item.page_size = "10";
    app.$post('api/ad/event', item).then((res) => {
      var data = res.data.data.list;
      if (is) {
        if (data.length == 0) {
          this.setData({
            isData: true
          })
          return;
        }
        var list = that.data.list;
        this.setData({
          list: list.concat(data)
        })
      } else {
        this.setData({ list: [] });
        this.setData({
          list: data,
          isData: false
        })
      }
    })
  },
  //显示规则组件
  selectRule() {
    this.setData({
      showRuleTwo: true
    })
  },
});
