var app = getApp();
var that;

Page({
  data: {
    userData: {},
    isBh:false
  },
  onLoad(query) {
    that = this;
  },
  onShow(query) {
    if (app.globalData.userData) {
      that.getUserData();
      that.getIncidentLsit();
      that.getIncidentNum();
    } else {
      app.login(app.globalData.corpId, function (is) {
        if(is){
          that.getUserData();
          that.getIncidentLsit();
          that.getIncidentNum();
        }else{
          dd.reLaunch({
            url:'../noJurisdiction/noJurisdiction'
          })
        }
      })
    }
  },
  showText() {
    this.setData({isBh:!this.data.isBh})
  },
  //跳转
  openView(e) {
    var index = e.target.dataset.index - 1;
    var urls;
    if (e.target.dataset.item) {
      urls = [
        { url: '../statistics_B/statistics_B', query: '' },
        { url: '../statistics_A/statistics_A', query: '' },
        { url: '../jk_B/jk_B', query: 'type=B' },
        { url: '../jk_B/jk_B', query: 'type=A' },
        { url: '../apply/apply', query: '' },
        { url: '../my_approve/my_approve', query: '' },
        { url: '../prize_buckle/prize_buckle', query: '' },
        { url: '../../statistics/prizeBuckleDetail/prizeBuckleDetail', query: 'id=' + e.target.dataset.item.id },
        { url: '../../statistics/integralEvent/integralEvent', query: '' },
      ];
    } else {
      urls = [
        { url: '../statistics_B/statistics_B', query: '' },
        { url: '../statistics_A/statistics_A', query: '' },
        { url: '../jk_B/jk_B', query: 'type=B' },
        { url: '../jk_B/jk_B', query: 'type=A' },
        { url: '../apply/apply', query: '' },
        { url: '../my_approve/my_approve', query: '' },
        { url: '../prize_buckle/prize_buckle', query: '' },
        { url: '../../statistics/prizeBuckleDetail/prizeBuckleDetail', query: '' },
        { url: '../../statistics/integralEvent/integralEvent', query: '' },
      ];
    }
    dd.navigateTo({
      url: urls[index].url + '?' + urls[index].query
    })
  },
  //获取个人统计
  getUserData() {
    app.$get("api/integral/statistics", { employee_id: 0, month: app.globalData.month }).then((res) => {
      var data = res.data.data;
      var task = data.task;
      dd.setNavigationBar({ title: data.name });
      var ratio = task.reward.point === 0 || task.deduction.point === 0 ? '-' : `${task.ratio.ratio}:1`
      var target_ratio = task.ratio.target_ratio <= 0 ? '0:0' : `${task.ratio.target_ratio}:1`
      data.ratio = {
        ratio: ratio,
        target_ratio: target_ratio
      }
      this.setData({
        userData: data
      })
    }, (err) => { })
  },
  //获取积分事件
  getIncidentLsit() {
    app.$get("api/integral/statistics/integral", { month: app.globalData.month, page: 1, page_size: 5 }).then((res) => {
      var data = res.data.data;
      this.setData({
        incidentLsit: data
      })
    }, (err) => { })
  },
  getIncidentNum() {
    app.$get("api/integral/review/list", { type: 'waiting', page: 1, pt_id: 0 }).then((res) => {
      var data = res.data.data;
      this.setData({
        total: data.total
      })
    }, (err) => { })
  },
});
