newUser.jsx 21 KB

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