
var app = getApp()
var that;
Page({
  data: {
    list: [],
    minuteIndex: 0,//条件选择
    minuteArray: [
      { id: 0, name: '全部完成任务' },
      { id: 1, name: '准时完成任务' },
      { id: 2, name: '提前完成任务' },
      { id: 3, name: '逾期完成任务' },
    ],
    parameter:{},
  },
  onLoad(e) {
    that = this;
    this.setData({
      parameter: JSON.parse(e.data),
    })
    dd.setNavigationBar({ title: "积分事件" });
  },
  onShow() {
    if (app.globalData.userData) {
    } else {
      app.login(app.globalData.corpId, function (is) {
        if (is) {
        } else {
          dd.reLaunch({
            url: '../../noJurisdiction/noJurisdiction'
          })
        }
      }, function () { })
    }
     this.opneWebSocket();
  },
  opneWebSocket() {
    app.globalData.socketApi.sendData(this.data.parameter, this.onmessageWS);
  },
  onmessageWS(e) {
    // 因为作用域问题，这个函数不能使用this
    if (e.type == 'week_statistics'&&e.msg=='ruleList') {
      let result = e.result
      result.map(item => {
        item.date = that.timestampToTime(item.event_time);
        item.pt_name=item.pt_id==3? 'B分':'A分'
      })
      that.setData({
        list: result
      })
    }
  },
  timestampToTime(timestamp) {
    var date = new Date(timestamp * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    var D = date.getDate() + ' ';
    var h = date.getHours() + ':';
    var m = date.getMinutes() + ':';
    var s = date.getSeconds();
    return Y + M + D;
  },
  openDetail(e) {
    var id = e.target.dataset.item.id;
    dd.navigateTo({
      url: '../../statistics/prizeBuckleDetail/prizeBuckleDetail?id=' + id
    })
  },
});
