addjurisdiction.jsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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. //秒、分处理
  152. if(createS<10){
  153. createS='0'+Times.getSeconds()
  154. }else{
  155. createS=Times.getSeconds();
  156. };
  157. if(createF<10){
  158. createF='0'+Times.getMinutes()
  159. }else{
  160. createF=Times.getMinutes();
  161. };
  162. let createTimes=createY+'-'+createM+'-'+createD+' '+createH+':'+createF+':'+createS;
  163. //更新时间
  164. let updateY=upTimes.getFullYear();
  165. let updateH=upTimes.getHours();
  166. let updateF=upTimes.getMinutes();
  167. let updateS=upTimes.getSeconds();
  168. let updateM,updateD;
  169. if(updateM<10){
  170. updateM='0'+upTimes.getMonth()
  171. }else{
  172. updateM=upTimes.getMonth();
  173. };
  174. if(updateD<10){
  175. updateD='0'+upTimes.getDate()
  176. }else{
  177. updateD=upTimes.getDate();
  178. };
  179. //m秒。分处理
  180. if(updateS<10){
  181. updateS='0'+upTimes.getSeconds()
  182. }else{
  183. updateS=upTimes.getSeconds();
  184. };
  185. if(updateF<10){
  186. updateF='0'+upTimes.getMinutes()
  187. }else{
  188. updateF=upTimes.getMinutes();
  189. };
  190. let updateTimes=updateY+'-'+updateM+'-'+updateD+' '+updateH+':'+updateF+':'+updateS;
  191. this.setState({
  192. ids:thisData.id,
  193. name:thisData.name, //接口名称
  194. url:thisData.url,//接口路径
  195. preModule:thisData.preModule,//接口上级模板功能
  196. createId:thisData.createId,
  197. createTime:createTimes,
  198. updateTime:updateTimes,
  199. autNo:thisData.autNo,
  200. auto:thisData.superId,
  201. });
  202. }.bind(this),
  203. }).always(function () {
  204. this.setState({
  205. loading: false
  206. });
  207. }.bind(this));
  208. }
  209. },
  210. handleOk(e) {
  211. this.setState({
  212. visible: false,
  213. });
  214. this.props.closeDesc(false, true);
  215. },
  216. handleCancel(e) {
  217. this.setState({
  218. visible: false,
  219. });
  220. this.props.closeDesc(false);
  221. },
  222. componentWillReceiveProps(nextProps) {
  223. this.state.visible = nextProps.showDesc;
  224. this.state.Detaile=nextProps.userDetaile;
  225. if(!nextProps.userDetaile){
  226. this.state.name='';
  227. this.state.url='';
  228. }else{
  229. this.loaduser(nextProps.datauser)
  230. }
  231. },
  232. render() {
  233. const theData = this.state.datauser||{};
  234. const { getFieldDecorator } = this.props.form;
  235. const FormItem = Form.Item
  236. const formItemLayout = {
  237. labelCol: { span: 8 },
  238. wrapperCol: { span: 14 },
  239. };
  240. const dataSources=this.state.customerArr || [];
  241. const options = dataSources.map((group,index) =>
  242. <Option key={index} value={group.name}>{group.name}</Option>
  243. )
  244. return (
  245. <div>
  246. <Modal maskClosable={false} visible={this.state.visible}
  247. onOk={this.handleOk} onCancel={this.handleCancel}
  248. width='600px'
  249. title={this.props.userDetaile?'权限详情':'新建权限'}
  250. footer=''
  251. className="admin-desc-content">
  252. <Form layout="horizontal" onSubmit={this.handleSubmit} id="demand-form">
  253. <Spin spinning={this.state.loading}>
  254. <div className="clearfix">
  255. <FormItem className="half-middle"
  256. {...formItemLayout}
  257. label="接口名称" >
  258. <Input placeholder="接口名称" value={this.state.name} style={{width:'230px'}}
  259. onChange={(e)=>{this.setState({name:e.target.value})}} required="required"/>
  260. <span className="mandatory">*</span>
  261. </FormItem>
  262. <FormItem className="half-middle"
  263. {...formItemLayout}
  264. label="接口路径" >
  265. <Input placeholder="接口路径" value={this.state.url} style={{width:'230px'}}
  266. onChange={(e)=>{this.setState({url:e.target.value})}} required="required"/>
  267. <span className="mandatory">*</span>
  268. </FormItem>
  269. </div>
  270. <div className="clearfix" style={{display:this.props.userDetaile?'block':'none'}}>
  271. <FormItem className="half-middle"
  272. {...formItemLayout}
  273. label="上级功能模块" >
  274. <AutoComplete
  275. className="certain-category-search"
  276. dropdownClassName="certain-category-search-dropdown"
  277. dropdownMatchSelectWidth={false}
  278. dropdownStyle={{ width: 230 }}
  279. size="large"
  280. style={{ width: '230px' }}
  281. dataSource={options}
  282. placeholder="输入名称"
  283. value={this.state.auto}
  284. onChange={this.httpChange}
  285. filterOption={true}
  286. onBlur={this.blurChange}
  287. onSelect={this.selectAuto}
  288. >
  289. <Input/>
  290. </AutoComplete>
  291. <span className="mandatory">*</span>
  292. </FormItem>
  293. <FormItem className="half-middle"
  294. {...formItemLayout}
  295. label="权限编号" >
  296. <span>{this.state.autNo}</span>
  297. </FormItem>
  298. <FormItem className="half-middle"
  299. {...formItemLayout}
  300. label="创建人" >
  301. <span>{this.state.createId}</span>
  302. </FormItem>
  303. <FormItem className="half-middle"
  304. {...formItemLayout}
  305. label="创建时间" >
  306. <span>{this.state.createTime}</span>
  307. </FormItem>
  308. <FormItem className="half-middle"
  309. {...formItemLayout}
  310. label="更新时间" >
  311. <span>{this.state.updateTime}</span>
  312. </FormItem>
  313. </div>
  314. <FormItem wrapperCol={{ span: 12, offset: 4 }} className="half-middle">
  315. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  316. <Button className="set-submit" type="ghost" onClick={this.handleCancel}>取消</Button>
  317. </FormItem>
  318. </Spin>
  319. </Form >
  320. </Modal>
  321. </div>
  322. )
  323. }
  324. }));
  325. export default Addjurisdiction;