user.jsx 18 KB

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