newUser.jsx 23 KB

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