
var app = getApp()
var that;
Page({
  data: {
    date: app.globalData.month,
    list: [],
    page: 1,
    month_total: 0,
    total: 0
  },
  onLoad() {
    that = this;
    dd.setNavigationBar({ title: "我的奖票" });
    this.getData();
  },
  //选择时间
  openDate(e) {
    dd.datePicker({
      format: 'yyyy-MM',
      currentDate: that.data.date,
      success: (res) => {
        that.setData({
          date: res.date
        })
        if (res.date) {
          that.getData();
        }
      },
    });
  },
  //上啦加载
  onScrollToLower() {
    if (!that.data.isData) {
      this.setData({ page: ++that.data.page })
    }
  },
  getData(is) {
    var data = {
      page: this.data.page,
      page_size: 20,
      employee_id: app.globalData.userData.id,
      month: this.data.date
    }
    app.$get('/api/integral/ticket', data).then((res) => {
      var data = res.data.data.month_list;
      var list = that.data.list;
      this.setData({
        month_total: res.data.data.month_total,
        total: res.data.data.total
      })
      if (is) {
        if (data.length < 20) {
          this.setData({
            list: list.concat(data),
            isData: true
          })
        } else {
          this.setData({
            list: list.concat(data)
          })
        }
      } else {
        this.setData({
          list: data,
          isData: false
        })
      }
    })
  },
  //打开更多
  openMore() {
    dd.navigateTo({
      url: '../../statistics/integralEvent/integralEvent?month=' + this.data.date + '&type=BF'
    })
  },
});
