newUser.jsx 21 KB

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