const _Http = getApp().globalData.http;

Page({
  data: {
    loading: true,
    active: "",
    "content": {
      nocache: true,
      "pageNumber": 1,
      "pageTotal": 1,
      "pageSize": 20,
      total: 0,
      "where": {
        "condition": "",
      },
      sort: []
    },
    filter: [{
      label: "品牌",
      index: null,
      showName: "brandname", //显示字段
      valueKey: "brandname", //返回Key
      selectKey: "brandname", //传参 代表选着字段 不传参返回整个选择对象
      value: "", //选中值
      list: []
    }, {
      label: "领域",
      index: null,
      showName: "tradefield", //显示字段
      valueKey: "tradefield", //返回Key
      selectKey: "tradefield", //传参 代表选着字段 不传参返回整个选择对象
      value: "", //选中值
      list: []
    }]
  },
  onLoad(options) {
    this.getList(true)
  },
  /* 处理筛选 */
  handleFilter({
    detail
  }) {
    this.setData({
      'content.where.startdate':detail.startdate,
      'content.where.enddate':detail.enddate,
    })
    this.getList(true)
  },
  getList(init = false) {
    if (init.detail != undefined) init = init.detail;
    let content = this.data.content;
    if (init) content.pageNumber = 1;
    if (content.pageNumber > content.pageTotal) return;
    content.where.status = this.data.active;
    _Http.basic({
      "id": 20221226152904,
      "version": 1,
      content
    }).then(res => {
      console.log("开票申请列表", res)
      this.selectComponent('#ListBox').RefreshToComplete();
      this.setData({
        list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
        "content.pageNumber": res.pageNumber + 1,
        "content.pageTotal": res.pageTotal,
        "content.sort": res.sort,
        "content.total": res.total,
        loading: false
      })
    })
  },
  /* 去新增 */
  toAdd(){
    wx.navigateTo({
      url: '/packageA/remitVoucher/update'
    })
  },
  /* 搜索 */
  onSearch({
    detail
  }) {
    this.setData({
      "content.where.condition": detail
    });
    this.getList(true)
  },
  /* 切换tabs */
  tabsChange(e) {
    this.setData({
      "content.where.status": e.detail.name ? e.detail.name : '',
      active: e.detail.name ? e.detail.name : ''
    });
    this.getList(true);
  },
  onReady() {
    this.setListHeight()
  },
  /* 设置页面高度 */
  setListHeight() {
    this.selectComponent("#ListBox").setHeight(".total", this);
  },
})