newUser.jsx 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  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: Number(thisdata.status),
  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
  408. placeholder="用户状态"
  409. value={this.state.status}
  410. style={{ width: '200px' }}
  411. onChange={(e) => { this.setState({ status: e }) }}
  412. >
  413. <Select.Option value={0} >正常</Select.Option>
  414. <Select.Option value={1} >锁定</Select.Option>
  415. </Select>
  416. <span className="mandatory">*</span>
  417. </FormItem> : ''}
  418. <FormItem className="half-item"
  419. {...formItemLayout}
  420. label="用户姓名" >
  421. <Input placeholder="请输入用户姓名" style={{ width: '200px' }} value={this.state.name}
  422. onChange={(e) => { this.setState({ name: e.target.value }) }} required="required" />
  423. <span className="mandatory">*</span>
  424. </FormItem>
  425. <FormItem className="half-item"
  426. {...formItemLayout}
  427. label="联系方式" >
  428. <Input placeholder="请输入手机号" style={{ width: '200px' }} value={this.state.contactMobile}
  429. onChange={(e) => { this.setState({ contactMobile: e.target.value }) }} />
  430. </FormItem>
  431. {/*<FormItem className="half-item"
  432. {...formItemLayout}
  433. label="入职时间" >
  434. <DatePicker
  435. style={{marginTop:'0',width:'200px',height:'27px'}}
  436. showTime
  437. format="YYYY-MM-DD"
  438. placeholder="选择入职时间"
  439. value={this.state.entryTime}
  440. onChange={(e,time)=>{this.selTime(e,time)}}
  441. />
  442. </FormItem>*/}
  443. {window.adminData.isSuperAdmin ? <FormItem className="half-item"
  444. {...formItemLayout}
  445. label="组织部门" >
  446. <Select placeholder="选择组织部门"
  447. style={{ width: 200 }}
  448. value={this.state.departmentId}
  449. onChange={(e) => { this.setState({ departmentId: e }) }}>
  450. {
  451. departmentArr.map(function (item) {
  452. return <Select.Option key={item.id} >{item.name}</Select.Option>
  453. })
  454. }
  455. </Select>
  456. <span className="mandatory">*</span>
  457. </FormItem> : ''}
  458. <FormItem className="half-item"
  459. {...formItemLayout}
  460. label="职务"
  461. >
  462. <Select placeholder="选择职务" style={{ width: '200px' }} value={this.state.duty} onChange={(e) => { this.setState({ duty: e }) }}>
  463. {
  464. post.map(function (item) {
  465. return <Select.Option key={item.value} >{item.key}</Select.Option>
  466. })
  467. }
  468. </Select>
  469. </FormItem>
  470. <FormItem className="half-item"
  471. {...formItemLayout}
  472. label="岗位"
  473. >
  474. <Select placeholder="选择岗位" style={{ width: '200px' }} value={this.state.position} onChange={(e) => { this.setState({ position: e }) }}>
  475. {
  476. station.map(function (item) {
  477. return <Select.Option key={item.value} >{item.key}</Select.Option>
  478. })
  479. }
  480. </Select>
  481. </FormItem>
  482. <FormItem className="half-item"
  483. {...formItemLayout}
  484. label="电子邮箱" >
  485. <Input placeholder="请输入邮箱" style={{ width: '200px' }} value={this.state.email}
  486. onChange={(e) => { this.setState({ email: e.target.value }) }} />
  487. </FormItem>
  488. <FormItem className="half-item"
  489. {...formItemLayout}
  490. label="上级主管"
  491. >
  492. <AutoComplete
  493. className="certain-category-search"
  494. dropdownClassName="certain-category-search-dropdown"
  495. dropdownMatchSelectWidth={false}
  496. size="large"
  497. style={{ width: '200px' }}
  498. dataSource={options}
  499. placeholder="输入名称"
  500. value={this.state.superior}
  501. onChange={this.httpChange}
  502. filterOption={true}
  503. onSelect={this.selectAuto}
  504. >
  505. <Input />
  506. </AutoComplete>
  507. <span className="mandatory">*</span>
  508. </FormItem>
  509. <FormItem className="half-item"
  510. {...formItemLayout}
  511. label="公出审核"
  512. >
  513. <StaffSearch
  514. valueName={this.state.reviewerName}
  515. placeholder="输入名称"
  516. onBlurChange={(obj) => {
  517. this.setState({
  518. reviewer: obj.value
  519. })
  520. }}
  521. />
  522. <span className="mandatory">*</span>
  523. </FormItem>
  524. {this.props.userDetaile ?
  525. <FormItem className="half-item"
  526. {...formItemLayout}
  527. label="用户编号" >
  528. <span>{this.state.userNo}</span>
  529. </FormItem>
  530. : ''}
  531. <div className='clearfix'>
  532. <FormItem className="half-item"
  533. {...formItemLayout}
  534. label="地区" >
  535. <Select
  536. multiple
  537. style={{ width: '500px' }}
  538. placeholder="选择地区"
  539. filterOption={(input, option) => { return option.props.children.indexOf(input) >= 0 }}
  540. value={this.state.district}
  541. onChange={(pids) => {
  542. this.state.district = pids;
  543. this.setState({
  544. district: this.state.district
  545. })
  546. }}
  547. >
  548. {this.state.cityOption}
  549. </Select>
  550. </FormItem>
  551. </div>
  552. <div className="clearfix pictures">
  553. <FormItem
  554. labelCol={{ span: 4 }}
  555. wrapperCol={{ span: 18 }}
  556. label="用户头像" >
  557. <PicturesWall
  558. domId={'newUser1'}
  559. pictureSign="customer_sys_file"
  560. fileList={this.getOrgCodeUrl}
  561. pictureUrl={this.state.orgCodeUrl} />
  562. <p>图片建议:要清晰。</p>
  563. </FormItem>
  564. </div>
  565. </div>
  566. <FormItem wrapperCol={{ span: 12, offset: 4 }}>
  567. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  568. <Button className="set-submit" type="ghost" onClick={this.handleCancel}>取消</Button>
  569. </FormItem>
  570. </Spin>
  571. </Form >
  572. </Modal>
  573. </div>
  574. )
  575. }
  576. }));
  577. export default Newuser;