/** * 选择人员弹窗@author Lyq */ import React, { Component } from "react"; import { Modal, Icon } from "antd"; import { getPerBaseInfoListByPerids } from '../../../services/api'; import PersonList from './PersonList'; import $loading from '../../../utils/loading'; import "./index.less"; export default class PersonModal extends Component { constructor(props, context) { super(props, context); this.state = { visible: true, //是否弹出 selectedList: [], //已经被选中的人员 type: this.props.type || 'checkbox', isRequestAll: false //是否已经请求过所有用户的接口 }; } componentWillMount() { this.__init(); } componentDidMount() { } componentWillReceiveProps(props) { this.__init(props); } __init = (props) => { props = props || this.props; this.setState({ visible: props.visible, }); const type = obj => Object.prototype.toString.call(obj).slice(8, -1); const { value } = props; if(value) { if(type(value) == 'Array') { if(type(value[0]) == 'Object') { // 直接传入完整的数据的情况 this.setState({ selectedList: value.filter(item => item.perId) }); }else if(type(value[0]) == 'String') { // 传入的数组是id的集合的情况 this._getPerBaseInfoListByPerids(value.join(',')); } }else if(type(value) == 'String') { // 传入的是字符串的情况,用,分割 this._getPerBaseInfoListByPerids(value); } } } _getPerBaseInfoListByPerids(perIds) { getPerBaseInfoListByPerids({perIds}).then(res => { this.setState({ selectedList: res.data }); }); } // _initValue = (cb) => { // if(!this.state.isRequestAll) { // this.setState({ // isRequestAll: true // }, () => { // $loading.open('数据请求中...'); // // 获取所有部门数据 获取所有人员 // getTreeperBydepart({}).then(response => { // this.setState({ // allPers: response.data // }, () => { // $loading.close(); // cb && cb(); // }); // }).catch(ex => { // $loading.close(); // }); // }); // }else { // cb && cb(); // } // } // _restructure = valueArray => { // $loading.open('数据处理中...'); // const selectedList = []; // const allStr = JSON.stringify(this.state.allPers); // valueArray.forEach(perId => { // if(perId && allStr.indexOf(perId) > 0) { // // 使用正则获取对应的值 // // const reg = new RegExp('(.*)(\{.*?\"key\":\"' + perId + '\",.*?\})(.*)'); // // 前半部分用key+id分割 // const reg = new RegExp('(.*)(\{.*?\"key\":\"' + perId + '\",.*\})(.*)'); // // 后半部分用children分割 // // const childrenReg = /(.*?,+\"children\":\".*?\".*?\})(.*)/; // // const childrenReg = /,+\"children\":\[.*\]/; // // const itemStr = allStr.replace(reg, '$2').replace(childrenReg, ''); // const str = allStr.replace(reg, '$2'); // selectedList.push({ // perId: str.replace(/(.*?\"key\":\")(.*?\")(.*)/, "$2").slice(0, -1), // name: str.replace(/(.*?\"label\":\")(.*?\")(.*)/, "$2").slice(0, -1), // mobilePhone: str.replace(/(.*?\"mobilePhone\":\")(.*?\")(.*)/, "$2").slice(0, -1), // idCardNo: str.replace(/(.*?\"idCardNo\":\")(.*?\")(.*)/, "$2").slice(0, -1) // }); // this.setState({ // selectedList // }); // // try { // // // 转成对应的格式 // // // const item = JSON.parse(itemStr); // // }catch (ex) { // // console.log(ex); // // } // } // }); // $loading.close(); // } render() { // const close = () => { // this.setState({ visible: false }); // }; const { selectedList } = this.state; return (
注:勾选部门只能选中该部门层级的人,该部门下级部门的人员需要单独勾选。
} { this.state.type == 'checkbox' && this.props.fetchType == 'task' &&注:勾选部门只能选中该部门层级的人,该部门下级部门的人员需要单独勾选;驻勤人员只能选择普通保安员/武装押运人员。
}