
var app = getApp()
var that;
Page({
  data: {
    activeIndex: 1,
    page: 1
  },
  onLoad() {
    that = this;
    dd.setNavigationBar({ title: "我申请的" });
    that.getData();
  },
  bindKeyInput(e) {
    this.setData({
      keyword: e.detail.value,
      page: 1,
    })
    this.getData();
  },
  getData(is) {
    var activeIndex = that.data.activeIndex;
    var data = {
      page: that.data.page,
      pt_id: 0,
      page_size: 20,
      type: '',
      keyword: that.data.keyword
    }
    if (activeIndex == 1) {
      data.type = "all"
    } else if (activeIndex == 2) {
      data.type = "complete"
    } else if (activeIndex == 3) {
      data.type = "waiting"
    } else {
      data.type = "refuse"
    }
    app.$get('api/integral/review/apply/list', 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();
  },
  openDetail(e) {
    var id = e.target.dataset.item.id;
    dd.navigateTo({
      url: '../../workbench/approveDetail/approveDetail?id=' + id + '&is=' + true
    })
  },
  //上啦加载
  onScrollToLower() {
    if (!that.data.isData) {
      this.setData({ page: ++that.data.page })
      this.getData(true);
    } else {
      app.globalData.showToast("已无更多咯");
    }
  },
});
