addjurisdiction.jsx 11 KB

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