var app = getApp()
var that;
Component({
  mixins: [],
  data: {
    all_user_list: {},
    isShow: false,
  },
  props: {
    onConfirm: (data) => console.log(data),
    onClose: (data) => console.log(data),
  },
  didMount() {
    that = this;
    this.setData({ isShow: this.props.isShow })
    this.getData();
  },
  didUpdate() { },
  didUnmount() { },
  methods: {
    //搜索
    bindKeyInput(e) {
      if (e.detail.value) {
        var all_user_list = this.data.all_user_list;
        var items = all_user_list.filter((item) => {
          return item.name.indexOf(e.detail.value) >= 0
        });
        this.setData({ userList: items });
      } else {
        this.setData({ userList: this.data.all_user_list });
      }

    },
    onConfirm() {
      this.props.onConfirm(this.data.selectUserId);
      this.props.onClose();
    },
    radioChange: function (e) {
      if (e.detail.value) {
        var arr = e.detail.value;
        this.setData({
          selectUserId: e.detail.value
        })
      } else {
        this.setData({
          selectUserId:[]
        })
      }
    },
    getData(keywords) {
      app.$get2("api/employee/list", { dept_id: 0, keywords: keywords }).then((res) => {
        this.setData({
          userList: res.data.data.list,
          all_user_list: res.data.data.list
        })
      })
    },
    //关闭
    onClose(e) {
      this.props.onClose();
    }
  },
});
