personal.js 14.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
import React from 'react'
import './personal.less'
import axios from '@src/axios/index'
import Utils from '@src/utils/utils'
import { OrgOptionsForm, UserManageBar } from '@components/Common'
import { API_USER_MANAGE ,API_SYSORORG_MANAGE} from '@src/Api'
import { Row, Col, Table, Form, Button, Input,Select, Icon, message, Modal,Tree,Layout } from 'antd'
import storage from '@src/utils/localStorage'

const FormItem = Form.Item;
const Option = Select.Option;
const {Sider,Content } = Layout;
const TreeNode = Tree.TreeNode;
const DirectoryTree =Tree.DirectoryTree

class Personal extends React.Component {
  expandedKeys=[]
  state = {
    getOrgOptionsName: {},//组织机构
    checkedObj: {},//选中组织对象
    tloading: false,
    searchInfo:{},
    orgVisible: false,//机构弹窗显示
    orgOptionsArr: [],//组织机构数组
    page: 1,
    pageSize: 10,
    checkedKeys: {},
    expandStatus: false,
    isShowOpt:true,
    widthX:1000
    
  }
  async componentWillMount() {
    let btnAuth = localStorage.btnAuth
    this.setState({btnAuth,})
    if(btnAuth.indexOf('people-lookMore') === -1){
      this.setState({isShowOpt: false,widthX:1000})
    }
    //获取机构树状图
    await this.getOrgTreeList()
    //获取用户信息列表
    this.getParamQuery()
  }
  async componentDidMount() {
     //根据机构名称查询
    this.getOrgByName()

  }

  //重置表单
  reset = () => {
    this.props.form.resetFields();
    this.getParamQuery()
  }
 

  //根据条件查询table数据
  queryList = () => {
     let searchInfo = Utils.trim(this.props.form.getFieldsValue());
      this.setState({page:1})  
      this.getParamQuery(searchInfo)
  }

  //获取用户信息多条件查询table数据
  getParamQuery = (item) => {
    let _this = this
    this.setState({
          tloading: true,
        })
    axios.ajax({
      url: API_USER_MANAGE.getParamQuery,
      data: {
        ...item,
        pageNum: this.state.page,
        pageSize: this.state.pageSize
      }
    }).then(res => {
      if (res.records && res.records.length > 0) {

        let list = res.records.map((item, index) => {
          item.key = index
          return item
        })
        this.setState({
          list,
          tloading: false,
          selectedRowKeys: [],
          selectedRows: null,
          pagination: Utils.pagination(res, (current) => {
            _this.state.page = current;
            _this.queryList();
          }),
          minHeight:res.total % 10 ===0?  '500px':'567px'
        })
      } else {
        this.setState({
          list: [],
          tloading: false,
          pagination: Utils.pagination(res, (current) => {
            _this.state.page = current;
            _this.queryList();
          }),
          minHeight:'567px'
        })
      }

    })
  }

