newUser.jsx 24 KB

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