newUser.jsx 22 KB

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