
var app = getApp()
var that;
Page({
  data: {
    date: app.globalData.month,
    minuteIndex: 0,//条件选择
    minuteArray: [
      { id: 0, name: '总分' },
      { id: 1, name: '加班' },
      { id: 2, name: '迟到' },
    ],

    showDate: false,//是否显示时间组件
    selectDateVal: app.globalData.month,

    showSx: false,//显示sx选择
    sxVal: '筛选',

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

    showTissue: false,//显示部门组件
    TissueVal: '全公司',

    sort:'DESC',
    position:'all',
    year:app.globalData.year,
    page:1,
    dateIndex:'3'
  },
  onLoad() {
    that = this;
    dd.setNavigationBar({ title: "部门排名" });
    this.getData();
  },
  getData(is) {  
    var data = {
      pt_id:app.getTypesItem('BF').id,
      dept_id:that.data.dept_id,
      page: that.data.page,
      rule_id: that.data.rule_id,
      sort:that.data.sort,
      position:that.data.position,
      page_size:10
    }
    if(that.data.dateIndex=='1'){
      data.year=that.data.year;
    }else if(that.data.dateIndex=='2'){
      data.quarter=that.data.quarter
    }else{
      data.month=that.data.month;
    }
    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) {
          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
        })
      }
    })
  },
  //上啦加载
  onScrollToLower() {
    if(!that.data.isData){
      this.setData({ page: ++that.data.page })
      this.getData(true);
    }else{
       app.globalData.showToast("已无更多咯");
    }
  },
  // //打开兴趣
  // openDetail(e) {
  //   var item = e.target.dataset.item;
  //   console.log(item)
  //   dd.navigateTo({
  //     url: '../prizeBuckleDetail/prizeBuckleDetail?id=' + item.employee_id
  //   })
  // },
  //显示规则组件
  selectRule() {
    this.setData({
      showRuleTwo: true
    })
  },
  //显示选择时间组件
  selectDate() {
    this.setData({
      showDate: true
    })
  },
  //显示选择员工
  selectSx() {
    this.setData({
      showSx: true
    })
  },
  //选择时间
  onConfirmDate(data) {
    this.setData({
        dateObj: data,
    })
    if (data.type == '1') {
      this.setData({
        selectDateVal:data.date,
        year:data.date,
        dateIndex:data.type
      })
    } else if(data.type == '2'){
      this.setData({
        selectDateVal:data.date+'季度',
        quarter: data.date,
        dateIndex:data.type
      })
    }else{
       this.setData({
        selectDateVal: data.date,
        month:data.date,
        dateIndex:data.type
      })
    }
    this.setData({page:1})
    this.getData();
  },
  //关闭弹窗
  onClose() {
    this.setData({
      showDate: false,
      showSx: false,
      showRuleTwo: false,
      showTissue: false,
    })
  },
  //选择筛选
  onConfirmSx(data) {
   this.setData({sxObj:data, sort:data[1],position:data[0],page:1})
   this.getData();
  },
  //选择规则
  onConfirmRule(data) {
    this.setData({rule_id:data.join(','),page:1})
    this.getData();
  },
  //显示部门选择组件
  selectTissue() {
    this.setData({ showTissue: !this.data.showTissue })
  },
  //选择部门
  onConfirmTissue(data) {
    this.setData({ dept_id: data.id,page:1,TissueVal:data.name })
    this.getData();
  },
});
