var app = getApp() var that; Component({ mixins: [], data: { all_user_list: {}, isShow: false, keyVal:'' }, props: { onConfirm: (data) => console.log(data), onClose: (data) => console.log(data), defaultUser: '', }, didMount() { that = this; this.setData({ isShow: this.props.isShow }) this.getData(); }, didUpdate() { }, didUnmount() { }, methods: { onReset(){ this.setData({ isVal: false, keyVal:'' }) }, //搜索 bindKeyInput(e) { this.setData({ keyVal:e.detail.value, isVal: e.detail.value ? true : false }) }, onConfirm() { this.props.onConfirm(this.data.selectUserId); this.props.onClose(); }, radioChange: function (e) { var selectUserId = this.data.selectUserId; var isExist = false; let item = e.target.dataset.item; let index = e.target.dataset.index; let checked = `userList[${index}].checked`;//获取当前控制选中的字段 let elm = this.data.userList[index].checked;//当前的状态 this.setData({ [checked]: !elm, }) if (e.detail.value) {//当有值时选中 selectUserId.forEach((element, _this) => { if (element.id == item.id) { isExist = true; } }); if (!isExist) { selectUserId.push(item); } } else {//取消选中 selectUserId.forEach((element, index, _this) => { if (element.id == item.id) { _this.splice(index, 1); } }); } this.setData({ selectUserId: selectUserId }) }, getData(keywords) { app.$get("api/employee/list", { dept_id: 0, keywords: keywords }).then((res) => { var list = res.data.data.list; var arr = this.props.defaultUser; if(typeof(arr)=='string'){ // arr=arr.substr(1, arr.length-2); arr= arr.split(','); } var ids=[],userList=list; // list.forEach(item=>{ // if(item.is_official==1){ // userList.push(item) // } // }) userList.map(item=>{ item.checked = false; if (arr.length > 0) { arr.forEach(item2 => { if (item.id == item2) { item.checked = true; ids.push(item); } }) } }) this.setData({ userList: userList, all_user_list: userList, selectUserId:ids.length>0? ids:[] }) }) }, //关闭 onClose(e) { this.props.onClose(); } }, });