
var app = getApp()
var that;
Page({
  data: {
    activeIndex: 1,
    page: 1,
    hall_type: 'waiting',
    list: [],
    userId: '',
  },
  onLoad() {
    that = this;
    dd.setNavigationBar({ title: "悬赏任务大厅" });
    this.setData({
      userId: app.globalData.userData.id
    })
  },
  onShow() {
    if (this.data.page == 1) {
      dd.hideLoading();
      that.getData();
    }
  },
  getData(is) {
    var data = {
      page: that.data.page,
      page_size: 20,
      hall_type: this.data.hall_type
    }
    app.$get('api/integral/task/hall', data).then((res) => {
      var data = res.data.data.list;
      var list = that.data.list;
      data.forEach(element => {
        if (element.pt_id) {
          element.pt_name = app.getTypesItem(element.pt_id).name
        }
      });
      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
        })
      }
    })
  },
  activeItem(e) {
    var index = e.target.dataset.index;
    this.setData({
      activeIndex: index,
      page: 1,
      list: [],
      sxObj: [],
      hall_type: index == 1 ? 'waiting' : 'catch'
    })
    this.getData();
  },
  openDetail(e) {
    var id = e.target.dataset.item.id;
    dd.navigateTo({
      url: '../taskDetail/taskDetail?id=' + id
    })
  },
  //上啦加载
  onScrollToLower() {
    if (!that.data.isData) {
      this.setData({ page: ++that.data.page })
      this.getData(true);
    }
  },
});
