newUser.jsx 24 KB

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