addjurisdiction.jsx 12 KB

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