  //获取expandedKeys 数组
  getExpandedKeys =(data)=>{
    if(!data || data.length ===0) return []
    if(data && data.length >0 ){

      return  data.map(k=>{
        if(k.childOrgs && k.childOrgs.length >0){
           this.getExpandedKeys(k.childOrgs)
        }
        this.expandedKeys.push(k.id.toString())
        
      })
    }
  }
  //根据机构名称查询
  getOrgByName = (item) => {
    axios.ajax({
      url: API_SYSORORG_MANAGE.getOrgByName,
      data: {
        name: item
      }

    }).then(res => {
      if (res && res.length > 0) {
        let orgList = res.map((item, index) => {
          item.key = index
          return item
        })
        this.getExpandedKeys(res)
        this.setState({
          orgList,
          selectedRowKeys: [],
          selectedRows: null,
        })
      } else {
        this.setState({
          orgList: [],
        })
      }

    })
  }
  // 机构清空
  onRef = (ref) => {
    this.child = ref;
  }
  //选择一行数据
  onRowClick = (record, index) => {
    let selectKey = [index];
    this.setState({
      selectedRowKeys: selectKey,
      selectedItem: record
    })
  }
  //获取机构树状图
  getOrgTreeList = () => {
   this.setState({
      tloading: true,
    })
    return new Promise((resolve, reject) => {
      axios.ajax({
        url: API_SYSORORG_MANAGE.getOrgTreeList,
      }).then(res => {
        if (res && res.length > 0) {
          let orgOptionsArr = res.map((item, index) => {
            item.key = index
            item.name = item.name.substring(0, 10)
            return item
          })
          this.setState({
            tloading: false,
            orgList:orgOptionsArr,
            orgOptionsArr,
            expandedKeys:this.expandedKeys
          })
          resolve(this.getOrgOptionsName(res))
        } else {
           this.setState({
            tloading: false,
            orgList:[],
            orgOptionsArr: []
          })
        }
      })
    })
  }
  //对机构进行扁平处理
  getOrgOptionsName = (data) => {
    const { getOrgOptionsName } = this.state
    let that = this
    if (data && data.length > 0) {
      data.map(item => {
        let id = item.id, name = item.name
        if (item.childOrgs && item.childOrgs.length > 0) {
          that.getOrgOptionsName(item.childOrgs)
        }
        Object.assign(getOrgOptionsName, { [id]: name })
      })
    }
    return getOrgOptionsName
  }
  //菜单渲染
  renderTree = (data) => {
    return data.map((item) => {
      if (item.childOrgs && item.childOrgs.length > 0) {
        return (
          <TreeNode 
            title={<span>{ Utils.formatTableColumn(item.name) }</span>}
            name={item.name}
            key={item.id}
          >

            {this.renderTree(item.childOrgs)}
          </TreeNode>
        )
      }
      return <TreeNode title={<span>{ Utils.formatTableColumn(item.name) }</span>} key={item.id} name={item.name}>
       
      </TreeNode>

    })
  }
  //选中机构
  onSelect = (checkedKeys, e) => {
    //let searchInfo = Utils.trim(this.props.form.getFieldsValue());
    console.log('checkedKeys',checkedKeys)
    //this.props.form.setFieldsValue({ 'orgId': checkedKeys[0] })
    let searchInfo={}
    searchInfo.orgId=checkedKeys && checkedKeys.length>0 ?checkedKeys[0]:''
    this.getParamQuery(searchInfo)
    this.setState({
      checkedObj:  {
          key: checkedKeys[0],
          val: e.node.props.name
        }
    })

  }
  //显示所属机构弹窗
  orgOptions = () => {
    this.setState({
      orgVisible: true
    })

  }
    //机构弹窗
  handleOrgOptions = () => {
    const checkedObj = this.state.checkedObj
    if (Object.keys(checkedObj).length == 0 || !checkedObj) {
      message.warn('请选择对应的机构')
      return
    } else {
      this.setState({
        checkedObj
      })
      this.props.form.setFieldsValue({ 'orgId': checkedObj.key })
      this.setState({
        orgVisible: false
      })
    }
  }
  //获取所属机构
  getCheckedObj = (obj) => {
    this.setState({
      checkedObj: obj
    })
  }
  //查看详情
  lookDetail=(item,uid)=>{
    if (uid) {
      this.props.history.push({
        pathname: '/home/orgManage/personaDetail/' + uid,
      });
    } else {
      Modal.confirm({
        title: '警告',
        content: "请选择一条数据"
      })
    }
  }
  onExpand = (expandedKeys) => {
    this.setState({
      expandedKeys,
      autoExpandParent: false,
    });
  }

