newUser.jsx 23 KB

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