newUser.jsx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  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){
  194. let theType='';
  195. let contactLists=this.state.customerArr||[];
  196. if (value) {
  197. contactLists.map(function (item) {
  198. if (item.name === value.toString()) {
  199. theType = item.id;
  200. }
  201. });
  202. }
  203. this.setState({
  204. theTypes:theType,
  205. superior:value
  206. })
  207. if(!this.state.reviewerName || !this.state.reviewer){
  208. this.setState({
  209. reviewerName:value,
  210. reviewer:theType
  211. })
  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. this.setState({
  243. id: thisdata.id,
  244. mobile: thisdata.mobile,
  245. name: thisdata.name,
  246. email: thisdata.email,
  247. createTime: thisdata.createTime,
  248. district:thisdata.district!=' '?JSON.parse(thisdata.district):undefined,
  249. position: thisdata.position?thisdata.position:undefined,
  250. superior:thisdata.superior,
  251. superiorId: thisdata.superiorId,//上级Id
  252. reviewerName:thisdata.reviewerName,
  253. reviewer:thisdata.reviewer,
  254. theTypes:'',
  255. duty:thisdata.duty?thisdata.duty:undefined,//职务
  256. status:thisdata.status?thisdata.status:undefined,
  257. contactMobile:thisdata.contactMobile?thisdata.contactMobile:undefined,//手机号
  258. departmentId:thisdata.departmentId?thisdata.departmentId:undefined,//部门id
  259. userNo:thisdata.userNo,
  260. orgCodeUrl: thisdata.headPortraitUrl? splitUrl(thisdata.headPortraitUrl, ',', globalConfig.avatarHost + '/upload') : [],
  261. role:this.props.role,
  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.props.closeDesc(false, true);
  299. },
  300. handleCancel(e) {
  301. this.props.closeDesc(false);
  302. },
  303. //入职时间选择
  304. selTime(e,index){
  305. this.setState({
  306. entryTime:e,
  307. selTime:index
  308. })
  309. },
  310. getOrgCodeUrl(e) {
  311. this.setState({ orgCodeUrl: e });
  312. },
  313. componentWillMount(e){
  314. const cityArrs=[];
  315. cityArr.map(function (item) {
  316. cityArrs.push(
  317. <Select.Option key={item.value}>{item.key}</Select.Option>
  318. )
  319. });
  320. this.state.cityOption=cityArrs;
  321. },
  322. componentDidMount() {
  323. if(this.props.datauser.id){
  324. this.loaduser(this.props.datauser)
  325. this.setState({
  326. rolek:this.props.role
  327. })
  328. }
  329. },
  330. render() {
  331. const FormItem = Form.Item
  332. const formItemLayout = {
  333. labelCol: { span: 8 },
  334. wrapperCol: { span: 14 },
  335. };
  336. const dataSources=this.state.customerArr || [];
  337. const options = dataSources.map((group,index) =>
  338. <Select.Option key={index} value={group.name}>{group.name}</Select.Option>
  339. )
  340. const departmentArr=this.props.departmentArr || [];
  341. const roleArrS=this.props.roleArr || [];
  342. const rolst=this.state.rolek || [];
  343. return (
  344. <div>
  345. <Modal maskClosable={false} visible={this.props.showDesc}
  346. onOk={this.handleOk} onCancel={this.handleCancel}
  347. width='800px'
  348. title={this.props.userDetaile?'用户详情':'新建用户'}
  349. footer=''
  350. className="admin-desc-content">
  351. <Form layout="horizontal" onSubmit={this.handleSubmit} id="demand-form">
  352. <Spin spinning={this.state.loading}>
  353. <div className="clearfix">
  354. <div className="clearfix">
  355. <FormItem className="half-item"
  356. {...formItemLayout}
  357. label="用户名" >
  358. <Input placeholder="输入登录用户名" value={this.state.mobile}
  359. onChange={(e)=>{this.setState({mobile:e.target.value})}} required="required" style={{width:'200px'}}/>
  360. <span className="mandatory">*</span>
  361. </FormItem>
  362. {this.props.userDetaile?
  363. <Popconfirm
  364. title={"用户 [ " + this.props.datauser.name + " ] 的密码将会重置为123456,确认操作?"}
  365. onConfirm={this.resetPwd}
  366. okText="确认"
  367. cancelText="取消"
  368. placement="topLeft">
  369. <Button>重置密码</Button>
  370. </Popconfirm>:''}
  371. </div>
  372. <FormItem className="half-item"
  373. {...formItemLayout}
  374. label="用户角色"
  375. >
  376. {roleArrS.length > 0 ?
  377. <Select
  378. mode="multiple"
  379. optionFilterProp={'title'}
  380. tokenSeparators={[',']}
  381. placeholder="选择用户角色"
  382. value={this.state.role}
  383. style={{width:'200px'}}
  384. onChange={(e)=>{
  385. this.setState({
  386. role:e
  387. })
  388. }}>
  389. {
  390. roleArrS.map(function (item,_) {
  391. return <Select.Option title={item.roleName} value={item.id}>{item.roleName}</Select.Option>
  392. })
  393. }
  394. </Select> : null
  395. }
  396. <span className="mandatory">*</span>
  397. </FormItem>
  398. <FormItem className="half-item"
  399. {...formItemLayout}
  400. label=""
  401. >
  402. <span style={{display:rolst.length>1?'block':'none',color:'red'}}>存在多个角色</span>
  403. </FormItem>
  404. {this.props.userDetaile?<FormItem className="half-item"
  405. {...formItemLayout}
  406. label="用户状态" >
  407. <Select placeholder="用户状态" value={this.state.status} style={{width:'200px'}}
  408. onChange={(e)=>{this.setState({status:e})}} >
  409. <Select.Option value="正常" >正常</Select.Option>
  410. <Select.Option value="注销" >注销</Select.Option>
  411. <Select.Option value="锁定" >锁定</Select.Option>
  412. </Select>
  413. <span className="mandatory">*</span>
  414. </FormItem>:''}
  415. <FormItem className="half-item"
  416. {...formItemLayout}
  417. label="用户姓名" >
  418. <Input placeholder="请输入用户姓名" style={{width:'200px'}} value={this.state.name}
  419. onChange={(e)=>{this.setState({name:e.target.value})}} required="required"/>
  420. <span className="mandatory">*</span>
  421. </FormItem>
  422. <FormItem className="half-item"
  423. {...formItemLayout}
  424. label="联系方式" >
  425. <Input placeholder="请输入手机号" style={{width:'200px'}} value={this.state.contactMobile}
  426. onChange={(e)=>{this.setState({contactMobile:e.target.value})}} />
  427. </FormItem>
  428. {/*<FormItem className="half-item"
  429. {...formItemLayout}
  430. label="入职时间" >
  431. <DatePicker
  432. style={{marginTop:'0',width:'200px',height:'32px'}}
  433. showTime
  434. format="YYYY-MM-DD"
  435. placeholder="选择入职时间"
  436. value={this.state.entryTime}
  437. onChange={(e,time)=>{this.selTime(e,time)}}
  438. />
  439. </FormItem>*/}
  440. {window.adminData.isSuperAdmin?<FormItem className="half-item"
  441. {...formItemLayout}
  442. label="组织部门" >
  443. <Select placeholder="选择组织部门"
  444. style={{ width: 200 }}
  445. value={this.state.departmentId}
  446. onChange={(e) => { this.setState({ departmentId: e }) }}>
  447. {
  448. departmentArr.map(function (item) {
  449. return <Select.Option key={item.id} >{item.name}</Select.Option>
  450. })
  451. }
  452. </Select>
  453. <span className="mandatory">*</span>
  454. </FormItem>:''}
  455. <FormItem className="half-item"
  456. {...formItemLayout}
  457. label="职务"
  458. >
  459. <Select placeholder="选择职务" style={{width:'200px'}} value={this.state.duty} onChange={(e)=>{this.setState({duty:e})}}>
  460. {
  461. post.map(function (item) {
  462. return <Select.Option key={item.value} >{item.key}</Select.Option>
  463. })
  464. }
  465. </Select>
  466. </FormItem>
  467. <FormItem className="half-item"
  468. {...formItemLayout}
  469. label="岗位"
  470. >
  471. <Select placeholder="选择岗位" style={{width:'200px'}} value={this.state.position} onChange={(e)=>{this.setState({position:e})}}>
  472. {
  473. station.map(function (item) {
  474. return <Select.Option key={item.value} >{item.key}</Select.Option>
  475. })
  476. }
  477. </Select>
  478. </FormItem>
  479. <FormItem className="half-item"
  480. {...formItemLayout}
  481. label="电子邮箱" >
  482. <Input placeholder="请输入邮箱" style={{width:'200px'}} value={this.state.email}
  483. onChange={(e)=>{this.setState({email:e.target.value})}} />
  484. </FormItem>
  485. <FormItem className="half-item"
  486. {...formItemLayout}
  487. label="上级主管"
  488. >
  489. <AutoComplete
  490. className="certain-category-search"
  491. dropdownClassName="certain-category-search-dropdown"
  492. dropdownMatchSelectWidth={false}
  493. size="large"
  494. style={{ width: '200px' }}
  495. dataSource={options}
  496. placeholder="输入名称"
  497. value={this.state.superior}
  498. onChange={this.httpChange}
  499. filterOption={true}
  500. onSelect={this.selectAuto}
  501. >
  502. <Input/>
  503. </AutoComplete>
  504. <span className="mandatory">*</span>
  505. </FormItem>
  506. <FormItem className="half-item"
  507. {...formItemLayout}
  508. label="公出审核"
  509. >
  510. <StaffSearch
  511. valueName={this.state.reviewerName}
  512. placeholder="输入名称"
  513. onBlurChange={(obj)=>{
  514. this.setState({
  515. reviewer:obj.value
  516. })
  517. }}
  518. />
  519. <span className="mandatory">*</span>
  520. </FormItem>
  521. {this.props.userDetaile?
  522. <FormItem className="half-item"
  523. {...formItemLayout}
  524. label="用户编号" >
  525. <span>{this.state.userNo}</span>
  526. </FormItem>
  527. :''}
  528. <div className='clearfix'>
  529. <FormItem className="half-item"
  530. {...formItemLayout}
  531. label="地区" >
  532. <Select
  533. multiple
  534. style={{width:'500px'}}
  535. placeholder="选择地区"
  536. filterOption={(input, option) => { return option.props.children.indexOf(input) >= 0 }}
  537. value={this.state.district}
  538. onChange={(pids) => {
  539. this.state.district = pids;
  540. this.setState({
  541. district: this.state.district
  542. })
  543. }}
  544. >
  545. {this.state.cityOption}
  546. </Select>
  547. </FormItem>
  548. </div>
  549. <div className="clearfix pictures">
  550. <FormItem
  551. labelCol={{ span: 4 }}
  552. wrapperCol={{ span: 18 }}
  553. label="用户头像" >
  554. <PicturesWall
  555. domId={'newUser1'}
  556. pictureSign="customer_sys_file"
  557. fileList={this.getOrgCodeUrl}
  558. pictureUrl={this.state.orgCodeUrl} />
  559. <p>图片建议:要清晰。</p>
  560. </FormItem>
  561. </div>
  562. </div>
  563. <FormItem wrapperCol={{ span: 12, offset: 4 }}>
  564. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  565. <Button className="set-submit" type="ghost" onClick={this.handleCancel}>取消</Button>
  566. </FormItem>
  567. </Spin>
  568. </Form >
  569. </Modal>
  570. </div>
  571. )
  572. }
  573. }));
  574. export default Newuser;