addjurisdiction.jsx 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. import React from 'react';
  2. import { Icon, Modal, message, AutoComplete,Spin, Input, Select, Button, Form,Upload } 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 Option = AutoComplete.Option;
  8. const Addjurisdiction = Form.create()(React.createClass({
  9. getInitialState() {
  10. return {
  11. loading: false,
  12. visible:false
  13. };
  14. },
  15. //保存
  16. handleSubmit(e) {
  17. e.preventDefault();
  18. let theType;
  19. if(this.props.userDetaile){
  20. if (!this.state.auto) {
  21. message.warning('请输入上级模块')
  22. return false;
  23. }
  24. }
  25. let api=this.props.userDetaile?'/api/admin/updateById':'/api/admin/addSupPermission';
  26. this.props.form.validateFields((err, values) => {
  27. if (!err) {
  28. this.setState({
  29. loading: true
  30. });
  31. $.ajax({
  32. method: "POST",
  33. dataType: "json",
  34. crossDomain: false,
  35. url: globalConfig.context + api,
  36. data: {
  37. id:this.state.ids,
  38. name:this.state.name, //接口名称
  39. url:this.state.url,//接口路径
  40. superId:this.state.auto,//接口上级模板功能
  41. }
  42. }).done(function (data) {
  43. this.setState({
  44. loading: false
  45. });
  46. if (!data.error.length) {
  47. message.success('保存成功!');
  48. this.props.closeDesc(false,true);
  49. } else {
  50. message.warning(data.error[0].message);
  51. }
  52. }.bind(this));
  53. }
  54. });
  55. },
  56. //主管初始加载(自动补全)
  57. supervisor(e){
  58. $.ajax({
  59. method: "post",
  60. dataType: "json",
  61. crossDomain: false,
  62. url: globalConfig.context + "/api/admin/selectName",
  63. data:{
  64. name:e
  65. },
  66. success: function (data) {
  67. let thedata=data.data;
  68. if (!thedata) {
  69. if (data.error && data.error.length) {
  70. message.warning(data.error[0].message);
  71. };
  72. thedata = {};
  73. };
  74. this.setState({
  75. customerArr:thedata,
  76. });
  77. }.bind(this),
  78. }).always(function () {
  79. this.setState({
  80. loading: false
  81. });
  82. }.bind(this));
  83. },
  84. //上级主管输入框失去焦点是判断客户是否存在
  85. selectAuto(value,options){
  86. this.setState({
  87. auto:value
  88. })
  89. },
  90. blurChange(e){
  91. let theType;
  92. let contactLists=this.state.customerArr||[];
  93. if (e) {
  94. contactLists.map(function (item) {
  95. if (item.name == e.toString()) {
  96. theType=item.id
  97. }
  98. });
  99. }
  100. this.setState({
  101. theTypes:theType
  102. })
  103. },
  104. //值改变时请求客户名称
  105. httpChange(e){
  106. if(e.length>=1){
  107. this.supervisor(e);
  108. }
  109. this.setState({
  110. auto:e
  111. })
  112. },
  113. //查看基本详情基本信息
  114. loaduser(record){
  115. if(record){
  116. $.ajax({
  117. method: "post",
  118. dataType: "json",
  119. crossDomain: false,
  120. url: globalConfig.context + '/api/admin/selectAllById',
  121. data: {
  122. id: record.id
  123. },
  124. success: function (data) {
  125. let thisData = data.data;
  126. if (!thisData) {
  127. if (data.error && data.error.length) {
  128. message.warning(data.error[0].message);
  129. };
  130. thisData = {};
  131. };
  132. this.setState({
  133. ids:thisData.id,
  134. name:thisData.name, //接口名称
  135. url:thisData.url,//接口路径
  136. preModule:thisData.preModule,//接口上级模板功能
  137. createId:thisData.createId,
  138. createTime:(new Date(thisData.createTime)).toLocaleString(),
  139. updateTime:(new Date(thisData.updateTime)).toLocaleString(),
  140. autNo:thisData.autNo,
  141. auto:thisData.superId,
  142. });
  143. }.bind(this),
  144. }).always(function () {
  145. this.setState({
  146. loading: false
  147. });
  148. }.bind(this));
  149. }
  150. },
  151. handleOk(e) {
  152. this.setState({
  153. visible: false,
  154. });
  155. this.props.closeDesc(false, true);
  156. },
  157. handleCancel(e) {
  158. this.setState({
  159. visible: false,
  160. });
  161. this.props.closeDesc(false);
  162. },
  163. componentWillReceiveProps(nextProps) {
  164. this.state.visible = nextProps.showDesc;
  165. this.state.Detaile=nextProps.userDetaile;
  166. if(!nextProps.userDetaile){
  167. this.state.name='';
  168. this.state.url='';
  169. }else{
  170. this.loaduser(nextProps.datauser)
  171. }
  172. },
  173. render() {
  174. const theData = this.state.datauser||{};
  175. const { getFieldDecorator } = this.props.form;
  176. const FormItem = Form.Item
  177. const formItemLayout = {
  178. labelCol: { span: 8 },
  179. wrapperCol: { span: 14 },
  180. };
  181. const dataSources=this.state.customerArr || [];
  182. const options = dataSources.map((group,index) =>
  183. <Option key={index} value={group.name}>{group.name}</Option>
  184. )
  185. return (
  186. <div>
  187. <Modal maskClosable={false} visible={this.state.visible}
  188. onOk={this.handleOk} onCancel={this.handleCancel}
  189. width='600px'
  190. title={this.props.userDetaile?'权限详情':'新建权限'}
  191. footer=''
  192. className="admin-desc-content">
  193. <Form layout="horizontal" onSubmit={this.handleSubmit} id="demand-form">
  194. <Spin spinning={this.state.loading}>
  195. <div className="clearfix">
  196. <FormItem className="half-middle"
  197. {...formItemLayout}
  198. label="接口名称" >
  199. <Input placeholder="接口名称" value={this.state.name} style={{width:'230px'}}
  200. onChange={(e)=>{this.setState({name:e.target.value})}} required="required"/>
  201. <span className="mandatory">*</span>
  202. </FormItem>
  203. <FormItem className="half-middle"
  204. {...formItemLayout}
  205. label="接口路径" >
  206. <Input placeholder="接口路径" value={this.state.url} style={{width:'230px'}}
  207. onChange={(e)=>{this.setState({url:e.target.value})}} required="required"/>
  208. <span className="mandatory">*</span>
  209. </FormItem>
  210. </div>
  211. <div className="clearfix" style={{display:this.props.userDetaile?'block':'none'}}>
  212. <FormItem className="half-middle"
  213. {...formItemLayout}
  214. label="上级功能模块" >
  215. <AutoComplete
  216. className="certain-category-search"
  217. dropdownClassName="certain-category-search-dropdown"
  218. dropdownMatchSelectWidth={false}
  219. dropdownStyle={{ width: 230 }}
  220. size="large"
  221. style={{ width: '230px' }}
  222. dataSource={options}
  223. placeholder="输入名称"
  224. value={this.state.auto}
  225. onChange={this.httpChange}
  226. filterOption={true}
  227. onBlur={this.blurChange}
  228. onSelect={this.selectAuto}
  229. >
  230. <Input/>
  231. </AutoComplete>
  232. <span className="mandatory">*</span>
  233. </FormItem>
  234. <FormItem className="half-middle"
  235. {...formItemLayout}
  236. label="权限编号" >
  237. <span>{this.state.autNo}</span>
  238. </FormItem>
  239. <FormItem className="half-middle"
  240. {...formItemLayout}
  241. label="创建人" >
  242. <span>{this.state.createId}</span>
  243. </FormItem>
  244. <FormItem className="half-middle"
  245. {...formItemLayout}
  246. label="创建时间" >
  247. <span>{this.state.createTime}</span>
  248. </FormItem>
  249. <FormItem className="half-middle"
  250. {...formItemLayout}
  251. label="更新时间" >
  252. <span>{this.state.updateTime}</span>
  253. </FormItem>
  254. </div>
  255. <FormItem className="half-middle">
  256. <Button className="set-submit" type="primary" htmlType="submit" style={{marginLeft:'150px'}}>保存</Button>
  257. <Button className="set-submit" type="ghost" onClick={this.handleCancel}>取消</Button>
  258. </FormItem>
  259. </Spin>
  260. </Form >
  261. </Modal>
  262. </div>
  263. )
  264. }
  265. }));
  266. export default Addjurisdiction;