newUser.jsx 29 KB

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