orgIndex.js 10.6 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
import React from 'react'
import './orgIndex.less'
import axios from '@src/axios/index'
import Utils from '@src/utils/utils'
import { NavLink } from 'react-router-dom'
import { API_SYSORORG_MANAGE } from '@src/Api'
import UserManageBar from '@components/Common/WhiteBar/index'
import { Row, Col, Table, Form, Button, Input, Icon, message, Modal } from 'antd'
const FormItem = Form.Item;

class Organization extends React.Component {
  state = {
    tloading: false,
    searchInfo:{},
    expandStatus: false,
    isShowOpt:true,
  }
  componentWillMount() {
    let btnAuth = localStorage.btnAuth
    this.setState({btnAuth,})
    if(
      btnAuth.indexOf('org-edit') === -1 && 
      btnAuth.indexOf('org-delete') === -1 && 
      btnAuth.indexOf('addNextOrg') === -1 ){
        this.setState({isShowOpt: false})
      }

  }
  async componentDidMount() {
    this.getParamQuery()
  }

  //重置表单
  reset = () => {
    this.props.form.resetFields();
    let searchInfo = Utils.trim(this.props.form.getFieldsValue());
    this.setState({searchInfo},() => {
      this.getParamQuery()
    }) 
  }
  //刷新表单
  refresh= () => {
    this.getParamQuery()
  }

  //根据条件查询table数据
  queryList = () => {
     let searchInfo = Utils.trim(this.props.form.getFieldsValue());
      console.log(searchInfo);
      this.setState({searchInfo},() => {
      this.getParamQuery()
    })  
  }
  
  //获取用户信息多条件查询table数据
  getParamQuery = (item) => {
    this.setState({
          tloading: true,
        })
    let searchInfo=this.state.searchInfo
    axios.ajax({
      url: API_SYSORORG_MANAGE.getOrgByName,
      data: {
        ...searchInfo,
      }
    }).then(res => {
      if (res && res.length > 0) {
        //let list = Utils.formatTreeData(res)
        let list = res.map((item, index) => {
          item.key = index
          Utils.formatTreeData(item.childOrgs)
          return item
        })
        this.setState({
          list,
          tloading: false,
          selectedRowKeys: [],
          selectedRows: null,
        })
      } else {
        this.setState({
          list: [],
          tloading: false,
        })
      }

    })
  }
  //根据机构code查询下级机构
  getChildsOrgByCode = (code) => {
    this.setState({
          tloading: true,
        })
    axios.ajax({
      url: API_SYSORORG_MANAGE.getChildsOrgByCode,
      data: {
        ...code,
      }
    }).then(res => {
      console.log(res)
      if (res && res.length > 0) {
        let data = res.map((item, index) => {
           item.key = index
           return  item
        })
        const childList = Utils.formatTreeData(data, 'childOrgs')
        this.setState({
          childList,
          tloading: false,
          selectedRowKeys: [],
          selectedRows: null,
        })
      } else {
        this.setState({
          childList: [],
          tloading: false,
        })
      }

    })
  }

  //删除一行
  handleDelete = (oid,mName) => {
    if (oid) {
      Modal.confirm({
        title: '删除',
        content: `您要删除的机构为 : ${mName} ?`,
        okText: "确认",
        cancelText:"取消",
        onOk: () => {
          axios.ajax({
            url: API_SYSORORG_MANAGE.deleteOrg,
            data: { id: oid }
          }).then(res => {
            console.log(res);
            message.success('删除成功')
            this.getParamQuery();
          })
        }
      })

    } else {
      Modal.confirm({
        title: '警告',
        content: "请选择一条数据"
      })
    }

  }

  //选择一行数据
  onRowClick = (record, index) => {
    let selectKey = [index];
    console.log(record);

    this.setState({
      selectedRowKeys: selectKey,
      selectedItem: record
    })
  }
  //点击展开图标时触发,根据机构code查询下级机构
  onExpand = (expanded, record) => {
    console.log('expanded',expanded);
    console.log('record',record);
    //_this = this
    if(expanded){
      this.setState({
          tloading: true,
        })
   
      axios.ajax({
        url: API_SYSORORG_MANAGE.getChildsOrgByCode,
        data: {
          code:record.code,
        }
      }).then(res => {
        console.log(res)
        if (res && res.length > 0) {
          this.renderList(this.state.list,record,res)
          //let list = Utils.formatTreeData(res)
          let childList = res.map((item, index) => {
            item.key = index
            Utils.formatTreeData(item.childOrgs)
            return item
          })
          this.setState({
            childList,
            tloading: false,
            selectedRowKeys: [],
            selectedRows: null,
          })
        } else {
          this.setState({
            childList: [],
            tloading: false,
          })
        }

      })
    }
    
  }
  renderList = (data,record,res) => {
    data.map((item) => {
      if(item.code==record.code){
        item.childOrgs=res
      }else if(item.childOrgs && item.childOrgs.length>0 ){
         this.renderList(item.childOrgs,record,res)

      }
    })
          
  }
  //修改一行数据
  update = (oid) => {
     console.log(oid);
    if (oid) {
      this.props.history.push({
        pathname: '/home/orgManage/OrgAdd/updateItem/' + oid,
      });
    } else {
      Modal.confirm({
        title: '警告',
        content: "请选择一条数据"
      })
    }
  }
  newAddOrg = (oid) => {
     console.log(oid);
    if (oid) {
      this.props.history.push({
        pathname: '/home/orgManage/OrgAdd/addNextItem/' + oid,
      });
    } else {
      Modal.confirm({
        title: '警告',
        content: "请选择一条数据"
      })
    }
  }
   onSelectChange =(selectedRowKeys)=>{
    console.log('onSelectChange',selectedRowKeys);
    this.setState({ selectedRowKeys });
  }
  //展开授权功能菜单
  expandOrg = () => {
     this.setState({ 
      list: [], 
      defaultExpandAllRows: !this.state.ExpandStatus, 
      ExpandStatus: !this.state.ExpandStatus}, () => {
      this.getParamQuery()
    })  
  }

