newUser.jsx 22 KB

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