user.jsx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  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. console.log(rolesId)
  307. this.setState({
  308. selectedRowKeys: [],
  309. loading: true
  310. });
  311. $.ajax({
  312. method: "POST",
  313. dataType: "json",
  314. crossDomain: false,
  315. url: globalConfig.context + "/api/admin/superviser/updateAdmin",
  316. data: {
  317. roles:rolesId,
  318. data:JSON.stringify({
  319. id: deletedIds,
  320. status: '锁定',
  321. name: names,
  322. mobile: mobiles,
  323. }),
  324. }
  325. }).done(function(data) {
  326. if(!data.error.length) {
  327. message.success('锁定成功!');
  328. this.setState({
  329. loading: false,
  330. });
  331. } else {
  332. message.warning(data.error[0].message);
  333. };
  334. this.loadData();
  335. }.bind(this));
  336. },
  337. //激活
  338. activation() {
  339. let deletedIds;
  340. let statust;
  341. let mobiles;
  342. let names;
  343. let rolesId=[]
  344. for(let idx = 0; idx < this.state.selectedRows.length; idx++) {
  345. let rowItem = this.state.selectedRows[idx];
  346. if(rowItem.id) {
  347. deletedIds=rowItem.id;
  348. statust=rowItem.status;
  349. names=rowItem.name;
  350. mobiles=rowItem.mobile;
  351. rolesId=rowItem.rolesId
  352. };
  353. };
  354. this.setState({
  355. selectedRowKeys: [],
  356. loading: true
  357. });
  358. $.ajax({
  359. method: "POST",
  360. dataType: "json",
  361. crossDomain: false,
  362. url: globalConfig.context + "/api/admin/superviser/updateAdmin",
  363. data: {
  364. roles:rolesId,
  365. data:JSON.stringify({
  366. id: deletedIds,
  367. status: '正常',
  368. name: names,
  369. mobile: mobiles,
  370. })
  371. }
  372. }).done(function(data) {
  373. if(!data.error.length) {
  374. message.success('激活成功!');
  375. this.setState({
  376. loading: false,
  377. });
  378. } else {
  379. message.warning(data.error[0].message);
  380. };
  381. this.loadData();
  382. }.bind(this));
  383. },
  384. //删除
  385. delectRow() {
  386. let deletedIds;
  387. for(let idx = 0; idx < this.state.selectedRows.length; idx++) {
  388. let rowItem = this.state.selectedRows[idx];
  389. if(rowItem.id) {
  390. deletedIds=rowItem.id;
  391. };
  392. };
  393. this.setState({
  394. selectedRowKeys: [],
  395. loading: true
  396. });
  397. $.ajax({
  398. method: "POST",
  399. dataType: "json",
  400. crossDomain: false,
  401. url: globalConfig.context + "/api/admin/superviser/deleteById",
  402. data: {
  403. id: deletedIds,
  404. }
  405. }).done(function(data) {
  406. if(!data.error.length) {
  407. message.success('删除成功!');
  408. this.setState({
  409. loading: false,
  410. });
  411. } else {
  412. message.warning(data.error[0].message);
  413. };
  414. this.loadData();
  415. }.bind(this));
  416. },
  417. addClick() {
  418. this.addIdS()
  419. this.state.userDetaile = false;
  420. this.setState({
  421. showDesc: true
  422. });
  423. },
  424. closeDesc(e, s) {
  425. this.state.showDesc = e;
  426. if(s) {
  427. this.loadData();
  428. };
  429. },
  430. search() {
  431. this.state.userDetaile = false
  432. this.loadData();
  433. },
  434. reset() {
  435. this.state.userNameSearch = '';
  436. this.state.organizationSearch = undefined;
  437. this.state.rolesSearch = undefined;
  438. this.state.postSearch = undefined;
  439. this.state.stationSearch = undefined;
  440. this.state.statusSeach = undefined;
  441. this.state.signNameSearch = '';
  442. this.state.mobileSearch = '';
  443. this.state.auto = '';
  444. this.state.theTypes='';
  445. this.loadData();
  446. },
  447. searchSwitch() {
  448. this.setState({
  449. searchMore: !this.state.searchMore
  450. });
  451. },
  452. //主管初始加载(自动补全)
  453. supervisor(e) {
  454. $.ajax({
  455. method: "post",
  456. dataType: "json",
  457. crossDomain: false,
  458. url: globalConfig.context + "/api/admin/organization/selectName",
  459. data: {
  460. name: e
  461. },
  462. success: function(data) {
  463. let thedata = data.data;
  464. if(!thedata) {
  465. if(data.error && data.error.length) {
  466. message.warning(data.error[0].message);
  467. };
  468. thedata = {};
  469. };
  470. this.setState({
  471. customerArr: thedata,
  472. });
  473. }.bind(this),
  474. }).always(function() {
  475. this.setState({
  476. loading: false
  477. });
  478. }.bind(this));
  479. },
  480. //上级主管输入框失去焦点是判断客户是否存在
  481. selectAuto(value, options) {
  482. this.setState({
  483. auto: value
  484. })
  485. },
  486. blurChange(e) {
  487. let theType = '';
  488. let contactLists = this.state.customerArr || [];
  489. if(e) {
  490. contactLists.map(function(item) {
  491. if(item.name == e.toString()) {
  492. theType = item.id;
  493. }
  494. });
  495. }
  496. this.setState({
  497. theTypes: theType
  498. })
  499. },
  500. //值改变时请求客户名称
  501. httpChange(e) {
  502. if(e.length >= 1) {
  503. this.supervisor(e);
  504. }
  505. this.setState({
  506. auto: e
  507. })
  508. },
  509. render() {
  510. const rowSelection = {
  511. selectedRowKeys: this.state.selectedRowKeys,
  512. onChange: (selectedRowKeys, selectedRows) => {
  513. this.setState({
  514. selectedRows: selectedRows.slice(-1),
  515. selectedRowKeys: selectedRowKeys.slice(-1)
  516. });
  517. },
  518. onSelectAll: (selected, selectedRows, changeRows) => {
  519. this.setState({
  520. selectedRowKeys: []
  521. })
  522. },
  523. };
  524. const dataSources = this.state.customerArr || [];
  525. const options = dataSources.map((group, index) =>
  526. <Select.Option key={index} value={group.name}>{group.name}</Select.Option>
  527. )
  528. const hasSelected = this.state.selectedRowKeys.length > 0;
  529. const { RangePicker } = DatePicker;
  530. let departmentArr = this.state.departmentArr || [];
  531. let roleArr = this.state.roleArr || [];
  532. return(
  533. <div className="user-content" >
  534. <div className="content-title">
  535. <div className="user-search">
  536. <Input placeholder="用户姓名" style={{width:'150px'}}
  537. value={this.state.userNameSearch}
  538. onChange={(e) => { this.setState({ userNameSearch: e.target.value }); }} />
  539. <Select placeholder="部门"
  540. style={{ width: 160 }}
  541. value={this.state.organizationSearch}
  542. onChange={(e) => { this.setState({ organizationSearch: e }) }}>
  543. {
  544. departmentArr.map(function (item) {
  545. return <Select.Option key={item.id} >{item.name}</Select.Option>
  546. })
  547. }
  548. </Select>
  549. <Select placeholder="角色"
  550. style={{ width: 160 }}
  551. value={this.state.rolesSearch}
  552. onChange={(e) => { this.setState({ rolesSearch: e }) }}>
  553. {
  554. roleArr.map(function (item) {
  555. return <Select.Option key={item.id} >{item.roleName}</Select.Option>
  556. })
  557. }
  558. </Select>
  559. <Button type="primary" onClick={this.search}>搜索</Button>
  560. <Button onClick={this.reset}>重置</Button>
  561. <Button style={{ background: "red", border: "none", color: "#fff" }}
  562. disabled={!hasSelected}
  563. onClick={this.delectRow}>删除<Icon type="minus" /></Button>
  564. <Button style={{ background: "#333333", border: "none", color: "#fff" }}
  565. disabled={!hasSelected}
  566. onClick={this.locking}>锁定<Icon type="lock" /></Button>
  567. <Button style={{ background: "green", border: "none", color: "#fff" }}
  568. disabled={!hasSelected}
  569. onClick={this.activation}>激活<Icon type="unlock" /></Button>
  570. <span>更多搜索<Switch defaultChecked={false} onChange={this.searchSwitch} /></span>
  571. <Button type="primary" className="addButton" onClick={this.addClick} >新增用户<Icon type="user" /></Button>
  572. <div className="search-more" style={this.state.searchMore ? { display: 'none' } : {}}>
  573. <Select placeholder="职务"
  574. style={{ width: 160 }}
  575. value={this.state.postSearch}
  576. onChange={(e) => { this.setState({ postSearch: e }) }}>
  577. {
  578. post.map(function (item) {
  579. return <Select.Option key={item.value} >{item.key}</Select.Option>
  580. })
  581. }
  582. </Select>
  583. <Select placeholder="岗位"
  584. style={{ width: 160 }}
  585. value={this.state.stationSearch}
  586. onChange={(e) => { this.setState({ stationSearch: e }) }}>
  587. {
  588. station.map(function (item) {
  589. return <Select.Option key={item.value} >{item.key}</Select.Option>
  590. })
  591. }
  592. </Select>
  593. <Select placeholder="状态"
  594. style={{ width: 160 }}
  595. value={this.state.statusSeach}
  596. onChange={(e) => { this.setState({ statusSeach: e }) }}>
  597. <Select.Option value="正常" >正常</Select.Option>
  598. <Select.Option value="锁定" >锁定</Select.Option>
  599. </Select>
  600. <Input placeholder="登录用户名" style={{width:'150px'}}
  601. value={this.state.signNameSearch}
  602. onChange={(e) => { this.setState({ signNameSearch: e.target.value }); }} />
  603. <AutoComplete
  604. className="certain-category-search"
  605. dropdownClassName="certain-category-search-dropdown"
  606. dropdownMatchSelectWidth={false}
  607. dropdownStyle={{ width: 200 }}
  608. size="large"
  609. style={{ width: '150px',height:'28px' ,marginLeft:'10px'}}
  610. dataSource={options}
  611. placeholder="输入上级主管名字"
  612. value={this.state.auto}
  613. onChange={this.httpChange}
  614. filterOption={true}
  615. onBlur={this.blurChange}
  616. onSelect={this.selectAuto}
  617. >
  618. <Input/>
  619. </AutoComplete>
  620. </div>
  621. </div>
  622. <div className="patent-table">
  623. <Spin spinning={this.state.loading}>
  624. <Table columns={this.state.columns}
  625. dataSource={this.state.dataSource}
  626. rowSelection={rowSelection}
  627. pagination={this.state.pagination}
  628. onRowClick={this.tableRowClick} />
  629. </Spin>
  630. </div>
  631. <Newuser
  632. role={this.state.role}
  633. addId={this.state.addId}
  634. roleArr={this.state.roleArr}
  635. departmentArr={this.state.departmentArr}
  636. userDetaile={this.state.userDetaile}
  637. datauser={this.state.datauser}
  638. showDesc={this.state.showDesc}
  639. closeDesc={this.closeDesc} />
  640. </div >
  641. </div>
  642. );
  643. }
  644. }));
  645. export default User;