newUser.jsx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  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. theTypes:theType
  193. })
  194. },
  195. //值改变时请求客户名称
  196. httpChange(e){
  197. if(e.length>=1){
  198. this.supervisor(e);
  199. }
  200. this.setState({
  201. superior:e
  202. })
  203. },
  204. //查看基本详情基本信息
  205. loaduser(record){
  206. if(record){
  207. $.ajax({
  208. method: "post",
  209. dataType: "json",
  210. crossDomain: false,
  211. url: globalConfig.context + '/api/admin/superviser/selectAllByid',
  212. data: {
  213. id: record.id
  214. },
  215. success: function (data) {
  216. let thisdata = data.data;
  217. if (!thisdata) {
  218. if (data.error && data.error.length) {
  219. message.warning(data.error[0].message);
  220. };
  221. thisdata = {};
  222. };
  223. let roleArr=[]
  224. roleArr.push(this.props.role[0])
  225. this.setState({
  226. id: thisdata.id,
  227. mobile: thisdata.mobile,
  228. name: thisdata.name,
  229. email: thisdata.email,
  230. createTime: thisdata.createTime,
  231. district:thisdata.district!=' '?JSON.parse(thisdata.district):undefined,
  232. position: thisdata.position?thisdata.position:undefined,
  233. superior:thisdata.superior,
  234. superiorId: thisdata.superiorId,//上级Id
  235. duty:thisdata.duty?thisdata.duty:undefined,//职务
  236. status:thisdata.status?thisdata.status:undefined,
  237. departmentId:thisdata.departmentId?thisdata.departmentId:undefined,//部门id
  238. userNo:thisdata.userNo,
  239. orgCodeUrl: thisdata.headPortraitUrl? splitUrl(thisdata.headPortraitUrl, ',', globalConfig.avatarHost + '/upload') : [],
  240. role:roleArr,
  241. });
  242. }.bind(this),
  243. }).always(function () {
  244. this.setState({
  245. loading: false
  246. });
  247. }.bind(this));
  248. }
  249. },
  250. //重置密码
  251. resetPwd() {
  252. this.setState({
  253. loading: true
  254. })
  255. $.ajax({
  256. type: 'post',
  257. url: globalConfig.context + "/api/admin/superviser/resetPwd",
  258. dataType: "json",
  259. data: {
  260. id: this.props.datauser.id
  261. },
  262. }).done((res) => {
  263. if (res.error && res.error.length) {
  264. message.error(res.error[0].message);
  265. } else {
  266. message.success("密码重置成功");
  267. }
  268. }).always(() => {
  269. this.setState({
  270. loading: false
  271. })
  272. });
  273. },
  274. handleOk(e) {
  275. this.setState({
  276. visible: false,
  277. });
  278. this.props.closeDesc(false, true);
  279. },
  280. handleCancel(e) {
  281. this.setState({
  282. visible: false,
  283. });
  284. this.props.closeDesc(false);
  285. },
  286. getOrgCodeUrl(e) {
  287. this.setState({ orgCodeUrl: e });
  288. },
  289. componentWillMount(e){
  290. const cityArrs=[];
  291. cityArr.map(function (item) {
  292. cityArrs.push(
  293. <Select.Option key={item.value}>{item.key}</Select.Option>
  294. )
  295. });
  296. this.state.cityOption=cityArrs;
  297. },
  298. componentWillReceiveProps(nextProps) {
  299. if(nextProps.userDetaile&&nextProps.datauser.id){
  300. this.loaduser(nextProps.datauser)
  301. this.setState({
  302. rolek:nextProps.role
  303. })
  304. }else{
  305. this.state.name='';
  306. this.state.role=[];
  307. this.state.departmentId=undefined;
  308. this.state.mobile='';
  309. this.state.duty=undefined;
  310. this.state.position=undefined;
  311. this.state.station=undefined;
  312. this.state.email='';
  313. this.state.superiorId='';
  314. this.state.superior='';
  315. this.state.district=[];
  316. this.state.orgCodeUrl=[];
  317. this.state.id='';
  318. this.state.rolek=[];
  319. }
  320. this.state.visible = nextProps.showDesc;
  321. },
  322. render() {
  323. const FormItem = Form.Item
  324. const formItemLayout = {
  325. labelCol: { span: 8 },
  326. wrapperCol: { span: 14 },
  327. };
  328. const dataSources=this.state.customerArr || [];
  329. const options = dataSources.map((group,index) =>
  330. <Select.Option key={index} value={group.name}>{group.name}</Select.Option>
  331. )
  332. const departmentArr=this.props.departmentArr || [];
  333. const roleArrS=this.props.roleArr || [];
  334. const rolst=this.state.rolek || [];
  335. return (
  336. <div>
  337. <Modal maskClosable={false} visible={this.state.visible}
  338. onOk={this.handleOk} onCancel={this.handleCancel}
  339. width='800px'
  340. title={this.props.userDetaile?'用户详情':'新建用户'}
  341. footer=''
  342. className="admin-desc-content">
  343. <Form layout="horizontal" onSubmit={this.handleSubmit} id="demand-form">
  344. <Spin spinning={this.state.loading}>
  345. <div className="clearfix">
  346. <div className="clearfix">
  347. <FormItem className="half-item"
  348. {...formItemLayout}
  349. label="用户名" >
  350. <Input placeholder="输入登录用户名" value={this.state.mobile}
  351. onChange={(e)=>{this.setState({mobile:e.target.value})}} required="required" style={{width:'200px'}}/>
  352. <span className="mandatory">*</span>
  353. </FormItem>
  354. {this.props.userDetaile?
  355. <Popconfirm
  356. title={"用户 [ " + this.props.datauser.name + " ] 的密码将会重置为123456,确认操作?"}
  357. onConfirm={this.resetPwd}
  358. okText="确认"
  359. cancelText="取消"
  360. placement="topLeft">
  361. <Button>重置密码</Button>
  362. </Popconfirm>:''}
  363. </div>
  364. <FormItem className="half-item"
  365. {...formItemLayout}
  366. label="用户角色"
  367. >
  368. <Select
  369. placeholder="选择用户角色"
  370. value={this.state.role}
  371. style={{width:'200px'}}
  372. onChange={(e)=>{this.setState({role:e})}} >
  373. {
  374. roleArrS.map(function (item) {
  375. return <Select.Option key={item.id} >{item.roleName}</Select.Option>
  376. })
  377. }
  378. </Select>
  379. <span className="mandatory">*</span>
  380. </FormItem>
  381. <FormItem className="half-item"
  382. {...formItemLayout}
  383. label=""
  384. >
  385. <span style={{display:rolst.length>1?'block':'none',color:'red'}}>存在多个角色</span>
  386. </FormItem>
  387. {this.props.userDetaile?<FormItem className="half-item"
  388. {...formItemLayout}
  389. label="用户状态" >
  390. <Select placeholder="用户状态" value={this.state.status} style={{width:'200px'}}
  391. onChange={(e)=>{this.setState({status:e})}} >
  392. <Select.Option value="正常" >正常</Select.Option>
  393. <Select.Option value="注销" >注销</Select.Option>
  394. <Select.Option value="锁定" >锁定</Select.Option>
  395. </Select>
  396. <span className="mandatory">*</span>
  397. </FormItem>:''}
  398. <FormItem className="half-item"
  399. {...formItemLayout}
  400. label="用户姓名" >
  401. <Input placeholder="请输入用户姓名" style={{width:'200px'}} value={this.state.name}
  402. onChange={(e)=>{this.setState({name:e.target.value})}} required="required"/>
  403. <span className="mandatory">*</span>
  404. </FormItem>
  405. <FormItem className="half-item"
  406. {...formItemLayout}
  407. label="组织部门" >
  408. <Select placeholder="选择组织部门"
  409. style={{ width: 200 }}
  410. value={this.state.departmentId}
  411. onChange={(e) => { this.setState({ departmentId: e }) }}>
  412. {
  413. departmentArr.map(function (item) {
  414. return <Select.Option key={item.id} >{item.name}</Select.Option>
  415. })
  416. }
  417. </Select>
  418. <span className="mandatory">*</span>
  419. </FormItem>
  420. <FormItem className="half-item"
  421. {...formItemLayout}
  422. label="职务"
  423. >
  424. <Select placeholder="选择职务" style={{width:'200px'}} value={this.state.duty} onChange={(e)=>{this.setState({duty:e})}}>
  425. {
  426. post.map(function (item) {
  427. return <Select.Option key={item.value} >{item.key}</Select.Option>
  428. })
  429. }
  430. </Select>
  431. </FormItem>
  432. <FormItem className="half-item"
  433. {...formItemLayout}
  434. label="岗位"
  435. >
  436. <Select placeholder="选择岗位" style={{width:'200px'}} value={this.state.position} onChange={(e)=>{this.setState({position:e})}}>
  437. {
  438. station.map(function (item) {
  439. return <Select.Option key={item.value} >{item.key}</Select.Option>
  440. })
  441. }
  442. </Select>
  443. </FormItem>
  444. <FormItem className="half-item"
  445. {...formItemLayout}
  446. label="电子邮箱" >
  447. <Input placeholder="请输入邮箱" style={{width:'200px'}} value={this.state.email}
  448. onChange={(e)=>{this.setState({email:e.target.value})}} />
  449. </FormItem>
  450. <FormItem className="half-item"
  451. {...formItemLayout}
  452. label="上级主管"
  453. >
  454. <AutoComplete
  455. className="certain-category-search"
  456. dropdownClassName="certain-category-search-dropdown"
  457. dropdownMatchSelectWidth={false}
  458. dropdownStyle={{ width: 200 }}
  459. size="large"
  460. style={{ width: '200px' }}
  461. dataSource={options}
  462. placeholder="输入名称"
  463. value={this.state.superior}
  464. onChange={this.httpChange}
  465. filterOption={true}
  466. onBlur={this.blurChange}
  467. onSelect={this.selectAuto}
  468. >
  469. <Input/>
  470. </AutoComplete>
  471. <span className="mandatory">*</span>
  472. </FormItem>
  473. {this.props.userDetaile?
  474. <FormItem className="half-item"
  475. {...formItemLayout}
  476. label="用户编号" >
  477. <span>{this.state.userNo}</span>
  478. </FormItem>
  479. :''}
  480. <div className='clearfix'>
  481. <FormItem className="half-item"
  482. {...formItemLayout}
  483. label="地区" >
  484. <Select
  485. multiple
  486. style={{width:'500px'}}
  487. placeholder="选择地区"
  488. filterOption={(input, option) => { return option.props.children.indexOf(input) >= 0 }}
  489. value={this.state.district}
  490. onChange={(pids) => {
  491. this.state.district = pids;
  492. this.setState({
  493. district: this.state.district
  494. })
  495. }}
  496. >
  497. {this.state.cityOption}
  498. </Select>
  499. </FormItem>
  500. </div>
  501. <div className="clearfix pictures">
  502. <FormItem
  503. labelCol={{ span: 4 }}
  504. wrapperCol={{ span: 18 }}
  505. label="用户头像" >
  506. <PicturesWall
  507. pictureSign="customer_sys_file"
  508. fileList={this.getOrgCodeUrl}
  509. pictureUrl={this.state.orgCodeUrl} />
  510. <p>图片建议:要清晰。</p>
  511. </FormItem>
  512. </div>
  513. </div>
  514. <FormItem wrapperCol={{ span: 12, offset: 4 }}>
  515. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  516. <Button className="set-submit" type="ghost" onClick={this.handleCancel}>取消</Button>
  517. </FormItem>
  518. </Spin>
  519. </Form >
  520. </Modal>
  521. </div>
  522. )
  523. }
  524. }));
  525. export default Newuser;