addjurisdiction.jsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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. showOrder: this.state.showOrder,
  43. },
  44. }).done(
  45. function (data) {
  46. this.setState({
  47. loading: false,
  48. });
  49. if (!data.error.length) {
  50. message.success("保存成功!");
  51. this.props.closeDesc(false, true);
  52. } else {
  53. message.warning(data.error[0].message);
  54. }
  55. }.bind(this)
  56. );
  57. }
  58. });
  59. },
  60. //主管初始加载(自动补全)
  61. supervisor(e){
  62. $.ajax({
  63. method: "post",
  64. dataType: "json",
  65. crossDomain: false,
  66. url: globalConfig.context + "/api/admin/selectName",
  67. data:{
  68. name:e
  69. },
  70. success: function (data) {
  71. let thedata=data.data;
  72. if (!thedata) {
  73. if (data.error && data.error.length) {
  74. message.warning(data.error[0].message);
  75. };
  76. thedata = {};
  77. };
  78. this.setState({
  79. customerArr:thedata,
  80. });
  81. }.bind(this),
  82. }).always(function () {
  83. this.setState({
  84. loading: false
  85. });
  86. }.bind(this));
  87. },
  88. //上级主管输入框失去焦点是判断客户是否存在
  89. selectAuto(value,options){
  90. this.setState({
  91. auto:value
  92. })
  93. },
  94. blurChange(e){
  95. let theType;
  96. let contactLists=this.state.customerArr||[];
  97. if (e) {
  98. contactLists.map(function (item) {
  99. if (item.name == e.toString()) {
  100. theType=item.id
  101. }
  102. });
  103. }
  104. this.setState({
  105. theTypes:theType
  106. })
  107. },
  108. //值改变时请求客户名称
  109. httpChange(e){
  110. if(e.length>=1){
  111. this.supervisor(e);
  112. }
  113. this.setState({
  114. auto:e
  115. })
  116. },
  117. //查看基本详情基本信息
  118. loaduser(record){
  119. if(record){
  120. $.ajax({
  121. method: "post",
  122. dataType: "json",
  123. crossDomain: false,
  124. url: globalConfig.context + '/api/admin/selectAllById',
  125. data: {
  126. id: record.id
  127. },
  128. success: function (data) {
  129. let thisData = data.data;
  130. if (!thisData) {
  131. if (data.error && data.error.length) {
  132. message.warning(data.error[0].message);
  133. };
  134. thisData = {};
  135. };
  136. this.setState({
  137. ids: thisData.id,
  138. name: thisData.name, //接口名称
  139. urlType: thisData.type.toString(),
  140. url: thisData.url, //接口路径
  141. preModule: thisData.preModule, //接口上级模板功能
  142. createId: thisData.createId,
  143. createTime: new Date(thisData.createTime).toLocaleString(),
  144. updateTime: new Date(thisData.updateTime).toLocaleString(),
  145. autNo: thisData.autNo,
  146. auto: thisData.superId,
  147. showOrder: thisData.showOrder,
  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
  195. maskClosable={false}
  196. visible={this.state.visible}
  197. onOk={this.handleOk}
  198. onCancel={this.handleCancel}
  199. width="600px"
  200. title={this.props.userDetaile ? "权限详情" : "新建权限"}
  201. footer=""
  202. className="admin-desc-content"
  203. >
  204. <Form
  205. layout="horizontal"
  206. onSubmit={this.handleSubmit}
  207. id="demand-form"
  208. >
  209. <Spin spinning={this.state.loading}>
  210. <div className="clearfix">
  211. <FormItem
  212. className="half-middle"
  213. {...formItemLayout}
  214. label="接口名称"
  215. >
  216. <Input
  217. placeholder="接口名称"
  218. value={this.state.name}
  219. style={{ width: "230px" }}
  220. onChange={(e) => {
  221. this.setState({ name: e.target.value });
  222. }}
  223. required="required"
  224. />
  225. <span className="mandatory">*</span>
  226. </FormItem>
  227. <FormItem
  228. className="half-middle"
  229. {...formItemLayout}
  230. label="接口路径"
  231. >
  232. <Input
  233. placeholder="接口路径"
  234. value={this.state.url}
  235. style={{ width: "230px" }}
  236. onChange={(e) => {
  237. this.setState({ url: e.target.value });
  238. }}
  239. required="required"
  240. />
  241. <span className="mandatory">*</span>
  242. </FormItem>
  243. <FormItem
  244. className="half-middle"
  245. {...formItemLayout}
  246. label="接口类型"
  247. >
  248. {this.props.userDetaile ? (
  249. <Select
  250. placeholder="选择接口类型"
  251. style={{ width: "230px" }}
  252. value={this.state.urlType}
  253. onChange={(e) => {
  254. this.setState({ urlType: e });
  255. }}
  256. >
  257. {urlType.map(function (item) {
  258. return (
  259. <Select.Option key={item.value}>
  260. {item.key}
  261. </Select.Option>
  262. );
  263. })}
  264. </Select>
  265. ) : (
  266. <span>导航</span>
  267. )}
  268. </FormItem>
  269. </div>
  270. {this.props.userDetaile ? <div
  271. className="clearfix"
  272. >
  273. <FormItem
  274. className="half-middle"
  275. {...formItemLayout}
  276. label="上级功能模块"
  277. >
  278. <AutoComplete
  279. className="certain-category-search"
  280. dropdownClassName="certain-category-search-dropdown"
  281. dropdownMatchSelectWidth={false}
  282. dropdownStyle={{ width: 230 }}
  283. size="large"
  284. style={{ width: "230px" }}
  285. dataSource={options}
  286. placeholder="输入名称"
  287. value={this.state.auto}
  288. onChange={this.httpChange}
  289. filterOption={true}
  290. onBlur={this.blurChange}
  291. onSelect={this.selectAuto}
  292. >
  293. <Input />
  294. </AutoComplete>
  295. <span className="mandatory">*</span>
  296. </FormItem>
  297. <FormItem
  298. className="half-middle"
  299. {...formItemLayout}
  300. label="排序"
  301. >
  302. <Input
  303. placeholder="排序数字"
  304. value={this.state.showOrder}
  305. style={{ width: "230px" }}
  306. onChange={(e) => {
  307. this.setState({ showOrder: e.target.value });
  308. }}
  309. required="required"
  310. />
  311. </FormItem>
  312. <FormItem
  313. className="half-middle"
  314. {...formItemLayout}
  315. label="权限编号"
  316. >
  317. <span>{this.state.autNo}</span>
  318. </FormItem>
  319. <FormItem
  320. className="half-middle"
  321. {...formItemLayout}
  322. label="创建人"
  323. >
  324. <span>{this.state.createId}</span>
  325. </FormItem>
  326. <FormItem
  327. className="half-middle"
  328. {...formItemLayout}
  329. label="创建时间"
  330. >
  331. <span>{this.state.createTime}</span>
  332. </FormItem>
  333. <FormItem
  334. className="half-middle"
  335. {...formItemLayout}
  336. label="更新时间"
  337. >
  338. <span>{this.state.updateTime}</span>
  339. </FormItem>
  340. </div> : null}
  341. <FormItem className="half-middle">
  342. <Button
  343. className="set-submit"
  344. type="primary"
  345. htmlType="submit"
  346. style={{ marginLeft: "150px" }}
  347. >
  348. 保存
  349. </Button>
  350. <Button
  351. className="set-submit"
  352. type="ghost"
  353. onClick={this.handleCancel}
  354. >
  355. 取消
  356. </Button>
  357. </FormItem>
  358. </Spin>
  359. </Form>
  360. </Modal>
  361. </div>
  362. );
  363. }
  364. }));
  365. export default Addjurisdiction;