
var app = getApp()
var that;
var chart1;
Page({
  data: {
    date: app.globalData.month,
    data_a: [],
    chartData: [],//折线图数据
  },
  onLoad() {
    that = this;
    dd.setNavigationBar({ title: "我的A分统计" });
  },
  //打开更多
  openMore(){
    dd.navigateTo({
      url: '../../statistics/integralEvent/integralEvent?month=' + this.data.date + '&type=AF'
    })
  },
  //则线图
  onInitChart(F2, config) {
    chart1 = new F2.Chart(config);
    chart1.source(that.data.chartData, {
      date: {
        range: [0, 1],
        tickCount: 5
      }
    });
    chart1.line().position('date*value');
    chart1.point().position('date*value').style({
      stroke: '#fff',
      lineWidth: 1
    });
    chart1.render();
    that.getIncidentLsit();
    return chart1;
  },
  //时间选择
  openDate() {
    dd.datePicker({
      format: 'yyyy-MM',
      currentDate: that.data.date,
      success: (res) => {
        that.setData({
          date: res.date
        })
        that.getIncidentLsit();
      },
    });
  },
  //获取积分事件
  getIncidentLsit() {
      app.$get("api/integral/statistics/a", {  employee_id: 0, month: that.data.date }).then((res) => {
          const {a, chart,list} = res.data.data
          const points = chart.reward.map((rewardItem, index) => {
            return { date: rewardItem.month, value: rewardItem.point + (chart.deduction[index].point || 0) }
          })
          chart1.changeData(points);
          that.setData({
            data_a: a,
            dataList:list
          });
      })
  },
});