  // 展开条件
  expandMenu = ()=> {
    this.setState({
      expandStatus: !this.state.expandStatus,
    })
  }
  render() {
    const {btnAuth} = this.state
    const columns = [
      {
        title: '机构名称',
        key: 'name',
        dataIndex: 'name',
        align: 'left',
        className:'pLeft tdWidth',
        width: '150px',
        render(name) {
          return Utils.formatTableColumn(name)
        }
      },
       {
        title: '机构级别',
        key: 'orgGrade',
        dataIndex: 'orgGrade',
        width: '60px',
      },
      {
        title: '更新时间',
        key: 'updateTime',
        dataIndex: 'updateTime',
        width: '60px',
        render(updateTime) {
          return Utils.formateDateToYMD(updateTime)
        }
      },
       {
        title: '备注',
        key: 'remark',
        dataIndex: 'remark',
        width: '100px',
        className:'tdWidth',
        render(remark) {
          return Utils.formatTableColumn(remark)
        }
      }
    ]
    const opt={
        title: '操作',
        key: 'opereate',
        className:'pRight',
        width: '150px',
        align: 'right',
        render: (text, item) => {
          let oid=item.id
          let mName=item.name
          
          return (
            <div>
            {
              btnAuth.indexOf('org-edit') !== -1 ? <Button size="small" style={{ marginRight: 10 }} onClick={(item) => { this.update(oid) }} >修改</Button>:''
            }
            {
              btnAuth.indexOf('org-delete') !== -1 ?<Button size="small" style={{ marginRight: 10 }} onClick={(item) => { this.handleDelete(oid,mName) }} >删除</Button>:''
            }
              
            {
              btnAuth.indexOf('addNextOrg') !== -1 ?<Button size="small" onClick={(item) => { this.newAddOrg(oid) }}>新增下级机构</Button>:''
            }
            </div>
          )
        }
      }
      if (this.state.isShowOpt) {
        columns.push(opt)
      }
    const { getFieldDecorator } = this.props.form;
  
    return (
      <div className='orgbg'>
       <div className="searchWrap">
        <UserManageBar title="机构管理" />
          <div className='expandMenu iconfont icon-chazhaobiaodanliebiao' onClick={this.expandMenu} ></div>      
        { 
          this.state.expandStatus ? 
          <div className="userForm">
            <Form layout="inline">
              <Row gutter={10}>
                <Col span="4">
                  <FormItem  >
                    <label htmlFor="机构名称">机构名称</label>
                    {
                      getFieldDecorator('name', {

                      })(
                        <Input placeholder="机构名称" />
                      )
                    }
                  </FormItem>
                </Col>
                <Col span="20">
                  <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>     

       
        
        <div className="operate">
          {
             btnAuth.indexOf('org-add') !== -1 ? <NavLink replace to={'/home/orgManage/orgAdd/addItem'} ><Button>新增</Button></NavLink>:''
          }
          
          <Button onClick={this.refresh} style={{ display: 'none' }}>刷新</Button>
        </div>

        <UserManageBar title="详细数据" />
        <div className="detData reTable">
          <div style={{ backgroundColor: '#fff', minHeight:'500px' }}>
            <Table
              rowKey="id"
              key={`table-${this.state.list && this.state.list.length}`}
              bordered={false}
              columns={columns}
              align='left'
              dataSource={this.state.list}
              defaultExpandAllRows = {this.state.ExpandStatus }
              loading={this.state.tloading}
              childrenColumnName='childOrgs'
              selections={false}
              pagination={false}
               onRow={(record, index) => {
                return {
                  onClick: () => {
                    this.onRowClick(record, index);
                  }
                };
              }}
              onExpand={this.onExpand}
            />
          </div>
        </div>
      </div>
    )
  }
}

export default Form.create()(Organization);