addjurisdiction.jsx 11 KB

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