user.jsx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. import React from 'react';
  2. import ReactDom from 'react-dom';
  3. import ajax from 'jquery/src/ajax/xhr.js';
  4. import $ from 'jquery/src/ajax';
  5. import { Form, Radio, Icon, Button, Input, Select, AutoComplete, Spin, Table, Switch, message, DatePicker, Modal, Upload } from 'antd';
  6. import Newuser from "./newUser.jsx"
  7. import './userMangagement.less'
  8. import { techAuditStatusList, station, post } from '../../../dataDic.js';
  9. import {getPost,getStation} from '../../../tools.js';
  10. const User = Form.create()(React.createClass({
  11. loadData(pageNo) {
  12. this.state.data = [];
  13. this.setState({
  14. userDetaile:false,
  15. loading: true,
  16. page:pageNo
  17. });
  18. var admin=window.adminData.isSuperAdmin||'';
  19. var departmentId=window.adminData.departmentId||'';
  20. $.ajax({
  21. method: "get",
  22. dataType: "json",
  23. crossDomain: false,
  24. url: globalConfig.context + '/api/admin/superviser/adminList',
  25. data: {
  26. pageNo: pageNo || 1,
  27. pageSize: this.state.pagination.pageSize,
  28. name: this.state.userNameSearch,
  29. departmentId: admin?this.state.organizationSearch:departmentId,
  30. rid: this.state.rolesSearch,
  31. duty: this.state.postSearch,
  32. position: this.state.stationSearch,
  33. status: this.state.statusSeach,
  34. mobile: this.state.signNameSearch,
  35. superiorId: this.state.theTypes
  36. },
  37. success: function(data) {
  38. let theArr = [];
  39. if(!data.data || !data.data.list) {
  40. if(data.error && data.error.length) {
  41. message.warning(data.error[0].message);
  42. };
  43. } else {
  44. for(let i = 0; i < data.data.list.length; i++) {
  45. let thisdata = data.data.list[i];
  46. theArr.push({
  47. key: i,
  48. id: thisdata.id,
  49. mobile: thisdata.mobile,
  50. name: thisdata.name,
  51. email: thisdata.email,
  52. createTime: thisdata.createTime,
  53. province: thisdata.province,
  54. position: thisdata.position,
  55. superior: thisdata.superior, //上级名称
  56. superiorId: thisdata.superiorId, //上级Id
  57. duty: thisdata.duty, //职务
  58. status: thisdata.status,
  59. userNo: thisdata.userNo,
  60. departmentName: thisdata.departmentName, //部门名称
  61. departmentId: thisdata.departmentId, //部门id
  62. roles:thisdata.roles[0],
  63. rolesId:thisdata.rolesId
  64. });
  65. };
  66. this.state.pagination.current = data.data.pageNo ? data.data.pageNo : '0';
  67. this.state.pagination.total = data.data.totalCount ? data.data.totalCount : '0';
  68. };
  69. if(!data.data.list.length){
  70. this.state.pagination.current=0
  71. this.state.pagination.total=0
  72. }
  73. this.setState({
  74. dataSource: theArr,
  75. pagination: this.state.pagination,
  76. selectedRowKeys:[]
  77. });
  78. }.bind(this),
  79. }).always(function() {
  80. this.setState({
  81. loading: false
  82. });
  83. }.bind(this));
  84. },
  85. getInitialState() {
  86. return {
  87. datauser: {},
  88. searchMore: true,
  89. selectedRowKeys: [],
  90. selectedRows: [],
  91. userDetaile: false,
  92. departmentArr: [],
  93. loading: false,
  94. roleArr:[],
  95. pagination: {
  96. defaultCurrent: 1,
  97. defaultPageSize: 10,
  98. showQuickJumper: true,
  99. pageSize: 10,
  100. onChange: function(page) {
  101. this.loadData(page);
  102. }.bind(this),
  103. showTotal: function(total) {
  104. return '共' + total + '条数据';
  105. }
  106. },
  107. columns: [{
  108. title: '用户编号',
  109. dataIndex: 'userNo',
  110. key: 'userNo',
  111. }, {
  112. title: '登录用户名',
  113. dataIndex: 'mobile',
  114. key: 'mobile',
  115. }, {
  116. title: '角色',
  117. dataIndex: 'roles',
  118. key: 'roles',
  119. }, {
  120. title: '用户姓名',
  121. dataIndex: 'name',
  122. key: 'name',
  123. }, {
  124. title: '部门',
  125. dataIndex: 'departmentName',
  126. key: 'departmentName',
  127. }, {
  128. title: '职务',
  129. dataIndex: 'duty',
  130. key: 'duty',
  131. render: text => { return getPost(text) }
  132. },
  133. {
  134. title: '岗位',
  135. dataIndex: 'position',
  136. key: 'position',
  137. render: text => { return getStation(text) }
  138. },
  139. {
  140. title: '上级主管姓名',
  141. dataIndex: 'superior',
  142. key: 'superior',
  143. },
  144. {
  145. title: '状态',
  146. dataIndex: 'status',
  147. key: 'status',
  148. }
  149. ],
  150. dataSource: [],
  151. };
  152. },
  153. componentWillMount() {
  154. this.loadData();
  155. this.departmentList();
  156. this.rolesList();
  157. },
  158. tableRowClick(record, index) {
  159. this.rolesArrS(record)
  160. this.setState({
  161. userDetaile:true,
  162. showDesc: true,
  163. datauser:record
  164. });
  165. },
  166. //新建获取id
  167. addIdS() {
  168. $.ajax({
  169. method: "post",
  170. dataType: "json",
  171. crossDomain: false,
  172. url: globalConfig.context + '/api/admin/superviser/newId',
  173. data: {},
  174. success: function(data) {
  175. this.setState({
  176. addId: data.data
  177. });
  178. }.bind(this),
  179. }).always(function() {
  180. this.setState({
  181. loading: false
  182. });
  183. }.bind(this));
  184. },
  185. //部门
  186. departmentList() {
  187. this.setState({
  188. loading: true
  189. });
  190. $.ajax({
  191. method: "post",
  192. dataType: "json",
  193. crossDomain: false,
  194. url: globalConfig.context + "/api/admin/organization/selectSuperId",
  195. data: {
  196. },
  197. success: function(data) {
  198. let thedata = data.data;
  199. let theArr = [];
  200. if(!thedata) {
  201. if(data.error && data.error.length) {
  202. message.warning(data.error[0].message);
  203. };
  204. thedata = {};
  205. } else {
  206. thedata.map(function(item, index) {
  207. theArr.push({
  208. key: index,
  209. name: item.name,
  210. id: item.id,
  211. depNo: item.depNo
  212. })
  213. })
  214. }
  215. this.setState({
  216. departmentArr: theArr,
  217. })
  218. }.bind(this),
  219. }).always(function() {
  220. this.setState({
  221. loading: false
  222. });
  223. }.bind(this));
  224. },
  225. //修改时获取角色数组
  226. rolesArrS(e) {
  227. $.ajax({
  228. method: "get",
  229. dataType: "json",
  230. crossDomain: false,
  231. url: globalConfig.context + "/api/admin/role",
  232. data: {
  233. uid:e.id
  234. },
  235. success: function(data) {
  236. let thedata = data.data;
  237. let theArr = [];
  238. let theId=[]
  239. if(!thedata) {
  240. if(data.error && data.error.length) {
  241. message.warning(data.error[0].message);
  242. };
  243. thedata = {};
  244. } else {
  245. }
  246. this.setState({
  247. role:thedata
  248. })
  249. }.bind(this),
  250. }).always(function() {
  251. }.bind(this));
  252. },
  253. //角色
  254. rolesList() {
  255. this.setState({
  256. loading: true
  257. });
  258. $.ajax({
  259. method: "get",
  260. dataType: "json",
  261. crossDomain: false,
  262. url: globalConfig.context + "/api/roles",
  263. data: {
  264. },
  265. success: function(data) {
  266. let thedata = data.data;
  267. let theArr = [];
  268. if(!thedata) {
  269. if(data.error && data.error.length) {
  270. message.warning(data.error[0].message);
  271. };
  272. thedata = {};
  273. } else {
  274. thedata.map(function(item, index) {
  275. theArr.push({
  276. key: index,
  277. roleName: item.roleName,
  278. id: item.id,
  279. })
  280. })
  281. }
  282. this.setState({
  283. roleArr: theArr,
  284. })
  285. }.bind(this),
  286. }).always(function() {
  287. this.setState({
  288. loading: false
  289. });
  290. }.bind(this));
  291. },
  292. //锁定
  293. locking() {
  294. let deletedIds;
  295. let statust;
  296. let mobiles;
  297. let names;
  298. let rolesId=[];
  299. for(let idx = 0; idx < this.state.selectedRows.length; idx++) {
  300. let rowItem = this.state.selectedRows[idx];
  301. if(rowItem.id) {
  302. deletedIds=rowItem.id;
  303. statust=rowItem.status;
  304. names=rowItem.name;
  305. mobiles=rowItem.mobile;
  306. rolesId=rowItem.rolesId
  307. };
  308. };
  309. this.setState({
  310. selectedRowKeys: [],
  311. loading: true
  312. });
  313. $.ajax({
  314. method: "POST",
  315. dataType: "json",
  316. crossDomain: false,
  317. url: globalConfig.context + "/api/admin/superviser/updateAdmin",
  318. data: {
  319. roles:rolesId,
  320. data:JSON.stringify({
  321. id: deletedIds,
  322. status: '锁定',
  323. name: names,
  324. mobile: mobiles,
  325. }),
  326. }
  327. }).done(function(data) {
  328. if(!data.error.length) {
  329. message.success('锁定成功!');
  330. this.setState({
  331. loading: false,
  332. });
  333. } else {
  334. message.warning(data.error[0].message);
  335. };
  336. this.loadData();
  337. }.bind(this));
  338. },
  339. //激活
  340. activation() {
  341. let deletedIds;
  342. let statust;
  343. let mobiles;
  344. let names;
  345. let rolesId=[]
  346. for(let idx = 0; idx < this.state.selectedRows.length; idx++) {
  347. let rowItem = this.state.selectedRows[idx];
  348. if(rowItem.id) {
  349. deletedIds=rowItem.id;
  350. statust=rowItem.status;
  351. names=rowItem.name;
  352. mobiles=rowItem.mobile;
  353. rolesId=rowItem.rolesId
  354. };
  355. };
  356. this.setState({
  357. selectedRowKeys: [],
  358. loading: true
  359. });
  360. $.ajax({
  361. method: "POST",
  362. dataType: "json",
  363. crossDomain: false,
  364. url: globalConfig.context + "/api/admin/superviser/updateAdmin",
  365. data: {
  366. roles:rolesId,
  367. data:JSON.stringify({
  368. id: deletedIds,
  369. status: '正常',
  370. name: names,
  371. mobile: mobiles,
  372. })
  373. }
  374. }).done(function(data) {
  375. if(!data.error.length) {
  376. message.success('激活成功!');
  377. this.setState({
  378. loading: false,
  379. });
  380. } else {
  381. message.warning(data.error[0].message);
  382. };
  383. this.loadData();
  384. }.bind(this));
  385. },
  386. //删除
  387. delectRow() {
  388. let deletedIds;
  389. for(let idx = 0; idx < this.state.selectedRows.length; idx++) {
  390. let rowItem = this.state.selectedRows[idx];
  391. if(rowItem.id) {
  392. deletedIds=rowItem.id;
  393. };
  394. };
  395. this.setState({
  396. selectedRowKeys: [],
  397. loading: true
  398. });
  399. $.ajax({
  400. method: "POST",
  401. dataType: "json",
  402. crossDomain: false,
  403. url: globalConfig.context + "/api/admin/superviser/deleteById",
  404. data: {
  405. id: deletedIds,
  406. }
  407. }).done(function(data) {
  408. if(!data.error.length) {
  409. message.success('删除成功!');
  410. this.setState({
  411. loading: false,
  412. });
  413. } else {
  414. message.warning(data.error[0].message);
  415. };
  416. this.loadData(this.state.page);
  417. }.bind(this));
  418. },
  419. addClick() {
  420. this.addIdS()
  421. this.state.userDetaile = false;
  422. this.setState({
  423. showDesc: true
  424. });
  425. },
  426. closeDesc(e, s) {
  427. this.state.userDetaile=false;
  428. this.state.showDesc = e;
  429. if(s) {
  430. this.loadData(this.state.page);
  431. };
  432. },
  433. search() {
  434. this.state.userDetaile = false
  435. this.loadData();
  436. },
  437. reset() {
  438. this.state.userNameSearch = '';
  439. this.state.organizationSearch = undefined;
  440. this.state.rolesSearch = undefined;
  441. this.state.postSearch = undefined;
  442. this.state.stationSearch = undefined;
  443. this.state.statusSeach = undefined;
  444. this.state.signNameSearch = '';
  445. this.state.mobileSearch = '';
  446. this.state.auto = '';
  447. this.state.theTypes='';
  448. this.loadData();
  449. },
  450. searchSwitch() {
  451. this.setState({
  452. searchMore: !this.state.searchMore
  453. });
  454. },
  455. //主管初始加载(自动补全)
  456. supervisor(e) {
  457. $.ajax({
  458. method: "post",
  459. dataType: "json",
  460. crossDomain: false,
  461. url: globalConfig.context + "/api/admin/organization/selectName",
  462. data: {
  463. name: e
  464. },
  465. success: function(data) {
  466. let thedata = data.data;
  467. if(!thedata) {
  468. if(data.error && data.error.length) {
  469. message.warning(data.error[0].message);
  470. };
  471. thedata = {};
  472. };
  473. this.setState({
  474. customerArr: thedata,
  475. });
  476. }.bind(this),
  477. }).always(function() {
  478. this.setState({
  479. loading: false
  480. });
  481. }.bind(this));
  482. },
  483. //上级主管输入框失去焦点是判断客户是否存在
  484. selectAuto(value, options) {
  485. this.setState({
  486. auto: value
  487. })
  488. },
  489. blurChange(e) {
  490. let theType = '';
  491. let contactLists = this.state.customerArr || [];
  492. if(e) {
  493. contactLists.map(function(item) {
  494. if(item.name == e.toString()) {
  495. theType = item.id;
  496. }
  497. });
  498. }
  499. this.setState({
  500. theTypes: theType
  501. })
  502. },
  503. //值改变时请求客户名称
  504. httpChange(e) {
  505. if(e.length >= 1) {
  506. this.supervisor(e);
  507. }
  508. this.setState({
  509. auto: e
  510. })
  511. },
  512. render() {
  513. const rowSelection = {
  514. selectedRowKeys: this.state.selectedRowKeys,
  515. onChange: (selectedRowKeys, selectedRows) => {
  516. this.setState({
  517. selectedRows: selectedRows.slice(-1),
  518. selectedRowKeys: selectedRowKeys.slice(-1)
  519. });
  520. },
  521. onSelectAll: (selected, selectedRows, changeRows) => {
  522. this.setState({
  523. selectedRowKeys: []
  524. })
  525. },
  526. };
  527. const dataSources = this.state.customerArr || [];
  528. const options = dataSources.map((group, index) =>
  529. <Select.Option key={index} value={group.name}>{group.name}</Select.Option>
  530. )
  531. const hasSelected = this.state.selectedRowKeys.length > 0;
  532. const { RangePicker } = DatePicker;
  533. let departmentArr = this.state.departmentArr || [];
  534. let roleArr = this.state.roleArr || [];
  535. return(
  536. <div className="user-content" >
  537. <div className="content-title">
  538. <div className="user-search">
  539. <Input placeholder="用户姓名" style={{width:'150px'}}
  540. value={this.state.userNameSearch}
  541. onChange={(e) => { this.setState({ userNameSearch: e.target.value }); }} />
  542. {window.adminData.isSuperAdmin?<Select placeholder="部门"
  543. style={{ width: 160 }}
  544. value={this.state.organizationSearch}
  545. onChange={(e) => { this.setState({ organizationSearch: e }) }}>
  546. {
  547. departmentArr.map(function (item) {
  548. return <Select.Option key={item.id} >{item.name}</Select.Option>
  549. })
  550. }
  551. </Select>:''}
  552. <Select placeholder="角色"
  553. style={{ width: 160 }}
  554. value={this.state.rolesSearch}
  555. onChange={(e) => { this.setState({ rolesSearch: e }) }}>
  556. {
  557. roleArr.map(function (item) {
  558. return <Select.Option key={item.id} >{item.roleName}</Select.Option>
  559. })
  560. }
  561. </Select>
  562. <Button type="primary" onClick={this.search}>搜索</Button>
  563. <Button onClick={this.reset}>重置</Button>
  564. <Button style={{ background: "red", border: "none", color: "#fff" }}
  565. disabled={!hasSelected}
  566. onClick={this.delectRow} style={{display:"none"}}>删除<Icon type="minus" /></Button>
  567. <Button style={{ background: "#333333", border: "none", color: "#fff" }}
  568. disabled={!hasSelected}
  569. onClick={this.locking}>锁定<Icon type="lock" /></Button>
  570. <Button style={{ background: "green", border: "none", color: "#fff" }}
  571. disabled={!hasSelected}
  572. onClick={this.activation}>激活<Icon type="unlock" /></Button>
  573. <span>更多搜索<Switch defaultChecked={false} onChange={this.searchSwitch} /></span>
  574. <Button type="primary" className="addButton" onClick={this.addClick} >新增用户<Icon type="user" /></Button>
  575. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {}}>
  576. <Select placeholder="职务"
  577. style={{ width: 160 }}
  578. value={this.state.postSearch}
  579. onChange={(e) => { this.setState({ postSearch: e }) }}>
  580. {
  581. post.map(function (item) {
  582. return <Select.Option key={item.value} >{item.key}</Select.Option>
  583. })
  584. }
  585. </Select>
  586. <Select placeholder="岗位"
  587. style={{ width: 160 }}
  588. value={this.state.stationSearch}
  589. onChange={(e) => { this.setState({ stationSearch: e }) }}>
  590. {
  591. station.map(function (item) {
  592. return <Select.Option key={item.value} >{item.key}</Select.Option>
  593. })
  594. }
  595. </Select>
  596. <Select placeholder="状态"
  597. style={{ width: 160 }}
  598. value={this.state.statusSeach}
  599. onChange={(e) => { this.setState({ statusSeach: e }) }}>
  600. <Select.Option value="正常" >正常</Select.Option>
  601. <Select.Option value="锁定" >锁定</Select.Option>
  602. </Select>
  603. <Input placeholder="登录用户名" style={{width:'150px'}}
  604. value={this.state.signNameSearch}
  605. onChange={(e) => { this.setState({ signNameSearch: e.target.value }); }} />
  606. <AutoComplete
  607. className="certain-category-search"
  608. dropdownClassName="certain-category-search-dropdown"
  609. dropdownMatchSelectWidth={false}
  610. dropdownStyle={{ width: 200 }}
  611. size="large"
  612. style={{ width: '150px',height:'28px' ,marginLeft:'10px'}}
  613. dataSource={options}
  614. placeholder="输入上级主管名字"
  615. value={this.state.auto}
  616. onChange={this.httpChange}
  617. filterOption={true}
  618. onBlur={this.blurChange}
  619. onSelect={this.selectAuto}
  620. >
  621. <Input/>
  622. </AutoComplete>
  623. </div>
  624. </div>
  625. <div className="patent-table">
  626. <Spin spinning={this.state.loading}>
  627. <Table columns={this.state.columns}
  628. dataSource={this.state.dataSource}
  629. rowSelection={rowSelection}
  630. pagination={this.state.pagination}
  631. onRowClick={this.tableRowClick} />
  632. </Spin>
  633. </div>
  634. <Newuser
  635. role={this.state.role}
  636. addId={this.state.addId}
  637. roleArr={this.state.roleArr}
  638. departmentArr={this.state.departmentArr}
  639. userDetaile={this.state.userDetaile}
  640. datauser={this.state.datauser}
  641. showDesc={this.state.showDesc}
  642. closeDesc={this.closeDesc} />
  643. </div >
  644. </div>
  645. );
  646. }
  647. }));
  648. export default User;