var app = getApp()
var that;
Component({
  data: {
    list: [],//人员集合
    isData:'',
    page:1,
    selectEnevt:{},
    keyVal:'',
  },
  props: {
    onClose: (data) => console.log(data),
    onConfirm: (data) => console.log(data),
    defaultEnevt: '',
    defaultVal:'',
  },
  didMount() {
    that = this;
    this.setData({ keyVal: this.props.defaultVal,isVal:this.props.defaultVal? true:false })
    that.getlist();
  },
  methods: {
    radioChange: function(e) {
      this.setData({
        selectEnevt:e.detail.value
      })
    },
    onReset() {
      this.setData({
        isVal: false,
        keyVal: ''
      })
      that.getlist();
    },
    onConfirm() {
      this.props.onConfirm(this.data.selectEnevt,this.data.keyVal);
      this.onClose();
    },
    //搜索
    bindKeyInput(e) {
      this.setData({
        keyVal: e.detail.value,
        isVal: e.detail.value ? true : false
      })
      that.getlist();
    },
    //关闭
    onClose(e) {
      this.props.onClose();
    },
    //获取事件列表
    getlist(is) {
      app.$get2('api/integral/statistics/integral', {page:that.data.page, keyword:that.data.keyVal, page_size: 20}).then((res) => {
        var data = res.data.data.list;
        data.map((item) => {
          item.ptObj = app.getTypesItem(item.pt_id);
          item.checked=false;
          if(item.id==that.props.defaultEnevt){
            item.checked=true;
          }
        })
        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
          })
        }
      })
    },
    //上啦加载
    onScrollToLower() {
      if (!that.data.isData) {
        this.setData({ page: ++that.data.page })
        this.getlist(true);
      }
    },
  },
});
