member.jsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. import React from 'react';
  2. import { Table, Button, Spin, message, Icon, Select, Input } from 'antd';
  3. import { provinceSelect, provinceList, getProvince } from '../../../NewDicProvinceList.js';
  4. import { companySearch } from '../../../tools';
  5. import ajax from 'jquery/src/ajax/xhr.js';
  6. import $ from 'jquery/src/ajax';
  7. import TheModal from './modal.jsx';
  8. const Member = React.createClass({
  9. loadData(pageNo) {
  10. this.setState({
  11. loading: true
  12. });
  13. $.ajax({
  14. type: 'get',
  15. cache: false,
  16. url: globalConfig.context + "/api/admin/supervise/adminList",
  17. dataType: "json",
  18. data: {
  19. pageNo: pageNo || 1,
  20. pageSize: this.state.pagination.pageSize,
  21. province: this.state.searchProvince,
  22. mobile: this.state.searchMobile,
  23. name: this.state.searchName,
  24. department:this.state.departmentt
  25. },
  26. success: function (data) {
  27. let theArr = [];
  28. if (!data.data) {
  29. if (data.error && data.error.length) {
  30. message.warning(data.error[0].message);
  31. };
  32. } else {
  33. for (let i = 0; i < data.data.list.length; i++) {
  34. let thisdata = data.data.list[i];
  35. this.state.onlyProvince = thisdata.province;
  36. theArr.push({
  37. key: i,
  38. id: thisdata.id,
  39. mobile: thisdata.mobile,
  40. name: thisdata.name,
  41. email: thisdata.email,
  42. createTime: thisdata.createTime,
  43. number: thisdata.number,
  44. province: thisdata.province,
  45. city:thisdata.city,
  46. position: thisdata.position,
  47. departmentName:thisdata.departmentName,
  48. departmentId:thisdata.departmentId,
  49. superior: thisdata.superior,
  50. superiorId: thisdata.superiorId,
  51. createTimeFormattedDate: thisdata.createTimeFormattedDate
  52. });
  53. };
  54. this.state.pagination.current = data.data.pageNo;
  55. this.state.pagination.total = data.data.totalCount;
  56. };
  57. this.setState({
  58. data: theArr,
  59. pagination: this.state.pagination
  60. });
  61. }.bind(this),
  62. }).always(function () {
  63. this.setState({
  64. loading: false
  65. });
  66. }.bind(this));
  67. },
  68. loadInitialData() {
  69. this.setState({
  70. loading: true
  71. });
  72. $.ajax({
  73. url: globalConfig.context + '/api/roles',
  74. cache: false
  75. }).done((rolesres) => {
  76. let theAdminRole = [], rolesObj = {};
  77. if (rolesres.data && window.adminData) {
  78. rolesres.data.map((item) => {
  79. theAdminRole.push(item.id);
  80. rolesObj[item.id] = item.roleName;
  81. })
  82. }
  83. this.setState({
  84. roles: rolesres.data,
  85. theAdminRole: theAdminRole,
  86. rolesObj:rolesObj,
  87. loading: false
  88. });
  89. })
  90. },
  91. loadBindRoles(uid) {
  92. this.setState({
  93. loading: true
  94. });
  95. $.ajax({
  96. url: globalConfig.context + '/api/admin/role',
  97. cache: false,
  98. data: {
  99. "uid": window.adminData.uid
  100. }
  101. }).done((data) => {
  102. this.setState({
  103. currentRoles: data.data || [],
  104. loading: false
  105. });
  106. })
  107. },
  108. getInitialState() {
  109. return {
  110. data: [],
  111. roles: [],
  112. currentRoles:[],
  113. rolesObj: {},
  114. theAdminRole: [],
  115. provinceList: [],
  116. dataSource: [],
  117. selectedRowKeys: [],
  118. selectedRows: [],
  119. departmentArr:[],
  120. loading: false,
  121. modalData: {},
  122. modalShow: false,
  123. pagination: {
  124. defaultCurrent: 1,
  125. defaultPageSize: 10,
  126. showQuickJumper: true,
  127. pageSize: 10,
  128. onChange: function (page) {
  129. this.loadData(page);
  130. }.bind(this),
  131. showTotal: function (total) {
  132. return '共' + total + '条数据';
  133. }
  134. },
  135. columns: [
  136. {
  137. title: '编号',
  138. dataIndex: 'number',
  139. key: 'number'
  140. }, {
  141. title: '登录账号',
  142. dataIndex: 'mobile',
  143. key: 'mobile'
  144. }, {
  145. title: '名字',
  146. dataIndex: 'name',
  147. key: 'name'
  148. }, {
  149. title: '职位',
  150. dataIndex: 'position',
  151. key: 'position'
  152. },{
  153. title: '部门',
  154. dataIndex: 'departmentName',
  155. key: 'departmentName'
  156. }, {
  157. title: '上级管理员',
  158. dataIndex: 'superior',
  159. key: 'superior'
  160. }, {
  161. title: '省份',
  162. dataIndex: 'province',
  163. key: 'province',
  164. render: text => {
  165. return text ? text.split(',').map((item) => {
  166. return getProvince(item) + ' '
  167. }) : []
  168. }
  169. }, {
  170. title: '邮箱',
  171. dataIndex: 'email',
  172. key: 'email'
  173. }, {
  174. title: '创建时间',
  175. dataIndex: 'createTimeFormattedDate',
  176. key: 'createTimeFormattedDate'
  177. }
  178. ]
  179. }
  180. },
  181. //部门
  182. departmentList() {
  183. this.setState({
  184. loading: true
  185. });
  186. $.ajax({
  187. method: "get",
  188. dataType: "json",
  189. crossDomain: false,
  190. url: globalConfig.context + "/api/admin/organization/selectSuperId",
  191. data: {
  192. },
  193. success: function(data) {
  194. let thedata = data.data;
  195. let theArr=[];
  196. if(!thedata) {
  197. if(data.error && data.error.length) {
  198. message.warning(data.error[0].message);
  199. };
  200. thedata = {};
  201. }else{
  202. thedata.map(function(item,index){
  203. theArr.push({
  204. key:index,
  205. name:item.name,
  206. id:item.id,
  207. depNo:item.depNo
  208. })
  209. })
  210. }
  211. this.setState({
  212. departmentArr:theArr,
  213. })
  214. }.bind(this),
  215. }).always(function() {
  216. this.setState({
  217. loading: false
  218. });
  219. }.bind(this));
  220. },
  221. componentWillMount() {
  222. this.state.provinceList = provinceSelect();
  223. this.loadData();
  224. this.departmentList()
  225. this.loadInitialData();
  226. this.loadBindRoles();
  227. },
  228. addNew() {
  229. let e = {}
  230. this.setState({
  231. modalData: e,
  232. modalShow: true
  233. })
  234. },
  235. edit(e) {
  236. this.setState({
  237. modalData: e,
  238. modalShow: true
  239. })
  240. },
  241. reset() {
  242. this.state.departmentt=undefined;
  243. this.state.searchMobile = undefined;
  244. this.state.searchName = undefined;
  245. this.state.searchProvince = undefined;
  246. this.loadData();
  247. },
  248. handleReturn(show, render) {
  249. this.state.modalShow = show;
  250. if (render) {
  251. this.loadData();
  252. }
  253. },
  254. render() {
  255. let departmentArr = this.state.departmentArr || [];
  256. return (
  257. <Spin spinning={this.state.loading}>
  258. <div className="set-content">
  259. <div className="set-title">
  260. <span>管理员设置</span>
  261. <Button style={{ background: "#ea0862", border: "none", color: "#fff" }}
  262. onClick={this.addNew}>添加<Icon type="plus" /></Button>
  263. </div>
  264. <div className="set-search">
  265. <Input placeholder="登录号"
  266. value={this.state.searchMobile}
  267. onChange={(e) => { this.setState({ searchMobile: e.target.value }); }} />
  268. <Input placeholder="管理员名字"
  269. value={this.state.searchName}
  270. onChange={(e) => { this.setState({ searchName: e.target.value }); }} />
  271. <Select placeholder="选择部门" style={{width:'120px'}}
  272. value={this.state.departmentt}
  273. onChange={(e) => { this.setState({ departmentt: e }) }}>
  274. {
  275. departmentArr.map(function (item) {
  276. return <Select.Option key={item.id} >{item.name}</Select.Option>
  277. })
  278. }
  279. </Select>
  280. <Select style={{ width: 120 }}
  281. placeholder="选择一个省份"
  282. showSearch
  283. filterOption={companySearch}
  284. value={this.state.searchProvince}
  285. onChange={(e) => { this.setState({ searchProvince: e }) }} >
  286. {this.state.provinceList.map((item) => {
  287. return <Select.Option key={String(item.value)}>{item.label}</Select.Option>
  288. })}
  289. </Select>
  290. <Button type="primary" onClick={() => { this.loadData() }}>搜索</Button>
  291. <Button onClick={this.reset}>重置</Button>
  292. </div>
  293. <TheModal
  294. theAdminRole={this.state.theAdminRole}
  295. currentRoles={this.state.currentRoles}
  296. roles={this.state.roles}
  297. rolesObj={this.state.rolesObj}
  298. data={this.state.modalData}
  299. onlyProvince={this.state.onlyProvince}
  300. show={this.state.modalShow}
  301. departmentArr={this.state.departmentArr}
  302. handleReturn={this.handleReturn} />
  303. <Table size="middle" className='member-table'
  304. columns={this.state.columns}
  305. style={{
  306. cursor: 'pointer',
  307. }}
  308. onRowClick={this.edit}
  309. dataSource={this.state.data}
  310. pagination={this.state.pagination} />
  311. </div>
  312. </Spin>
  313. );
  314. }
  315. });
  316. export default Member;