addjurisdiction.jsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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=true
  97. }else{
  98. theType=false
  99. }
  100. });
  101. }
  102. this.setState({
  103. theTypes:theType
  104. })
  105. },
  106. //值改变时请求客户名称
  107. httpChange(e){
  108. if(e.length>=1){
  109. this.supervisor(e);
  110. }
  111. this.setState({
  112. auto:e
  113. })
  114. },
  115. //查看基本详情基本信息
  116. loaduser(record){
  117. if(record){
  118. $.ajax({
  119. method: "post",
  120. dataType: "json",
  121. crossDomain: false,
  122. url: globalConfig.context + '/api/admin/selectAllById',
  123. data: {
  124. id: record.id
  125. },
  126. success: function (data) {
  127. let thisData = data.data;
  128. if (!thisData) {
  129. if (data.error && data.error.length) {
  130. message.warning(data.error[0].message);
  131. };
  132. thisData = {};
  133. };
  134. let Times = new Date(thisData.createTime);
  135. let upTimes = new Date(thisData.updateTime);
  136. let createY=Times.getFullYear();
  137. let createH=Times.getHours();
  138. let createF=Times.getMinutes();
  139. let createS=Times.getSeconds();
  140. let createM,createD;
  141. if(createM<10){
  142. createM='0'+Times.getMonth()
  143. }else{
  144. createM=Times.getMonth();
  145. };
  146. if(createD<10){
  147. createD='0'+Times.getDate()
  148. }else{
  149. createD=Times.getDate();
  150. };
  151. let createTimes=createY+'-'+createM+'-'+createD+' '+createH+':'+createF+':'+createS;
  152. //更新时间
  153. let updateY=upTimes.getFullYear();
  154. let updateH=upTimes.getHours();
  155. let updateF=upTimes.getMinutes();
  156. let updateS=upTimes.getSeconds();
  157. let updateM,updateD;
  158. if(updateM<10){
  159. updateM='0'+upTimes.getMonth()
  160. }else{
  161. updateM=upTimes.getMonth();
  162. };
  163. if(updateD<10){
  164. updateD='0'+upTimes.getDate()
  165. }else{
  166. updateD=upTimes.getDate();
  167. };
  168. let updateTimes=updateY+'-'+updateM+'-'+updateD+' '+updateH+':'+updateF+':'+updateS;
  169. this.setState({
  170. ids:thisData.id,
  171. name:thisData.name, //接口名称
  172. url:thisData.url,//接口路径
  173. preModule:thisData.preModule,//接口上级模板功能
  174. createId:thisData.createId,
  175. createTime:createTimes,
  176. updateTime:updateTimes,
  177. autNo:thisData.autNo,
  178. auto:thisData.superId,
  179. });
  180. }.bind(this),
  181. }).always(function () {
  182. this.setState({
  183. loading: false
  184. });
  185. }.bind(this));
  186. }
  187. },
  188. handleOk(e) {
  189. this.setState({
  190. visible: false,
  191. });
  192. this.props.closeDesc(false, true);
  193. },
  194. handleCancel(e) {
  195. this.setState({
  196. visible: false,
  197. });
  198. this.props.closeDesc(false);
  199. },
  200. componentWillReceiveProps(nextProps) {
  201. this.state.visible = nextProps.showDesc;
  202. this.state.Detaile=nextProps.userDetaile;
  203. if(!nextProps.userDetaile){
  204. this.state.name='';
  205. this.state.url='';
  206. }else{
  207. this.loaduser(nextProps.datauser)
  208. }
  209. },
  210. render() {
  211. const theData = this.state.datauser||{};
  212. const { getFieldDecorator } = this.props.form;
  213. const FormItem = Form.Item
  214. const formItemLayout = {
  215. labelCol: { span: 8 },
  216. wrapperCol: { span: 14 },
  217. };
  218. const dataSources=this.state.customerArr || [];
  219. const options = dataSources.map((group,index) =>
  220. <Option key={index} value={group.name}>{group.name}</Option>
  221. )
  222. return (
  223. <div>
  224. <Modal maskClosable={false} visible={this.state.visible}
  225. onOk={this.handleOk} onCancel={this.handleCancel}
  226. width='600px'
  227. title={this.props.userDetaile?'权限详情':'新建权限'}
  228. footer=''
  229. className="admin-desc-content">
  230. <Form layout="horizontal" onSubmit={this.handleSubmit} id="demand-form">
  231. <Spin spinning={this.state.loading}>
  232. <div className="clearfix">
  233. <FormItem className="half-middle"
  234. {...formItemLayout}
  235. label="接口名称" >
  236. <Input placeholder="接口名称" value={this.state.name} style={{width:'230px'}}
  237. onChange={(e)=>{this.setState({name:e.target.value})}} required="required"/>
  238. <span className="mandatory">*</span>
  239. </FormItem>
  240. <FormItem className="half-middle"
  241. {...formItemLayout}
  242. label="接口路径" >
  243. <Input placeholder="接口路径" value={this.state.url} style={{width:'230px'}}
  244. onChange={(e)=>{this.setState({url:e.target.value})}} required="required"/>
  245. <span className="mandatory">*</span>
  246. </FormItem>
  247. </div>
  248. <div className="clearfix" style={{display:this.props.userDetaile?'block':'none'}}>
  249. <FormItem className="half-middle"
  250. {...formItemLayout}
  251. label="上级功能模块" >
  252. <AutoComplete
  253. className="certain-category-search"
  254. dropdownClassName="certain-category-search-dropdown"
  255. dropdownMatchSelectWidth={false}
  256. dropdownStyle={{ width: 230 }}
  257. size="large"
  258. style={{ width: '230px' }}
  259. dataSource={options}
  260. placeholder="输入名称"
  261. value={this.state.auto}
  262. onChange={this.httpChange}
  263. filterOption={true}
  264. onBlur={this.blurChange}
  265. onSelect={this.selectAuto}
  266. >
  267. <Input/>
  268. </AutoComplete>
  269. <span className="mandatory">*</span>
  270. </FormItem>
  271. <FormItem className="half-middle"
  272. {...formItemLayout}
  273. label="权限编号" >
  274. <span>{this.state.autNo}</span>
  275. </FormItem>
  276. <FormItem className="half-middle"
  277. {...formItemLayout}
  278. label="创建人" >
  279. <span>{this.state.createId}</span>
  280. </FormItem>
  281. <FormItem className="half-middle"
  282. {...formItemLayout}
  283. label="创建时间" >
  284. <span>{this.state.createTime}</span>
  285. </FormItem>
  286. <FormItem className="half-middle"
  287. {...formItemLayout}
  288. label="更新时间" >
  289. <span>{this.state.updateTime}</span>
  290. </FormItem>
  291. </div>
  292. <FormItem wrapperCol={{ span: 12, offset: 4 }} className="half-middle">
  293. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  294. <Button className="set-submit" type="ghost" onClick={this.handleCancel}>取消</Button>
  295. </FormItem>
  296. </Spin>
  297. </Form >
  298. </Modal>
  299. </div>
  300. )
  301. }
  302. }));
  303. export default Addjurisdiction;