
var app = getApp()
var that;
Page({
  data: {
    date: app.globalData.month,
    list: [],
    page: 1,
    all: 0,
    grant: 0,
    exchange:0,
    consume: 0,
    take_back: 0,
  },
  onLoad() {
    that = this;
    dd.setNavigationBar({ title: "功勋点明细" });
    this.getData();
  },
  //上啦加载
  onScrollToLower() {
    if (!that.data.isData) {
      this.setData({ page: ++that.data.page })
      this.getData(true);
    }
    
  },
  getData(is) {
    var data = {
      page: this.data.page,
      page_size: 20,
      employee_id: app.globalData.userData.id,
      export: 0,
    }
    app.$get('/api/shop/achievement/detail', data).then((res) => {
      var data = res.data.data.list;
      data.map(item => {
        item.date = this.timestampToTime(item.create_time)
      })
      var list = that.data.list;
      this.setData({
        all: res.data.data.all,
        grant: res.data.data.grant,
        exchange: res.data.data.exchange,
        consume: res.data.data.consume,
        take_back: res.data.data.take_back,
      })
      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
        })
      }
    })
  },
  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 + h + m + s;
  },
});
