newUser.jsx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. import React from 'react';
  2. import { Icon, Modal, message, AutoComplete,Spin, Input, Select, Button, Form,Upload,Popconfirm ,DatePicker} 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. import moment from 'moment';
  10. //图片组件
  11. const PicturesWall = React.createClass({
  12. getInitialState() {
  13. return {
  14. previewVisible: false,
  15. previewImage: '',
  16. fileList: [],
  17. role:[],
  18. district:[],
  19. cityOption:[],
  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. getDefaultProps(){
  77. return{
  78. userDetaile:false
  79. }
  80. },
  81. handleSubmit(e) {
  82. e.preventDefault();
  83. if(!this.state.role){
  84. message.warning('请选择角色');
  85. return false;
  86. };
  87. if(!this.state.status&&this.props.userDetaile){
  88. message.warning('请选择角色状态');
  89. return false;
  90. };
  91. if(window.adminData.isSuperAdmin){
  92. if(!this.state.departmentId){
  93. message.warning('请选择组织部门');
  94. return false;
  95. };
  96. }
  97. if(!this.state.theTypes&&!this.state.superiorId){
  98. message.warning('请输入正确的上级主管');
  99. return false;
  100. };
  101. if(this.state.contactMobile){
  102. if(!(/^1[1-9][0-9]\d{4,8}$/.test(this.state.contactMobile))){
  103. message.warning("不是完整的11位手机号或者正确的手机号前七位");
  104. this.setState({
  105. loading: false
  106. });
  107. return false;
  108. }
  109. }
  110. if(this.state.mobile.length>11){
  111. message.warning("用户名不能超过11位");
  112. return false;
  113. }
  114. let theorgCodeUrl = [];
  115. if (this.state.orgCodeUrl.length) {
  116. let picArr = [];
  117. this.state.orgCodeUrl.map(function (item) {
  118. if ( item.response && item.response.data && item.response.data.length ){
  119. picArr.push(item.response.data);
  120. }
  121. });
  122. theorgCodeUrl = picArr.join(",");
  123. };
  124. let api = this.props.userDetaile?"/api/admin/superviser/updateAdmin":'/api/admin/superviser/insertAdmin'
  125. this.setState({
  126. loading: true
  127. });
  128. let roleArrT=[];
  129. roleArrT.push((this.state.role).toString())
  130. $.ajax({
  131. method: "POST",
  132. dataType: "json",
  133. crossDomain: false,
  134. url: globalConfig.context + api,
  135. data: {
  136. roles:roleArrT,
  137. data:JSON.stringify({
  138. id:this.state.id?this.state.id:this.props.addId,
  139. mobile:this.state.mobile,
  140. status:this.state.status,
  141. contactMobile:this.state.contactMobile,
  142. name:this.state.name,
  143. departmentId:window.adminData.isSuperAdmin?this.state.departmentId:window.adminData.departmentId,
  144. duty:this.state.duty,
  145. position:this.state.position,//岗位
  146. email:this.state.email,
  147. superiorId:this.state.theTypes?this.state.theTypes:this.state.superiorId,
  148. district:this.state.district,
  149. headPortraitUrl:theorgCodeUrl.length?theorgCodeUrl:'',
  150. entryTime:this.state.selTime
  151. })
  152. }
  153. }).done(function (data) {
  154. this.setState({
  155. loading: false
  156. });
  157. if (!data.error.length) {
  158. message.success('保存成功!');
  159. this.handleOk();
  160. } else {
  161. message.warning(data.error[0].message);
  162. }
  163. }.bind(this));
  164. },
  165. //主管初始加载(自动补全)
  166. supervisor(e){
  167. $.ajax({
  168. method: "post",
  169. dataType: "json",
  170. crossDomain: false,
  171. url: globalConfig.context + "/api/admin/organization/selectName",
  172. data:{
  173. name:e
  174. },
  175. success: function (data) {
  176. let thedata=data.data;
  177. if (!thedata) {
  178. if (data.error && data.error.length) {
  179. message.warning(data.error[0].message);
  180. };
  181. thedata = {};
  182. };
  183. this.setState({
  184. customerArr:thedata,
  185. });
  186. }.bind(this),
  187. }).always(function () {
  188. this.setState({
  189. loading: false
  190. });
  191. }.bind(this));
  192. },
  193. //上级主管输入框失去焦点是判断客户是否存在
  194. selectAuto(value,options){
  195. this.setState({
  196. superior:value
  197. })
  198. },
  199. blurChange(e){
  200. let theType='';
  201. let contactLists=this.state.customerArr||[];
  202. if (e) {
  203. contactLists.map(function (item) {
  204. if (item.name == e.toString()) {
  205. theType = item.id;
  206. }
  207. });
  208. }
  209. this.setState({
  210. theName:e,
  211. theTypes:theType
  212. })
  213. },
  214. //值改变时请求客户名称
  215. httpChange(e){
  216. if(e.length>=1){
  217. this.supervisor(e);
  218. }
  219. this.setState({
  220. superior:e
  221. })
  222. },
  223. //查看基本详情基本信息
  224. loaduser(record){
  225. if(record){
  226. $.ajax({
  227. method: "post",
  228. dataType: "json",
  229. crossDomain: false,
  230. url: globalConfig.context + '/api/admin/superviser/selectAllByid',
  231. data: {
  232. id: record.id
  233. },
  234. success: function (data) {
  235. let thisdata = data.data;
  236. if (!thisdata) {
  237. if (data.error && data.error.length) {
  238. message.warning(data.error[0].message);
  239. };
  240. thisdata = {};
  241. };
  242. let roleArr=[]
  243. roleArr.push(this.props.role[0])
  244. this.setState({
  245. id: thisdata.id,
  246. mobile: thisdata.mobile,
  247. name: thisdata.name,
  248. email: thisdata.email,
  249. createTime: thisdata.createTime,
  250. district:thisdata.district!=' '?JSON.parse(thisdata.district):undefined,
  251. position: thisdata.position?thisdata.position:undefined,
  252. superior:thisdata.superior,
  253. superiorId: thisdata.superiorId,//上级Id
  254. duty:thisdata.duty?thisdata.duty:undefined,//职务
  255. status:thisdata.status?thisdata.status:undefined,
  256. contactMobile:thisdata.contactMobile?thisdata.contactMobile:undefined,//手机号
  257. departmentId:thisdata.departmentId?thisdata.departmentId:undefined,//部门id
  258. userNo:thisdata.userNo,
  259. orgCodeUrl: thisdata.headPortraitUrl? splitUrl(thisdata.headPortraitUrl, ',', globalConfig.avatarHost + '/upload') : [],
  260. role:roleArr,
  261. theTypes:'',
  262. entryTime:thisdata.entryTime?moment(thisdata.entryTime,'YYYY-MM-DD'):undefined,
  263. selTime:thisdata.entryTime
  264. });
  265. }.bind(this),
  266. }).always(function () {
  267. this.setState({
  268. loading: false
  269. });
  270. }.bind(this));
  271. }
  272. },
  273. //重置密码
  274. resetPwd() {
  275. this.setState({
  276. loading: true
  277. })
  278. $.ajax({
  279. type: 'post',
  280. url: globalConfig.context + "/api/admin/superviser/resetPwd",
  281. dataType: "json",
  282. data: {
  283. id: this.props.datauser.id
  284. },
  285. }).done((res) => {
  286. if (res.error && res.error.length) {
  287. message.error(res.error[0].message);
  288. } else {
  289. message.success("密码重置成功");
  290. }
  291. }).always(() => {
  292. this.setState({
  293. loading: false
  294. })
  295. });
  296. },
  297. handleOk(e) {
  298. this.setState({
  299. visible: false,
  300. });
  301. this.props.closeDesc(false, true);
  302. },
  303. handleCancel(e) {
  304. this.setState({
  305. visible: false,
  306. });
  307. this.props.closeDesc(false);
  308. },
  309. //入职时间选择
  310. selTime(e,index){
  311. this.setState({
  312. entryTime:e,
  313. selTime:index
  314. })
  315. },
  316. getOrgCodeUrl(e) {
  317. this.setState({ orgCodeUrl: e });
  318. },
  319. componentWillMount(e){
  320. const cityArrs=[];
  321. cityArr.map(function (item) {
  322. cityArrs.push(
  323. <Select.Option key={item.value}>{item.key}</Select.Option>
  324. )
  325. });
  326. this.state.cityOption=cityArrs;
  327. },
  328. componentWillReceiveProps(nextProps) {
  329. if(nextProps.userDetaile&&nextProps.datauser.id){
  330. this.loaduser(nextProps.datauser)
  331. this.setState({
  332. rolek:nextProps.role
  333. })
  334. }else{
  335. this.state.name='';
  336. this.state.role=[];
  337. this.state.departmentId=undefined;
  338. this.state.mobile='';
  339. this.state.duty=undefined;
  340. this.state.position=undefined;
  341. this.state.station=undefined;
  342. this.state.contactMobile='';
  343. this.state.email='';
  344. this.state.superiorId='';
  345. this.state.superior='';
  346. this.state.district=[];
  347. this.state.orgCodeUrl=[];
  348. this.state.id='';
  349. this.state.rolek=[];
  350. this.state.entryTime=undefined;
  351. }
  352. this.state.visible = nextProps.showDesc;
  353. },
  354. render() {
  355. const FormItem = Form.Item
  356. const formItemLayout = {
  357. labelCol: { span: 8 },
  358. wrapperCol: { span: 14 },
  359. };
  360. const dataSources=this.state.customerArr || [];
  361. const options = dataSources.map((group,index) =>
  362. <Select.Option key={index} value={group.name}>{group.name}</Select.Option>
  363. )
  364. const departmentArr=this.props.departmentArr || [];
  365. const roleArrS=this.props.roleArr || [];
  366. const rolst=this.state.rolek || [];
  367. return (
  368. <div>
  369. <Modal maskClosable={false} visible={this.state.visible}
  370. onOk={this.handleOk} onCancel={this.handleCancel}
  371. width='800px'
  372. title={this.props.userDetaile?'用户详情':'新建用户'}
  373. footer=''
  374. className="admin-desc-content">
  375. <Form layout="horizontal" onSubmit={this.handleSubmit} id="demand-form">
  376. <Spin spinning={this.state.loading}>
  377. <div className="clearfix">
  378. <div className="clearfix">
  379. <FormItem className="half-item"
  380. {...formItemLayout}
  381. label="用户名" >
  382. <Input placeholder="输入登录用户名" value={this.state.mobile}
  383. onChange={(e)=>{this.setState({mobile:e.target.value})}} required="required" style={{width:'200px'}}/>
  384. <span className="mandatory">*</span>
  385. </FormItem>
  386. {this.props.userDetaile?
  387. <Popconfirm
  388. title={"用户 [ " + this.props.datauser.name + " ] 的密码将会重置为123456,确认操作?"}
  389. onConfirm={this.resetPwd}
  390. okText="确认"
  391. cancelText="取消"
  392. placement="topLeft">
  393. <Button>重置密码</Button>
  394. </Popconfirm>:''}
  395. </div>
  396. <FormItem className="half-item"
  397. {...formItemLayout}
  398. label="用户角色"
  399. >
  400. <Select
  401. placeholder="选择用户角色"
  402. value={this.state.role}
  403. style={{width:'200px'}}
  404. onChange={(e)=>{this.setState({role:e})}} >
  405. {
  406. roleArrS.map(function (item) {
  407. return <Select.Option key={item.id} >{item.roleName}</Select.Option>
  408. })
  409. }
  410. </Select>
  411. <span className="mandatory">*</span>
  412. </FormItem>
  413. <FormItem className="half-item"
  414. {...formItemLayout}
  415. label=""
  416. >
  417. <span style={{display:rolst.length>1?'block':'none',color:'red'}}>存在多个角色</span>
  418. </FormItem>
  419. {this.props.userDetaile?<FormItem className="half-item"
  420. {...formItemLayout}
  421. label="用户状态" >
  422. <Select placeholder="用户状态" value={this.state.status} style={{width:'200px'}}
  423. onChange={(e)=>{this.setState({status:e})}} >
  424. <Select.Option value="正常" >正常</Select.Option>
  425. <Select.Option value="注销" >注销</Select.Option>
  426. <Select.Option value="锁定" >锁定</Select.Option>
  427. </Select>
  428. <span className="mandatory">*</span>
  429. </FormItem>:''}
  430. <FormItem className="half-item"
  431. {...formItemLayout}
  432. label="用户姓名" >
  433. <Input placeholder="请输入用户姓名" style={{width:'200px'}} value={this.state.name}
  434. onChange={(e)=>{this.setState({name:e.target.value})}} required="required"/>
  435. <span className="mandatory">*</span>
  436. </FormItem>
  437. <FormItem className="half-item"
  438. {...formItemLayout}
  439. label="联系方式" >
  440. <Input placeholder="请输入手机号" style={{width:'200px'}} value={this.state.contactMobile}
  441. onChange={(e)=>{this.setState({contactMobile:e.target.value})}} />
  442. </FormItem>
  443. {/*<FormItem className="half-item"
  444. {...formItemLayout}
  445. label="入职时间" >
  446. <DatePicker
  447. style={{marginTop:'0',width:'200px',height:'32px'}}
  448. showTime
  449. format="YYYY-MM-DD"
  450. placeholder="选择入职时间"
  451. value={this.state.entryTime}
  452. onChange={(e,time)=>{this.selTime(e,time)}}
  453. />
  454. </FormItem>*/}
  455. {window.adminData.isSuperAdmin?<FormItem className="half-item"
  456. {...formItemLayout}
  457. label="组织部门" >
  458. <Select placeholder="选择组织部门"
  459. style={{ width: 200 }}
  460. value={this.state.departmentId}
  461. onChange={(e) => { this.setState({ departmentId: e }) }}>
  462. {
  463. departmentArr.map(function (item) {
  464. return <Select.Option key={item.id} >{item.name}</Select.Option>
  465. })
  466. }
  467. </Select>
  468. <span className="mandatory">*</span>
  469. </FormItem>:''}
  470. <FormItem className="half-item"
  471. {...formItemLayout}
  472. label="职务"
  473. >
  474. <Select placeholder="选择职务" style={{width:'200px'}} value={this.state.duty} onChange={(e)=>{this.setState({duty:e})}}>
  475. {
  476. post.map(function (item) {
  477. return <Select.Option key={item.value} >{item.key}</Select.Option>
  478. })
  479. }
  480. </Select>
  481. </FormItem>
  482. <FormItem className="half-item"
  483. {...formItemLayout}
  484. label="岗位"
  485. >
  486. <Select placeholder="选择岗位" style={{width:'200px'}} value={this.state.position} onChange={(e)=>{this.setState({position:e})}}>
  487. {
  488. station.map(function (item) {
  489. return <Select.Option key={item.value} >{item.key}</Select.Option>
  490. })
  491. }
  492. </Select>
  493. </FormItem>
  494. <FormItem className="half-item"
  495. {...formItemLayout}
  496. label="电子邮箱" >
  497. <Input placeholder="请输入邮箱" style={{width:'200px'}} value={this.state.email}
  498. onChange={(e)=>{this.setState({email:e.target.value})}} />
  499. </FormItem>
  500. <FormItem className="half-item"
  501. {...formItemLayout}
  502. label="上级主管"
  503. >
  504. <AutoComplete
  505. className="certain-category-search"
  506. dropdownClassName="certain-category-search-dropdown"
  507. dropdownMatchSelectWidth={false}
  508. dropdownStyle={{ width: 200 }}
  509. size="large"
  510. style={{ width: '200px' }}
  511. dataSource={options}
  512. placeholder="输入名称"
  513. value={this.state.superior}
  514. onChange={this.httpChange}
  515. filterOption={true}
  516. onBlur={this.blurChange}
  517. onSelect={this.selectAuto}
  518. >
  519. <Input/>
  520. </AutoComplete>
  521. <span className="mandatory">*</span>
  522. </FormItem>
  523. {this.props.userDetaile?
  524. <FormItem className="half-item"
  525. {...formItemLayout}
  526. label="用户编号" >
  527. <span>{this.state.userNo}</span>
  528. </FormItem>
  529. :''}
  530. <div className='clearfix'>
  531. <FormItem className="half-item"
  532. {...formItemLayout}
  533. label="地区" >
  534. <Select
  535. multiple
  536. style={{width:'500px'}}
  537. placeholder="选择地区"
  538. filterOption={(input, option) => { return option.props.children.indexOf(input) >= 0 }}
  539. value={this.state.district}
  540. onChange={(pids) => {
  541. this.state.district = pids;
  542. this.setState({
  543. district: this.state.district
  544. })
  545. }}
  546. >
  547. {this.state.cityOption}
  548. </Select>
  549. </FormItem>
  550. </div>
  551. <div className="clearfix pictures">
  552. <FormItem
  553. labelCol={{ span: 4 }}
  554. wrapperCol={{ span: 18 }}
  555. label="用户头像" >
  556. <PicturesWall
  557. pictureSign="customer_sys_file"
  558. fileList={this.getOrgCodeUrl}
  559. pictureUrl={this.state.orgCodeUrl} />
  560. <p>图片建议:要清晰。</p>
  561. </FormItem>
  562. </div>
  563. </div>
  564. <FormItem wrapperCol={{ span: 12, offset: 4 }}>
  565. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  566. <Button className="set-submit" type="ghost" onClick={this.handleCancel}>取消</Button>
  567. </FormItem>
  568. </Spin>
  569. </Form >
  570. </Modal>
  571. </div>
  572. )
  573. }
  574. }));
  575. export default Newuser;