newRole.jsx 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. import React from 'react';
  2. import { Icon, Table, Modal, message, Spin, Input, Select, Button, Form } from 'antd';
  3. import ajax from 'jquery/src/ajax/xhr.js';
  4. import $ from 'jquery/src/ajax';
  5. import './userMangagement.less';
  6. import {} from '../../../dataDic.js';
  7. const Newrole = Form.create()(React.createClass({
  8. addloadData() {
  9. this.setState({
  10. loading: true
  11. });
  12. $.ajax({
  13. method: "post",
  14. dataType: "json",
  15. crossDomain: false,
  16. url: globalConfig.context + '/api/admin/customer/listAllPersonalCustomer',
  17. data: {
  18. pageNo: 1,
  19. pageSize: 10,
  20. },
  21. success: function(data) {
  22. let theArr = [];
  23. if(!data.data || !data.data.list) {
  24. if(data.error && data.error.length) {
  25. message.warning(data.error[0].message);
  26. };
  27. } else {
  28. for(let i = 0; i < data.data.list.length; i++) {
  29. let thisdata = data.data.list[i];
  30. let nub = Math.floor(Math.random() * 100000);
  31. theArr.push({
  32. key: 'AM' + nub,
  33. id: 'nub' + i + 'b',
  34. name: '成果录入' + i,
  35. Interface: 'api/admin/customer' + i,
  36. children: [{
  37. key: 'BM' + nub,
  38. id: 'nub' + i + 'b' + i,
  39. name: '成果录入' + i + i,
  40. Interface: 'api/admin/customer' + i + i + i,
  41. },
  42. {
  43. key: 'BM' + nub + i,
  44. id: 'nub' + i + 'c' + i,
  45. name: '成果录入' + i + i,
  46. Interface: 'api/admin/customer' + i + i + i,
  47. }
  48. ]
  49. });
  50. };
  51. };
  52. this.setState({
  53. Interface: theArr,
  54. });
  55. }.bind(this),
  56. }).always(function() {
  57. this.setState({
  58. loading: false
  59. });
  60. }.bind(this));
  61. },
  62. getInitialState() {
  63. return {
  64. orgCodeUrl: [],
  65. loading: false,
  66. visible: false,
  67. addColumns: [{
  68. title: '选择角色权限',
  69. dataIndex: 'name',
  70. key: 'name',
  71. }, {
  72. title: '',
  73. dataIndex: 'Interface',
  74. key: 'Interface',
  75. }],
  76. };
  77. },
  78. handleSubmit(e) {
  79. e.preventDefault();
  80. //let api=this.props.userDetaile?'保存':'新建';
  81. this.props.form.validateFields((err, values) => {
  82. let idsArr = this.state.selectedRowst || [];
  83. let prekeys = this.state.selectedRowKeyst;
  84. let Interfaces = this.state.Interface;
  85. let ineIds = [];
  86. let ids = [];
  87. if(idsArr.length) {
  88. idsArr.map(function(index) {
  89. ids.push(
  90. index.id
  91. )
  92. if(idsArr.children) {
  93. idsArr.children.map(function(item) {
  94. ids.push(
  95. item.id
  96. )
  97. })
  98. }
  99. })
  100. } else {
  101. prekeys.map(function(item) {
  102. ineIds.push(Interfaces[item].id)
  103. });
  104. }
  105. if(!err) {
  106. this.setState({
  107. loading: true
  108. });
  109. $.ajax({
  110. method: "POST",
  111. dataType: "json",
  112. crossDomain: false,
  113. url: globalConfig.context + '/api/admin/customer/addCustomer',
  114. data: {
  115. roleName: this.state.roleName,
  116. id: ids.length ? JSON.stringify(ids) : JSON.stringify(ineIds)
  117. }
  118. }).done(function(data) {
  119. this.setState({
  120. loading: false
  121. });
  122. if(!data.error.length) {
  123. message.success('保存成功!');
  124. this.handleCancel()
  125. } else {
  126. message.warning(data.error[0].message);
  127. }
  128. }.bind(this));
  129. }
  130. });
  131. },
  132. //查看基本详情基本信息
  133. loaduser(record) {
  134. if(record) {
  135. $.ajax({
  136. method: "get",
  137. dataType: "json",
  138. crossDomain: false,
  139. url: globalConfig.context + '/api/admin/customer/toUpdateBusiness',
  140. data: {
  141. businessId: record.id
  142. },
  143. success: function(data) {
  144. let thisData = data.data;
  145. if(!thisData) {
  146. if(data.error && data.error.length) {
  147. message.warning(data.error[0].message);
  148. };
  149. thisData = {};
  150. };
  151. this.setState({
  152. detaileuser: thisData,
  153. uids: thisData.uid,
  154. //selectedRowKeyst:[0,1,2]
  155. });
  156. }.bind(this),
  157. }).always(function() {
  158. this.setState({
  159. loading: false
  160. });
  161. }.bind(this));
  162. }
  163. },
  164. handleOk(e) {
  165. this.setState({
  166. visible: false,
  167. });
  168. this.props.closeDesc(false, true);
  169. },
  170. handleCancel(e) {
  171. this.setState({
  172. visible: false,
  173. });
  174. this.props.closeDesc(false);
  175. },
  176. componentWillMount() {
  177. this.addloadData()
  178. },
  179. componentWillReceiveProps(nextProps) { //props改变时触发
  180. this.state.visible = nextProps.showDesc;
  181. if(nextProps.userDetaile && nextProps.showDesc) {
  182. if(nextProps.datauser && nextProps.datauser.id) {
  183. this.loaduser(nextProps.datauser);
  184. }
  185. }
  186. this.setState({
  187. selectedRowKeyst: [],
  188. datauser: {},
  189. })
  190. },
  191. render() {
  192. const theData = this.state.detaileuser || {};
  193. const FormItem = Form.Item
  194. const formItemLayout = {
  195. labelCol: { span: 8 },
  196. wrapperCol: { span: 14 },
  197. };
  198. const rowSelection = {
  199. selectedRowKeys: this.state.selectedRowKeyst,
  200. onChange: (selectedRowKeys, selectedRows) => {
  201. this.setState({
  202. selectedRowst: selectedRows,
  203. selectedRowKeyst: selectedRowKeys
  204. });
  205. },
  206. onSelect: (recordt, selected, selectedRows) => {
  207. this.setState({
  208. recordt:recordt.id
  209. })
  210. },
  211. };
  212. return(
  213. <div>
  214. <Modal maskClosable={false} visible={this.state.visible}
  215. onOk={this.handleOk} onCancel={this.handleCancel}
  216. width='1000px'
  217. title={!this.props.userDetaile?'添加角色':'编辑角色'}
  218. footer=''
  219. className="admin-desc-content">
  220. <Form layout="horizontal" onSubmit={this.handleSubmit} id="demand-form" style={{paddingBottom:'40px'}} required="required">
  221. <Spin spinning={this.state.loading}>
  222. <div className="clearfix">
  223. <div className="clearfix">
  224. <FormItem className="half-item"
  225. {...formItemLayout}
  226. label="角色名称" >
  227. <Input placeholder="角色名称" value={this.state.roleName} onChange={(e)=>{this.setState({roleName:e.target.value})}} style={{width:'200px'}} required="required"/>
  228. <span className="mandatory">*</span>
  229. </FormItem>
  230. <FormItem className="half-item"
  231. {...formItemLayout}
  232. label="" >
  233. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  234. <Button className="set-submit" type="ghost" onClick={this.handleCancel}>返回</Button>
  235. </FormItem>
  236. </div>
  237. <div className="clearfix">
  238. <Table columns={this.state.addColumns}
  239. dataSource={this.state.Interface}
  240. rowSelection={rowSelection}
  241. scroll={{ y: 500 }}
  242. pagination={false}
  243. />
  244. </div>
  245. </div>
  246. </Spin>
  247. </Form >
  248. </Modal>
  249. </div>
  250. )
  251. }
  252. }));
  253. export default Newrole;