newUser.jsx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. import React from 'react';
  2. import { Icon, Modal, message, AutoComplete,Spin, Input, Select, Button, Form,Upload,Popconfirm } from 'antd';
  3. import ajax from 'jquery/src/ajax/xhr.js';
  4. import $ from 'jquery/src/ajax';
  5. import './userMangagement.less';
  6. import {socialAttribute,cityArr,station,post} from '../../../dataDic.js';
  7. import {splitUrl} from '../../../tools.js';
  8. const Option = AutoComplete.Option;
  9. //图片组件
  10. const PicturesWall = React.createClass({
  11. getInitialState() {
  12. return {
  13. previewVisible: false,
  14. previewImage: '',
  15. fileList: [],
  16. role:[],
  17. district:[],
  18. cityOption:[],
  19. kkt:false
  20. }
  21. },
  22. handleCancel() {
  23. this.setState({ previewVisible: false })
  24. },
  25. handlePreview(file) {
  26. this.setState({
  27. previewImage: file.url || file.thumbUrl,
  28. previewVisible: true,
  29. });
  30. },
  31. handleChange(info) {
  32. let fileList = info.fileList;
  33. this.setState({ fileList });
  34. this.props.fileList(fileList);
  35. },
  36. componentWillReceiveProps(nextProps) {
  37. this.state.fileList = nextProps.pictureUrl;
  38. },
  39. render() {
  40. const { previewVisible, previewImage, fileList } = this.state;
  41. const uploadButton = (
  42. <div>
  43. <Icon type="plus" />
  44. <div className="ant-upload-text">点击上传</div>
  45. </div>
  46. );
  47. return (
  48. <div style={{display:"inline-block"}}>
  49. <Upload
  50. action={globalConfig.context + "/api/admin/superviser/uploadAdminImg"}
  51. data={{ 'sign': this.props.pictureSign }}
  52. listType="picture-card"
  53. fileList={fileList}
  54. onPreview={this.handlePreview}
  55. onChange={this.handleChange} >
  56. {fileList.length >= 1 ? null : uploadButton}
  57. </Upload>
  58. <Modal maskClosable={false} visible={previewVisible} footer={null} onCancel={this.handleCancel}>
  59. <img alt="example" style={{ width: '100%' }} src={previewImage} />
  60. </Modal>
  61. </div>
  62. );
  63. }
  64. });
  65. const Newuser = Form.create()(React.createClass({
  66. getInitialState() {
  67. return {
  68. orgCodeUrl:[],
  69. loading: false,
  70. loaduser: {},
  71. visible:false,
  72. datauser:[],
  73. role:[]
  74. };
  75. },
  76. handleSubmit(e) {
  77. e.preventDefault();
  78. if(!this.state.role){
  79. message.warning('请选择角色');
  80. return false;
  81. };
  82. if(!this.state.status&&this.props.userDetaile){
  83. message.warning('请选择角色状态');
  84. return false;
  85. };
  86. if(!this.state.departmentId){
  87. message.warning('请选择组织部门');
  88. return false;
  89. };
  90. if(!this.state.theTypes&&!this.state.superiorId){
  91. message.warning('请输入正确的上级主管');
  92. return false;
  93. };
  94. let theorgCodeUrl = [];
  95. if (this.state.orgCodeUrl.length) {
  96. let picArr = [];
  97. this.state.orgCodeUrl.map(function (item) {
  98. picArr.push(item.response.data);
  99. });
  100. theorgCodeUrl = picArr.join(",");
  101. };
  102. let api = this.props.userDetaile?"/api/admin/superviser/updateAdmin":'/api/admin/superviser/insertAdmin'
  103. this.setState({
  104. loading: true
  105. });
  106. let roleArrT=[];
  107. roleArrT.push((this.state.role).toString())
  108. $.ajax({
  109. method: "POST",
  110. dataType: "json",
  111. crossDomain: false,
  112. url: globalConfig.context + api,
  113. data: {
  114. roles:roleArrT,
  115. data:JSON.stringify({
  116. id:this.state.id?this.state.id:this.props.addId,
  117. mobile:this.state.mobile,
  118. status:this.state.status,
  119. name:this.state.name,
  120. departmentId:this.state.departmentId,
  121. duty:this.state.duty,
  122. position:this.state.position,//岗位
  123. email:this.state.email,
  124. superiorId:this.state.theTypes?this.state.theTypes:this.state.superiorId,
  125. district:this.state.district,
  126. headPortraitUrl:theorgCodeUrl,
  127. })
  128. }
  129. }).done(function (data) {
  130. this.setState({
  131. loading: false
  132. });
  133. if (!data.error.length) {
  134. message.success('保存成功!');
  135. this.handleOk();
  136. } else {
  137. message.warning(data.error[0].message);
  138. }
  139. }.bind(this));
  140. },
  141. //主管初始加载(自动补全)
  142. supervisor(e){
  143. $.ajax({
  144. method: "post",
  145. dataType: "json",
  146. crossDomain: false,
  147. url: globalConfig.context + "/api/admin/organization/selectName",
  148. data:{
  149. name:e
  150. },
  151. success: function (data) {
  152. let thedata=data.data;
  153. if (!thedata) {
  154. if (data.error && data.error.length) {
  155. message.warning(data.error[0].message);
  156. };
  157. thedata = {};
  158. };
  159. this.setState({
  160. customerArr:thedata,
  161. });
  162. }.bind(this),
  163. }).always(function () {
  164. this.setState({
  165. loading: false
  166. });
  167. }.bind(this));
  168. },
  169. //上级主管输入框失去焦点是判断客户是否存在
  170. selectAuto(value,options){
  171. this.setState({
  172. superior:value
  173. })
  174. },
  175. blurChange(e){
  176. let theType='';
  177. let contactLists=this.state.customerArr||[];
  178. if (e) {
  179. contactLists.map(function (item) {
  180. if (item.name == e.toString()) {
  181. theType = item.id;
  182. }
  183. });
  184. }
  185. this.setState({
  186. theTypes:theType
  187. })
  188. },
  189. //值改变时请求客户名称
  190. httpChange(e){
  191. if(e.length>=1){
  192. this.supervisor(e);
  193. }
  194. this.setState({
  195. superior:e
  196. })
  197. },
  198. //查看基本详情基本信息
  199. loaduser(record){
  200. if(record){
  201. $.ajax({
  202. method: "post",
  203. dataType: "json",
  204. crossDomain: false,
  205. url: globalConfig.context + '/api/admin/superviser/selectAllByid',
  206. data: {
  207. id: record.id
  208. },
  209. success: function (data) {
  210. let thisdata = data.data;
  211. if (!thisdata) {
  212. if (data.error && data.error.length) {
  213. message.warning(data.error[0].message);
  214. };
  215. thisdata = {};
  216. };
  217. let roleArr=[]
  218. roleArr.push(this.props.role[0])
  219. this.setState({
  220. id: thisdata.id,
  221. mobile: thisdata.mobile,
  222. name: thisdata.name,
  223. email: thisdata.email,
  224. createTime: thisdata.createTime,
  225. district:thisdata.district!=' '?JSON.parse(thisdata.district):undefined,
  226. position: thisdata.position?thisdata.position:undefined,
  227. superior:thisdata.superior,
  228. superiorId: thisdata.superiorId,//上级Id
  229. duty:thisdata.duty?thisdata.duty:undefined,//职务
  230. status:thisdata.status?thisdata.status:undefined,
  231. departmentId:thisdata.departmentId?thisdata.departmentId:undefined,//部门id
  232. userNo:thisdata.userNo,
  233. orgCodeUrl: thisdata.headPortraitUrl? splitUrl(thisdata.headPortraitUrl, ',', globalConfig.avatarHost + '/upload') : [],
  234. role:roleArr,
  235. });
  236. }.bind(this),
  237. }).always(function () {
  238. this.setState({
  239. loading: false
  240. });
  241. }.bind(this));
  242. }
  243. },
  244. //重置密码
  245. resetPwd() {
  246. this.setState({
  247. loading: true
  248. })
  249. $.ajax({
  250. type: 'post',
  251. url: globalConfig.context + "/api/admin/superviser/resetPwd",
  252. dataType: "json",
  253. data: {
  254. id: this.props.datauser.id
  255. },
  256. }).done((res) => {
  257. if (res.error && res.error.length) {
  258. message.error(res.error[0].message);
  259. } else {
  260. message.success("密码重置成功");
  261. }
  262. }).always(() => {
  263. this.setState({
  264. loading: false
  265. })
  266. });
  267. },
  268. handleOk(e) {
  269. this.setState({
  270. visible: false,
  271. });
  272. this.props.closeDesc(false, true);
  273. },
  274. handleCancel(e) {
  275. this.setState({
  276. visible: false,
  277. });
  278. this.props.closeDesc(false);
  279. },
  280. getOrgCodeUrl(e) {
  281. this.setState({ orgCodeUrl: e });
  282. },
  283. componentWillMount(e){
  284. const cityArrs=[];
  285. cityArr.map(function (item) {
  286. cityArrs.push(
  287. <Select.Option key={item.value}>{item.key}</Select.Option>
  288. )
  289. });
  290. this.state.cityOption=cityArrs;
  291. },
  292. componentWillReceiveProps(nextProps) {
  293. this.state.visible = nextProps.showDesc;
  294. this.state.Detaile=nextProps.userDetaile;
  295. if(nextProps.userDetaile&&nextProps.datauser.id){
  296. this.loaduser(nextProps.datauser)
  297. }else{
  298. this.state.name='';
  299. this.state.role=[];
  300. this.state.departmentId=undefined;
  301. this.state.mobile='';
  302. this.state.duty=undefined;
  303. this.state.position=undefined;
  304. this.state.station=undefined;
  305. this.state.email='';
  306. this.state.superiorId='';
  307. this.state.superior='';
  308. this.state.district=[];
  309. this.state.orgCodeUrl=[];
  310. this.state.id='';
  311. }
  312. },
  313. render() {
  314. const FormItem = Form.Item
  315. const formItemLayout = {
  316. labelCol: { span: 8 },
  317. wrapperCol: { span: 14 },
  318. };
  319. const dataSources=this.state.customerArr || [];
  320. const options = dataSources.map((group,index) =>
  321. <Select.Option key={index} value={group.name}>{group.name}</Select.Option>
  322. )
  323. const departmentArr=this.props.departmentArr || [];
  324. const roleArrS=this.props.roleArr || [];
  325. const rolst=this.props.role || [];
  326. return (
  327. <div>
  328. <Modal maskClosable={false} visible={this.state.visible}
  329. onOk={this.handleOk} onCancel={this.handleCancel}
  330. width='800px'
  331. title={this.props.userDetaile?'用户详情':'新建用户'}
  332. footer=''
  333. className="admin-desc-content">
  334. <Form layout="horizontal" onSubmit={this.handleSubmit} id="demand-form">
  335. <Spin spinning={this.state.loading}>
  336. <div className="clearfix">
  337. <div className="clearfix">
  338. <FormItem className="half-item"
  339. {...formItemLayout}
  340. label="用户名" >
  341. <Input placeholder="输入登录用户名" value={this.state.mobile}
  342. onChange={(e)=>{this.setState({mobile:e.target.value})}} required="required" style={{width:'200px'}}/>
  343. <span className="mandatory">*</span>
  344. </FormItem>
  345. {this.props.userDetaile?
  346. <Popconfirm
  347. title={"用户 [ " + this.props.datauser.name + " ] 的密码将会重置为123456,确认操作?"}
  348. onConfirm={this.resetPwd}
  349. okText="确认"
  350. cancelText="取消"
  351. placement="topLeft">
  352. <Button>重置密码</Button>
  353. </Popconfirm>:''}
  354. </div>
  355. <FormItem className="half-item"
  356. {...formItemLayout}
  357. label="用户角色"
  358. >
  359. <Select
  360. placeholder="选择用户角色"
  361. value={this.state.role}
  362. style={{width:'200px'}}
  363. onChange={(e)=>{this.setState({role:e,kkt:true})}} >
  364. {
  365. roleArrS.map(function (item) {
  366. return <Select.Option key={item.id} >{item.roleName}</Select.Option>
  367. })
  368. }
  369. </Select>
  370. <span className="mandatory">*</span>
  371. </FormItem>
  372. <FormItem className="half-item"
  373. {...formItemLayout}
  374. label=""
  375. >
  376. <span style={{display:rolst.length>1?'block':'none',color:'red'}}>存在多个角色</span>
  377. </FormItem>
  378. {this.props.userDetaile?<FormItem className="half-item"
  379. {...formItemLayout}
  380. label="用户状态" >
  381. <Select placeholder="用户状态" value={this.state.status} style={{width:'200px'}}
  382. onChange={(e)=>{this.setState({status:e})}} >
  383. <Select.Option value="正常" >正常</Select.Option>
  384. <Select.Option value="注销" >注销</Select.Option>
  385. <Select.Option value="锁定" >锁定</Select.Option>
  386. </Select>
  387. <span className="mandatory">*</span>
  388. </FormItem>:''}
  389. <FormItem className="half-item"
  390. {...formItemLayout}
  391. label="用户姓名" >
  392. <Input placeholder="请输入用户姓名" style={{width:'200px'}} value={this.state.name}
  393. onChange={(e)=>{this.setState({name:e.target.value})}} required="required"/>
  394. <span className="mandatory">*</span>
  395. </FormItem>
  396. <FormItem className="half-item"
  397. {...formItemLayout}
  398. label="组织部门" >
  399. <Select placeholder="选择组织部门"
  400. style={{ width: 200 }}
  401. value={this.state.departmentId}
  402. onChange={(e) => { this.setState({ departmentId: e }) }}>
  403. {
  404. departmentArr.map(function (item) {
  405. return <Select.Option key={item.id} >{item.name}</Select.Option>
  406. })
  407. }
  408. </Select>
  409. <span className="mandatory">*</span>
  410. </FormItem>
  411. <FormItem className="half-item"
  412. {...formItemLayout}
  413. label="职务"
  414. >
  415. <Select placeholder="选择职务" style={{width:'200px'}} value={this.state.duty} onChange={(e)=>{this.setState({duty:e})}}>
  416. {
  417. post.map(function (item) {
  418. return <Select.Option key={item.value} >{item.key}</Select.Option>
  419. })
  420. }
  421. </Select>
  422. </FormItem>
  423. <FormItem className="half-item"
  424. {...formItemLayout}
  425. label="岗位"
  426. >
  427. <Select placeholder="选择岗位" style={{width:'200px'}} value={this.state.position} onChange={(e)=>{this.setState({position:e})}}>
  428. {
  429. station.map(function (item) {
  430. return <Select.Option key={item.value} >{item.key}</Select.Option>
  431. })
  432. }
  433. </Select>
  434. </FormItem>
  435. <FormItem className="half-item"
  436. {...formItemLayout}
  437. label="电子邮箱" >
  438. <Input placeholder="请输入邮箱" style={{width:'200px'}} value={this.state.email}
  439. onChange={(e)=>{this.setState({email:e.target.value})}} />
  440. </FormItem>
  441. <FormItem className="half-item"
  442. {...formItemLayout}
  443. label="上级主管"
  444. >
  445. <AutoComplete
  446. className="certain-category-search"
  447. dropdownClassName="certain-category-search-dropdown"
  448. dropdownMatchSelectWidth={false}
  449. dropdownStyle={{ width: 200 }}
  450. size="large"
  451. style={{ width: '200px' }}
  452. dataSource={options}
  453. placeholder="输入名称"
  454. value={this.state.superior}
  455. onChange={this.httpChange}
  456. filterOption={true}
  457. onBlur={this.blurChange}
  458. onSelect={this.selectAuto}
  459. >
  460. <Input/>
  461. </AutoComplete>
  462. <span className="mandatory">*</span>
  463. </FormItem>
  464. {this.props.userDetaile?
  465. <FormItem className="half-item"
  466. {...formItemLayout}
  467. label="用户编号" >
  468. <span>{this.state.userNo}</span>
  469. </FormItem>
  470. :''}
  471. <div className='clearfix'>
  472. <FormItem className="half-item"
  473. {...formItemLayout}
  474. label="地区" >
  475. <Select
  476. multiple
  477. style={{width:'500px'}}
  478. placeholder="选择地区"
  479. filterOption={(input, option) => { return option.props.children.indexOf(input) >= 0 }}
  480. value={this.state.district}
  481. onChange={(pids) => {
  482. this.state.district = pids;
  483. this.setState({
  484. district: this.state.district
  485. })
  486. }}
  487. >
  488. {this.state.cityOption}
  489. </Select>
  490. </FormItem>
  491. </div>
  492. <div className="clearfix pictures">
  493. <FormItem
  494. labelCol={{ span: 4 }}
  495. wrapperCol={{ span: 18 }}
  496. label="用户头像" >
  497. <PicturesWall
  498. pictureSign="customer_sys_file"
  499. fileList={this.getOrgCodeUrl}
  500. pictureUrl={this.state.orgCodeUrl} />
  501. <p>图片建议:要萌。</p>
  502. </FormItem>
  503. </div>
  504. </div>
  505. <FormItem wrapperCol={{ span: 12, offset: 4 }}>
  506. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  507. <Button className="set-submit" type="ghost" onClick={this.handleCancel}>取消</Button>
  508. </FormItem>
  509. </Spin>
  510. </Form >
  511. </Modal>
  512. </div>
  513. )
  514. }
  515. }));
  516. export default Newuser;