personal.jsx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. /*
  2. @author:李霆
  3. @update:2018/05/29
  4. @descript:复制粘贴,拿起来就是干!!
  5. */
  6. import React from 'react';
  7. import {
  8. Radio,
  9. Icon,
  10. Button,
  11. Cascader,
  12. Input,
  13. Select,
  14. Spin,
  15. message,
  16. DatePicker,
  17. Modal,
  18. Upload,
  19. Form,
  20. Row,
  21. Col,
  22. } from 'antd';
  23. import $ from 'jquery/src/ajax';
  24. import moment from 'moment';
  25. import './unit.less';
  26. import { areaSelect } from '@/NewDicProvinceList';
  27. import {
  28. socialAttribute,
  29. industry,
  30. } from '@/dataDic.js';
  31. import {
  32. splitUrl,
  33. } from '@/tools.js';
  34. message.config({
  35. top: 200,
  36. });
  37. const FormItem = Form.Item;
  38. const monthFormat = 'YYYY/MM';
  39. //图片组件
  40. const PicturesWall = React.createClass({
  41. getInitialState() {
  42. return {
  43. previewVisible: false,
  44. previewImage: '',
  45. fileList: []
  46. };
  47. },
  48. handleCancel() {
  49. this.setState({
  50. previewVisible: false
  51. });
  52. },
  53. handlePreview(file) {
  54. this.setState({
  55. previewImage: file.url || file.thumbUrl,
  56. previewVisible: true
  57. });
  58. },
  59. handleChange(info) {
  60. let fileList = info.fileList;
  61. this.setState({
  62. fileList
  63. });
  64. this.props.fileList(fileList);
  65. },
  66. componentWillReceiveProps(nextProps) {
  67. this.state.fileList = nextProps.pictureUrl;
  68. },
  69. render() {
  70. const { previewVisible, previewImage, fileList } = this.state;
  71. const uploadButton = (
  72. <div>
  73. <Icon type="plus" />
  74. <div className="ant-upload-text">点击上传</div>
  75. </div>
  76. );
  77. return (
  78. <div style={{ display: 'inline-block' }}>
  79. <Upload
  80. action={globalConfig.context + '/api/user/uploadPicture'}
  81. data={{ sign: 'user_picture' }}
  82. listType="picture-card"
  83. fileList={fileList}
  84. onPreview={this.handlePreview}
  85. onChange={this.handleChange}
  86. >
  87. {fileList.length >= 1 ? null : uploadButton}
  88. </Upload>
  89. <Modal maskClosable={false} visible={previewVisible} footer={null} onCancel={this.handleCancel}>
  90. <img alt="example" style={{ width: '100%' }} src={previewImage} />
  91. </Modal>
  92. </div>
  93. );
  94. }
  95. });
  96. const Personal = React.createClass({
  97. getInitialState() {
  98. return {
  99. loading: false,
  100. orgCodeUrl: [],
  101. companyLogoUrl: [],
  102. headPortraitUrl: [],
  103. positiveIdUrl: [],
  104. oppositeIdUrl: []
  105. };
  106. },
  107. loadInformation(record) {
  108. this.setState({
  109. loading: true
  110. });
  111. $.ajax({
  112. method: 'get',
  113. dataType: 'json',
  114. crossDomain: false,
  115. url: globalConfig.context + '/api/user/getUserDetail',
  116. success: function(data) {
  117. let thisData = data.data;
  118. if (!thisData) {
  119. if (data.error && data.error.length) {
  120. message.warning(data.error[0].message);
  121. }
  122. thisData = {};
  123. }
  124. let ProvinceCityArr = [];
  125. let ProvinceS = thisData.province; //getprovince
  126. let citys = thisData.city;
  127. let Areas = thisData.area;
  128. ProvinceCityArr.push(ProvinceS, citys, Areas);
  129. let month = thisData.dateOfBirthYear
  130. ? thisData.dateOfBirthYear + '/' + thisData.dateOfBirthMonth
  131. : undefined;
  132. this.setState({
  133. InformationId: thisData.id,
  134. InformationUid: thisData.uid,
  135. identifyName: thisData.identifyName,
  136. headPortraitUrl: thisData.headPortraitUrl
  137. ? splitUrl(thisData.headPortraitUrl, ',', globalConfig.avatarHost + '/upload')
  138. : [],
  139. positiveIdUrl: thisData.positiveIdUrl
  140. ? splitUrl(thisData.positiveIdUrl, ',', globalConfig.avatarHost + '/upload')
  141. : [],
  142. oppositeIdUrl: thisData.oppositeIdUrl
  143. ? splitUrl(thisData.oppositeIdUrl, ',', globalConfig.avatarHost + '/upload')
  144. : [],
  145. dataInformation: thisData,
  146. idNumber: thisData.idNumber,
  147. mobile:thisData.mobile,
  148. ProvinceCity: ProvinceCityArr[0] != null ? ProvinceCityArr : undefined,
  149. industry: thisData.industry ? String(thisData.industry) : undefined,
  150. societyTag: thisData.societyTag || undefined,
  151. sex: thisData.sex,
  152. yearMonth: month,
  153. postalAddress: thisData.postalAddress,
  154. fixedTel: thisData.fixedTel,
  155. email: thisData.email,
  156. qq: thisData.qq,
  157. mobile:thisData.mobile,
  158. introduction: thisData.introduction,
  159. type:thisData.type,
  160. authentication:thisData.authentication
  161. });
  162. }.bind(this)
  163. }).always(
  164. function() {
  165. this.setState({
  166. loading: false
  167. });
  168. }.bind(this)
  169. );
  170. },
  171. //图片
  172. getOrgCodeUrl(e) {
  173. this.setState({
  174. orgCodeUrl: e
  175. });
  176. },
  177. getCompanyLogoUrl(e) {
  178. this.setState({
  179. companyLogoUrl: e
  180. });
  181. },
  182. //基本信息提交
  183. newSubmit(e) {
  184. this.state.data = [];
  185. this.setState({
  186. selectedRowKeys: []
  187. });
  188. let theorgCodeUrl = [];
  189. if (this.state.headPortraitUrl.length) {
  190. let picArr = [];
  191. this.state.headPortraitUrl.map(function(item) {
  192. if (item.response && item.response.data && item.response.data.length) {
  193. picArr.push(item.response.data);
  194. }
  195. });
  196. theorgCodeUrl = picArr.join(',');
  197. }
  198. let thecompanyLogoUrl = [];
  199. if (this.state.positiveIdUrl.length) {
  200. let picArr = [];
  201. this.state.positiveIdUrl.map(function(item) {
  202. if (item.response && item.response.data && item.response.data.length) {
  203. picArr.push(item.response.data);
  204. }
  205. });
  206. thecompanyLogoUrl = picArr.join(',');
  207. }
  208. let thecompanyLogoUrls = [];
  209. if (this.state.oppositeIdUrl.length) {
  210. let picArr = [];
  211. this.state.oppositeIdUrl.map(function(item) {
  212. if (item.response && item.response.data && item.response.data.length) {
  213. picArr.push(item.response.data);
  214. }
  215. });
  216. thecompanyLogoUrls = picArr.join(',');
  217. }
  218. let years = [];
  219. let yearMonth = this.state.yearMonth != undefined ? new Date(this.state.yearMonth).toLocaleDateString() : '';
  220. years = yearMonth.split('/');
  221. this.setState({
  222. loading: true
  223. });
  224. $.ajax({
  225. method: 'post',
  226. dataType: 'json',
  227. url: globalConfig.context + '/api/user/updateUserDetail',
  228. data: {
  229. id: this.state.InformationId,
  230. uid: this.state.InformationUid,
  231. societyTag: this.state.societyTag,
  232. identifyName: this.state.identifyName,
  233. industry: this.state.industry,
  234. dateOfBirthYear: years[0], //出生年
  235. dateOfBirthMonth: years[1], //出生月
  236. province: this.state.ProvinceCity[0], //省-
  237. city: this.state.ProvinceCity[1], //市
  238. area: this.state.ProvinceCity[2], //区
  239. sex: this.state.sex,
  240. mobile:this.state.mobile,
  241. fixedTel: this.state.fixedTel,
  242. qq: this.state.qq,
  243. idNumber: this.state.idNumber,
  244. email: this.state.email,
  245. postalAddress: this.state.postalAddress,
  246. introduction: this.state.introduction,
  247. positiveIdUrl: thecompanyLogoUrl.length != 0 ? thecompanyLogoUrl : '',
  248. oppositeIdUrl: thecompanyLogoUrls.length != 0 ? thecompanyLogoUrls : '',
  249. headPortraitUrl: theorgCodeUrl.length != 0 ? theorgCodeUrl : '',
  250. authentication:this.state.authentication,
  251. type:this.state.type
  252. }
  253. }).done(
  254. function(data) {
  255. this.setState({
  256. loading: false
  257. });
  258. if (!data.error.length) {
  259. if(this.state.type!='0'){
  260. message.success('个人认证成功,1s后回到首页.')
  261. setTimeout(()=>{
  262. window.location.href = globalConfig.context + "/user/account/index.html";
  263. },1000)
  264. }else{
  265. message.success('保存成功!');
  266. this.loadInformation();
  267. }
  268. } else {
  269. message.warning(data.error[0].message);
  270. }
  271. }.bind(this)
  272. );
  273. },
  274. subFun(){
  275. if(this.state.type=='0'||this.state.type=='1'){
  276. if(!this.state.identifyName){
  277. message.warning("请填写姓名!")
  278. return;
  279. }
  280. if (!this.state.industry) {
  281. message.warning('请选择行业!');
  282. return false;
  283. }
  284. if (!this.state.societyTag) {
  285. message.warning('请选择社会性质!');
  286. return false;
  287. }
  288. if (!this.state.ProvinceCity||!this.state.ProvinceCity.length) {
  289. message.warning('请选择地区!');
  290. return false;
  291. }
  292. if(!this.state.mobile){
  293. message.warning("请填写手机号码!")
  294. return;
  295. }
  296. this.newSubmit()
  297. }else{
  298. if(!this.state.identifyName){
  299. message.warning("请填写姓名!")
  300. return;
  301. }
  302. if (!this.state.industry) {
  303. message.warning('请选择行业!');
  304. return false;
  305. }
  306. if (!this.state.societyTag) {
  307. message.warning('请选择社会性质!');
  308. return false;
  309. }
  310. if (!this.state.ProvinceCity||!this.state.ProvinceCity.length) {
  311. message.warning('请选择地区!');
  312. return false;
  313. }
  314. if(!this.state.mobile){
  315. message.warning("请填写手机号码!")
  316. return;
  317. }
  318. this.setState({
  319. visible:true
  320. })
  321. }
  322. },
  323. handleOk(){
  324. this.newSubmit();
  325. this.setState({
  326. visible:false
  327. })
  328. },
  329. handleCancel(){
  330. this.setState({
  331. visible:false
  332. })
  333. },
  334. getHeadPortraitUrl(e) {
  335. this.setState({ headPortraitUrl: e });
  336. },
  337. getPositiveIdUrl(e) {
  338. this.setState({ positiveIdUrl: e });
  339. },
  340. getOppositeIdUrl(e) {
  341. this.setState({ oppositeIdUrl: e });
  342. },
  343. componentWillMount() {
  344. this.loadInformation();
  345. },
  346. componentWillReceiveProps(nextProps) {},
  347. render() {
  348. const { RangePicker, MonthPicker } = DatePicker;
  349. const formItemLayout = {
  350. labelCol: {
  351. span: 6
  352. },
  353. wrapperCol: {
  354. span: 14
  355. }
  356. };
  357. return (
  358. <div className="unit-wrap">
  359. <Form layout="horizontal" onSubmit={this.newSubmit} id="demand-form" style={{width:'80%'}}>
  360. <Spin spinning={this.state.loading}>
  361. <Row style={{ marginBottom: 20 }}>
  362. <Col offset={2} span={4}>
  363. <h4 style={{fontSize:20}}>个人资料</h4>
  364. </Col>
  365. </Row>
  366. <div className="clearfix">
  367. <FormItem className="half-item" {...formItemLayout} label={<span><span className="color-red"> * </span>姓名</span>}>
  368. <Input
  369. maxLength={128}
  370. placeholder="输入姓名"
  371. value={this.state.identifyName}
  372. onChange={(e) => {
  373. this.setState({ identifyName: e.target.value });
  374. }}
  375. />
  376. </FormItem>
  377. <FormItem className="half-item" {...formItemLayout} label="性别">
  378. <Radio.Group
  379. value={this.state.sex}
  380. onChange={(e) => {
  381. this.setState({ sex: e.target.value });
  382. }}
  383. >
  384. <Radio value={'男'}>男</Radio>
  385. <Radio value={'女'}>女</Radio>
  386. </Radio.Group>
  387. </FormItem>
  388. </div>
  389. <div className="clearfix">
  390. <FormItem className="half-item" {...formItemLayout} label={<span><span className="color-red"> * </span>行业</span>}>
  391. <Select
  392. placeholder="选择行业"
  393. value={this.state.industry}
  394. onChange={(e) => {
  395. this.setState({ industry: e });
  396. }}
  397. >
  398. {industry.map(function(item) {
  399. return <Select.Option key={item.value}>{item.key}</Select.Option>;
  400. })}
  401. </Select>
  402. </FormItem>
  403. <FormItem className="half-item" {...formItemLayout} label={<span><span className="color-red"> * </span>社会属性</span>}>
  404. <Select
  405. placeholder="客户社会属性"
  406. value={this.state.societyTag}
  407. onChange={(e) => {
  408. this.setState({ societyTag: e });
  409. }}
  410. >
  411. {socialAttribute.map(function(item) {
  412. return <Select.Option key={item.value}>{item.key}</Select.Option>;
  413. })}
  414. </Select>
  415. </FormItem>
  416. <FormItem className="half-item" {...formItemLayout} label="出生日期">
  417. {!this.state.yearMonth ? (
  418. <MonthPicker
  419. placeholder="选择出生年月"
  420. value={this.state.yearMonth}
  421. onChange={(time) => {
  422. this.setState({ yearMonth: time });
  423. }}
  424. />
  425. ) : (
  426. <MonthPicker
  427. value={moment(this.state.yearMonth, monthFormat)}
  428. format={monthFormat}
  429. onChange={(time) => {
  430. this.setState({ yearMonth: time });
  431. }}
  432. />
  433. )}
  434. </FormItem>
  435. <FormItem className="half-item" {...formItemLayout} label="身份证号码">
  436. <Input
  437. maxLength={20}
  438. placeholder="身份证号码"
  439. value={this.state.idNumber}
  440. onChange={(e) => {
  441. this.setState({ idNumber: e.target.value });
  442. }}
  443. />
  444. </FormItem>
  445. </div>
  446. <div className="clearfix">
  447. <FormItem className="half-item" {...formItemLayout} label={<span><span className="color-red"> * </span>省-市-区</span>}>
  448. <Cascader
  449. options={areaSelect()}
  450. value={this.state.ProvinceCity}
  451. placeholder="选择城市"
  452. onChange={(e, pre) => {
  453. this.setState({ ProvinceCity: e });
  454. }}
  455. />
  456. </FormItem>
  457. <FormItem className="half-item" {...formItemLayout} label="通信地址">
  458. <Input
  459. maxLength={255}
  460. placeholder="客户通信地址"
  461. value={this.state.postalAddress}
  462. onChange={(e, pre) => {
  463. this.setState({ postalAddress: e.target.value });
  464. }}
  465. />
  466. </FormItem>
  467. <FormItem className="half-item" {...formItemLayout} label={<span><span className="color-red"> * </span>手机号码</span>}>
  468. <Input
  469. maxLength={16}
  470. placeholder="手机号码"
  471. value={this.state.mobile}
  472. onChange={(e) => {
  473. this.setState({ mobile: e.target.value });
  474. }}
  475. />
  476. </FormItem>
  477. <FormItem className="half-item" {...formItemLayout} label="固定电话">
  478. <Input
  479. maxLength={13}
  480. placeholder="客户固定电话"
  481. value={this.state.fixedTel}
  482. onChange={(e) => {
  483. this.setState({ fixedTel: e.target.value });
  484. }}
  485. />
  486. </FormItem>
  487. <FormItem className="half-item" {...formItemLayout} label="QQ">
  488. <Input
  489. maxLength={16}
  490. placeholder="QQ"
  491. value={this.state.qq}
  492. onChange={(e) => {
  493. this.setState({ qq: e.target.value });
  494. }}
  495. />
  496. </FormItem>
  497. <FormItem className="half-item" {...formItemLayout} label="电子邮箱">
  498. <Input
  499. maxLength={128}
  500. placeholder="客户电子邮箱"
  501. value={this.state.email}
  502. onChange={(e) => {
  503. this.setState({ email: e.target.value });
  504. }}
  505. />
  506. </FormItem>
  507. </div>
  508. <div className="clearfix">
  509. <FormItem labelCol={{ span: 3 }} wrapperCol={{ span: 18 }} label="个人简介">
  510. <Input
  511. maxLength={512}
  512. type="textarea"
  513. rows={4}
  514. value={this.state.introduction}
  515. onChange={(e, pre) => {
  516. this.setState({ introduction: e.target.value });
  517. }}
  518. />
  519. </FormItem>
  520. </div>
  521. <div className="clearfix pictures">
  522. <FormItem
  523. className="picWidth"
  524. labelCol={{ span: 10 }}
  525. wrapperCol={{ span: 10 }}
  526. label="身份证正面"
  527. >
  528. <PicturesWall
  529. fileList={this.getPositiveIdUrl}
  530. pictureUrl={this.state.positiveIdUrl}
  531. />
  532. <p>建议:图片要清晰。</p>
  533. </FormItem>
  534. <FormItem
  535. className="picWidth"
  536. labelCol={{ span: 10 }}
  537. wrapperCol={{ span: 10 }}
  538. label="身份证反面"
  539. >
  540. <PicturesWall
  541. fileList={this.getOppositeIdUrl}
  542. pictureUrl={this.state.oppositeIdUrl}
  543. />
  544. <p>建议:图片要清晰。</p>
  545. </FormItem>
  546. <FormItem
  547. className="picWidth"
  548. labelCol={{ span: 10 }}
  549. wrapperCol={{ span: 10 }}
  550. label="客户照片"
  551. >
  552. <PicturesWall
  553. fileList={this.getHeadPortraitUrl}
  554. pictureUrl={this.state.headPortraitUrl}
  555. />
  556. <p>建议:图片要清晰。</p>
  557. </FormItem>
  558. </div>
  559. <Row style={{ marginBottom: 20 }}>
  560. <Col offset={3} span={4}>
  561. <Button size="large" className="set-submit" type="primary" onClick={this.subFun}>
  562. 保存
  563. </Button>
  564. </Col>
  565. </Row>
  566. </Spin>
  567. </Form>
  568. <Modal
  569. visible={this.state.visible}
  570. onOk={this.handleOk}
  571. onCancel={this.handleCancel}
  572. >
  573. <p>是否申请个人用户认证?</p>
  574. </Modal>
  575. </div>
  576. );
  577. }
  578. });
  579. export default Personal;