user.jsx 18 KB

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