   // 展开条件
   expandMenu = ()=> {
    this.setState({
      expandStatus: !this.state.expandStatus,
    })
  }
  render() {
    const {btnAuth} = this.state
    const columns = [
      {
        title: '用户昵称',
        key: 'userName',
        dataIndex: 'userName',
        className:' tdWidth',
        width: 100,
        align: 'center',
        //fixed: 'left',
        render(userName) {
          return Utils.formatTableColumn(userName)
        }
      },
      {
        title: '登录账号',
        key: 'loginName',
        dataIndex: 'loginName',
        className:' tdWidth',
        width: 100,
        align: 'center',
        //fixed: 'left',
        render(loginName) {
          return Utils.formatTableColumn(loginName)
        }
      },
      {
        title: '证件号码',
        key: 'certNo',
        dataIndex: 'certNo',
        width: 200,
        align: 'center',
      },
       {
        title: '手机号码',
        key: 'mobile',
        dataIndex: 'mobile',
        width: 150,
        align: 'center',
      },
       {
        title: '邮箱',
        key: 'email',
        dataIndex: 'email',
        width: 150,
        align: 'center',
      },
      {
        title: '入职时间',
        key: 'joinTime',
        dataIndex: 'joinTime',
        width: 100,
        align: 'center',
        render(joinTime) {
          return Utils.formateDateToYMDSFM(joinTime)
        }
      },
       {
        title: '状态',
        key: 'status',
        dataIndex: 'status',
        width: 100,
        align: 'center',
        render(status) {
          return {
          0: <span>其他</span>,
          1: <span>未激活</span>,
          2: <span className= "textDefault">正常</span>,
          3: <span className= "textDanger">禁用</span>,
          4: <span className= "textWarn">锁定</span>,
        }[status]
        }
      }
    ]
    const opt ={
        title: '操作',
        key: 'opereate',
        width: 100,
        align: 'center',
        render: (text, item) => {
          let uid=item.uid
          return (
            <div  >
              {
              btnAuth.indexOf('people-lookMore') !== -1 ?<Button size="small" onClick={(item) => { this.lookDetail(item,uid) }} >查看详情</Button>:''
              }
            </div>
          )
        }
      }
      if (this.state.isShowOpt) {
        columns.push(opt)
      }
    const { getFieldDecorator } = this.props.form;
  
    return (
      <div className='personbg'>
        <div className="searchWrap">
          <UserManageBar title="组织人员" />
          <div className='expandMenu iconfont icon-chazhaobiaodanliebiao' onClick={this.expandMenu} ></div>
         
        { 
          this.state.expandStatus ? 
          <div className="personForm">
            <Form>
              <Row gutter={10}>
                <Col span="4">
                  <FormItem  >
                    <label htmlFor="用户昵称">用户昵称</label>
                    {
                      getFieldDecorator('userName', {

                      })(
                        <Input placeholder="用户昵称" />
                      )
                    }
                  </FormItem>
                </Col>
                <Col span="4">
                  <FormItem  >
                    <label htmlFor="登录账号">登录账号</label>
                    {
                      getFieldDecorator('loginName', {

                      })(
                        <Input placeholder="登录账号" />
                      )
                    }
                  </FormItem>
                </Col>
                <Col span="4">
                  <FormItem>
                    <label htmlFor="所属机构">所属机构</label>
                    {
                      getFieldDecorator('orgId', {

                      })(
                        <Select disabled showArrow={false} placeholder="所属机构">
                          <Option value={this.state.checkedObj.key} >{this.state.checkedObj.val}</Option>
                        </Select>
                      )
                    }
                  </FormItem>
                </Col>
                <Col span="1">
                  <FormItem    >
                    <Icon className="orghover" onClick={this.orgOptions} type="appstore" />
                  </FormItem>
                </Col>

                <Col span="8">
                  <FormItem style={{ marginTop: 38, }} >
                  <Button onClick={(item) => { this.queryList(item) }} style={{ background: '#00BB29', color: "#fff", marginRight: 4 }} >查询</Button>
                  <Button onClick={this.reset} style={{ background: '#ED1719', color: "#fff" }} type="danger">重置</Button>
                </FormItem>
                </Col>
              </Row>
              
            </Form>
        </div>       
          : ''
        }    
        </div>      

       
        <Layout className="personalMain" style={{ marginBottom: '10px', }}>
          <Sider className="personalMenu" >
            <DirectoryTree
              className="orgPersonalTree"
              showIcon={false}
              expandAction="doubleClick"
              onExpand={this.onExpand}
              expandedKeys={this.state.expandedKeys}
              onSelect={(checkedKeys, e) => { this.onSelect(checkedKeys, e) }}
            >
              {this.renderTree(this.state.orgOptionsArr)}
            </DirectoryTree>
          </Sider>
          <Content>
          <div className="detData reTable personalTable">
            <div style={{ backgroundColor: '#fff',  marginTop: '10px',marginRight: '26px',minHeight:this.state.minHeight }}>
              <Table
                bordered={false}
                columns={columns}
                align='left'
                dataSource={this.state.list}
                loading={this.state.tloading}
                selections={false}
                pagination={this.state.pagination}
                 onRow={(record, index) => {
                  return {
                    onClick: () => {
                      this.onRowClick(record, index);
                    }
                  };
                }}
              />
            </div>
          </div>
          </Content>
        </Layout>
        {/* 所属机构弹窗 */}
        <Modal
          title="所属机构"
          visible={this.state.orgVisible}
          width={800}
          className="modal"
          cancelText="取消"
          okText="确定"
          onOk={this.handleOrgOptions}
          onCancel={() => {
            this.child.reset();
            this.setState({
              orgVisible: false,
              checkedObj:""
            })

          }}
        >
          <OrgOptionsForm
            getOrgByName={(orgName) => this.getOrgByName(orgName)}
            getOrgTreeList={this.getOrgTreeList}
            orgOptionsArr={this.state.orgList}
            getCheckedObj={this.getCheckedObj}
            onRef={this.onRef}
          ></OrgOptionsForm>
        </Modal>
      </div>
    )
  }
}

export default Form.create()(Personal);