
var app = getApp()
var that;
Page({
  data: {
    date: app.globalData.month,
    activeIndex: 1,
    page: 1,
  },
  onLoad() {
    that = this;
    dd.setNavigationBar({ title: "我奖扣的" });
    that.getData(1);
  },
  bindKeyInput(e) {
    this.setData({
      keyword: e.detail.value,
      page: 1,
    })
    this.getData(that.data.activeIndex);
  },
  getData(index, is) {
    var urlS = ['api/integral/statistics/integral', 'api/integral/review/entry/list', 'api/integral/review/entry/list'];
    var data;
    if (index == 1) {
      data = {
        page: that.data.page,
        page_size:20,
        recorder_id: app.globalData.userData.id,
        source_type: 1,
        keyword: that.data.keyword
      }
    } else if (index == 2) {
      data = {
        page: that.data.page,
                page_size:20,
        type: 'waiting',
        pt_id: 0,
        keyword: that.data.keyword
      }
    } else {
      data = {
        page: that.data.page,
                page_size:20,
        type: 'refuse',
        pt_id: 0,
        keyword: that.data.keyword
      }
    }
    app.$get(urlS[index - 1], data).then((res) => {
      var data = res.data.data.list;
      if (is) {
        if (data.length == 0) {
          this.setData({
            isData: true
          })
          return;
        }
        var list = that.data.list;
        this.setData({
          list: list.concat(data)
        })
      } else {
        this.setData({list:[]});
        this.setData({
          list: data,
          isData: false
        })
      }
    })
  },
  activeItem(e) {
    var index = e.target.dataset.index;
    this.setData({ activeIndex: index, page: 1,list:[] })
    this.getData(index);
  },
  openDetail(e) {
    var id = e.target.dataset.item.id;
    var index=e.target.dataset.index;
    if (index=='1') {
      dd.navigateTo({
        url: '../prizeBuckleDetail/prizeBuckleDetail?id='+id
      })
    } else {
      dd.navigateTo({
        url: '../../workbench/approveDetail/approveDetail?id='+id+'&is='+true
      })
    }
  },
  //上啦加载
  onScrollToLower() {
    if(!that.data.isData){
      this.setData({ page: ++that.data.page })
      this.getData(that.data.activeIndex, true);
    }else{
       app.globalData.showToast("已无更多咯");
    }
  },
});
