newUser.jsx 28 KB

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