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