
var app = getApp()
var that;
Page({
  data: {
    date: app.globalData.month,
    activeIndex: 1,
    httpType: 'waiting',
    keyword: '',
    page: 1,
    isBh: false,//是否显示驳回弹窗
    textArea: ""
  },
  onLoad() {
    that = this;
    dd.setNavigationBar({ title: "我的审批" });
  },
  onShow() {
    this.setData({
       page: 1,
    });
    that.getData();
  },
  bindTextAreaBlur(e) {
    this.setData({
      textArea: e.detail.value
    });
  },
  confirmBh() {
    var item = that.data.bhItem;
    if (that.data.textArea=='') {
      app.globalData.showToast("请输入审批意见");
      return;
    }
    app.$post("api/integral/review", { review_id: item.id, remark: that.data.textArea, action: "refuse", ticket_count: 0 }).then((res) => {
      that.closeBh()
      app.globalData.showToast("已驳回");
      setTimeout(() => {
        that.setData({ textArea: '', page: 1 });
        that.getData();
      }, 1000);;
    })
  },
  closeBh() {
    this.setData({ isBh: false,textArea:''})
  },
  openBh(e) {
    var item = e.target.dataset.item;
    this.setData({
      isBh: true,
      bhItem: item
    })
  },
  activeItem(e) {
    var index = e.target.dataset.index;
    this.setData({
      activeIndex: index,
      httpType: index == '1' ? 'waiting' : 'reviewed',
      page: 1,
      dataList: []
    })
    this.getData();
  },
  //选择规则分类
  bindKeyInput(e) {
    this.setData({
      keyword: e.detail.value,
      page: 1,
    });
    this.getData();
    dd.hideKeyboard();
  },
  openSearch() {
    app.globalData.showToast("暂不支持筛选");
  },
  openDetail(e) {
    var id = e.target.dataset.item.id;
    dd.navigateTo({
      url: '../approveDetail/approveDetail?id=' + id
    })
  },
  getData(type) {
    app.$get("api/integral/review/list", { type: that.data.httpType, page: that.data.page, pt_id: 0, page_size: 20, keyword: that.data.keyword }).then((res) => {
      var data = res.data.data.list || [];
      var dataList = that.data.dataList || [];
      if (type == '2') {
        if (data.length > 0) {
          this.setData({
            dataList: dataList.concat(data)
          })
        } else {
          this.setData({ isData: true })
          return;
        }
      } else {
        this.setData({ dataList: data,isData: false })
      }
    })
  },
  //上啦加载
  onScrollToLower() {
    if (!that.data.isData) {
      this.setData({ page: ++that.data.page })
      this.getData("2");
    } else {
      app.globalData.showToast("已无更多咯");
    }
  },
});
