company.jsx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. import React from 'react';
  2. import { Input, Button, Form, Select, Upload, Icon, Spin, message, InputNumber, Modal, Cascader } from 'antd';
  3. import './person.less';
  4. import ajax from 'jquery/src/ajax/xhr.js'
  5. import $ from 'jquery/src/ajax';
  6. import { areaSelect } from '../../NewDicProvinceList';
  7. import { splitUrl, getBase64, beforeUpload } from '../../tools.js';
  8. import { eduLevelList, zizhiArr, schoolArr ,mechanism} from '../../dataDic.js';
  9. class Avatar extends React.Component {
  10. constructor(props) {
  11. super(props);
  12. this.state = {
  13. imageUrl: '',
  14. propsbool: true,
  15. }
  16. }
  17. handleChange(info) {
  18. if (info.file.status === 'done') {
  19. // Get this url from response in real world.
  20. getBase64(info.file.originFileObj, imageUrl => this.setState({ imageUrl }));
  21. this.props.urlData(info.file.response.data);
  22. }
  23. }
  24. componentWillReceiveProps(nextProps) {
  25. if (nextProps.logoUrl && this.state.propsbool) {
  26. this.state.imageUrl = globalConfig.avatarHost + "/upload" + nextProps.logoUrl;
  27. this.state.propsbool = false;
  28. }
  29. }
  30. render() {
  31. const imageUrl = this.state.imageUrl;
  32. return (
  33. <Upload
  34. className="avatar-uploader"
  35. name="avatar"
  36. showUploadList={false}
  37. action={globalConfig.context + "/api/user/avatar/uploadReplace"}
  38. data={{ 'sign': this.props.name }}
  39. beforeUpload={beforeUpload}
  40. onChange={this.handleChange.bind(this)}
  41. >
  42. {
  43. imageUrl ?
  44. <img src={imageUrl} role="presentation" className="avatar" /> :
  45. <Icon type="plus" className="avatar-uploader-trigger" />
  46. }
  47. </Upload>
  48. );
  49. }
  50. };
  51. class PicturesWall extends React.Component {
  52. constructor(props) {
  53. super(props);
  54. this.state = {
  55. previewVisible: false,
  56. propsbool: true,
  57. previewImage: '',
  58. fileList: [],
  59. }
  60. }
  61. handleCancel() {
  62. this.setState({ previewVisible: false })
  63. }
  64. handlePreview(file) {
  65. this.setState({
  66. previewImage: file.url || file.thumbUrl,
  67. previewVisible: true,
  68. });
  69. }
  70. handleChange(info) {
  71. let fileList = info.fileList;
  72. this.setState({ fileList });
  73. this.props.fileList(fileList);
  74. }
  75. componentWillReceiveProps(nextProps) {
  76. if (nextProps.lifePhotoList && this.state.propsbool) {
  77. this.state.fileList = nextProps.lifePhotoList;
  78. this.state.propsbool = false;
  79. }
  80. }
  81. render() {
  82. const { previewVisible, previewImage, fileList } = this.state;
  83. const uploadButton = (
  84. <div>
  85. <Icon type="plus" />
  86. <div className="ant-upload-text">Upload</div>
  87. </div>
  88. );
  89. return (
  90. <div className="clearfix">
  91. <Upload
  92. action={globalConfig.context + "/api/user/avatar/upload"}
  93. listType="picture-card"
  94. fileList={fileList}
  95. multiple
  96. onPreview={this.handlePreview.bind(this)}
  97. onChange={this.handleChange.bind(this)}
  98. >
  99. {uploadButton}
  100. </Upload>
  101. <Modal maskClosable={false} visible={previewVisible} footer={null} onCancel={this.handleCancel.bind(this)}>
  102. <img alt="" style={{ width: '100%' }} src={previewImage} />
  103. </Modal>
  104. </div>
  105. );
  106. }
  107. };
  108. const PersonFrom = Form.create()(React.createClass({
  109. getData() {
  110. this.props.spinState(true);
  111. $.ajax({
  112. method: "get",
  113. dataType: "json",
  114. url: globalConfig.context + "/api/user/member",
  115. success: function (data) {
  116. if (data.data && data.data.info && data.data.pro) {
  117. let theArr = splitUrl(data.data.info.publicityPictureUrl, ',', globalConfig.avatarHost + '/upload');
  118. let comp=data.data.info.companyType;
  119. let pantt;
  120. switch(comp){
  121. case 0:
  122. pantt='待定';
  123. break;
  124. case 1:
  125. pantt='投资机构';
  126. break;
  127. };
  128. this.setState({
  129. iid: data.data.info.id,
  130. pid: data.data.pro.id,
  131. province: [data.data.info.locationProvince, data.data.info.locationCity, data.data.info.locationArea],
  132. idttType: data.data.info.identityType,
  133. companyt: pantt,
  134. unitName: data.data.info.companyName,
  135. unitNumber: data.data.info.unitSize,
  136. unitIntro: data.data.info.companyIntroduction,
  137. unitFrom: data.data.info.homeUnit,
  138. logoUrl: data.data.info.logoUrl,
  139. publicityPictureUrl: data.data.info.publicityPictureUrl,
  140. companyLifePicList: theArr,
  141. qiyezizhi: data.data.pro.qualification,
  142. turnover: data.data.pro.turnover,
  143. schoolProp: data.data.pro.collegeAttribute,
  144. schoolTime: data.data.pro.collegeEstablishTime,
  145. aca: data.data.pro.academician,
  146. PhDTutor: data.data.pro.doctoralTutor,
  147. MSTutor: data.data.pro.masterTutor,
  148. otherExperts: data.data.pro.otherExpert,
  149. StateKeyLab: data.data.pro.nationalLab,
  150. EduKeyLab: data.data.pro.educationLab,
  151. ComCenter: data.data.pro.enterpriseCenter,
  152. otherCenter: data.data.pro.otherCenter,
  153. resTime: data.data.pro.institutionEstablishTime
  154. });
  155. this.idttTypeChange(data.data.info.identityType);
  156. };
  157. }.bind(this),
  158. }).always(function () {
  159. this.props.spinState(false);
  160. }.bind(this));
  161. },
  162. getInitialState() {
  163. return {
  164. loading: false,
  165. idttType: '企业',
  166. companyt:'待定',
  167. companyDis: 'block',
  168. schoolDis: 'none',
  169. resDis: 'none',
  170. companyLifePicObj: [],
  171. aca: 0,
  172. PhDTutor: 0,
  173. MSTutor: 0,
  174. otherExperts: 0,
  175. StateKeyLab: 0,
  176. EduKeyLab: 0,
  177. ComCenter: 0,
  178. otherCenter: 0
  179. };
  180. },
  181. handleSubmit(e) {
  182. e.preventDefault();
  183. this.props.form.validateFields((err, values) => {
  184. let lifePhotoUrl = this.state.publicityPictureUrl;
  185. if (this.state.companyLifePicObj.length) {
  186. let leftPicArr = [];
  187. this.state.companyLifePicObj.map(function (item) {
  188. if ( item.response && item.response.data && item.response.data.length ){
  189. leftPicArr.push(item.response.data);
  190. }
  191. });
  192. lifePhotoUrl = leftPicArr.join(",");
  193. };
  194. if (!err) {
  195. this.props.spinState(true);
  196. let ktt=values.companyType;
  197. let sktt;
  198. switch(ktt){
  199. case '待定':
  200. sktt='0';
  201. break;
  202. case '投资机构':
  203. sktt='1';
  204. break;
  205. };
  206. $.ajax({
  207. method: "POST",
  208. dataType: "json",
  209. crossDomain: false,
  210. url: globalConfig.context + "/api/user/orgPro",
  211. data: {
  212. "iid": this.state.iid,
  213. "pid": this.state.pid,
  214. "identityType": values.identityType,
  215. "companyType":sktt,
  216. "companyName": values.unitName,
  217. "locationProvince": values.province[0],
  218. "locationCity": values.province[1],
  219. "locationArea": values.province[2],
  220. "unitSize": values.unitNumber,
  221. "companyIntroduction": values.unitIntro,
  222. "homeUnit": values.unitFrom,
  223. "logoUrl": this.state.companyLogoUrl,
  224. "publicityPictureUrl": lifePhotoUrl,
  225. "qualification": values.qiyezizhi,
  226. "turnover": values.turnover,
  227. "collegeAttribute": values.schoolProp,
  228. "collegeEstablishTime": values.schoolTime,
  229. "academician": values.aca,
  230. "doctoralTutor": values.PhDTutor,
  231. "masterTutor": values.MSTutor,
  232. "otherExpert": values.otherExperts,
  233. "nationalLab": values.StateKeyLab,
  234. "educationLab": values.EduKeyLab,
  235. "enterpriseCenter": values.ComCenter,
  236. "otherCenter": values.otherCenter,
  237. "institutionEstablishTime": values.resTime
  238. }
  239. }).done(function (data) {
  240. if (!data.error.length) {
  241. message.success('保存成功!');
  242. this.getData();
  243. } else {
  244. message.warning(data.error[0].message);
  245. }
  246. }.bind(this)).always(function () {
  247. this.props.spinState(false);
  248. }.bind(this));
  249. }
  250. });
  251. },
  252. idttTypeChange(e) {
  253. if (e === '企业') {
  254. this.setState({
  255. companyDis: 'block',
  256. schoolDis: 'none',
  257. companys:'block',
  258. resDis: 'none'
  259. });
  260. } else if (e === '院校') {
  261. this.setState({
  262. companyDis: 'none',
  263. schoolDis: 'block',
  264. companys:'none',
  265. resDis: 'none'
  266. });
  267. } else if (e === '研究机构') {
  268. this.setState({
  269. companyDis: 'none',
  270. schoolDis: 'none',
  271. companys:'none',
  272. resDis: 'block'
  273. });
  274. } else {
  275. this.setState({
  276. companyDis: 'none',
  277. schoolDis: 'none',
  278. companys:'none',
  279. resDis: 'none'
  280. });
  281. }
  282. },
  283. downloadPic(type) {
  284. window.open(globalConfig.context + "/open/downLoadPicture?path=" + type)
  285. },
  286. companyLogoUrl(e) {
  287. this.state.companyLogoUrl = e;
  288. },
  289. companyLifePicUrl(e) {
  290. this.state.companyLifePicObj = e;
  291. },
  292. componentWillMount() {
  293. this.getData();
  294. },
  295. render() {
  296. const FormItem = Form.Item;
  297. const Option = Select.Option;
  298. const { getFieldDecorator } = this.props.form;
  299. const formItemLayout = {
  300. labelCol: { span: 3 },
  301. wrapperCol: { span: 12 },
  302. };
  303. const _me = this;
  304. return (
  305. <Form horizontal onSubmit={this.handleSubmit} className="person-form">
  306. <FormItem
  307. labelCol={{ span: 3 }}
  308. wrapperCol={{ span: 8 }}
  309. label="身份类型"
  310. >
  311. {getFieldDecorator('identityType', {
  312. initialValue: this.state.idttType
  313. })(
  314. <Select className="acc-edu-lvl" onChange={this.idttTypeChange}>
  315. {
  316. eduLevelList.map(function (item) {
  317. return <Option key={item.key} >{item.key}</Option>
  318. })
  319. }
  320. </Select>
  321. )}
  322. </FormItem>
  323. <FormItem style={{ 'display': this.state.companys}}
  324. labelCol={{ span: 3 }}
  325. wrapperCol={{ span: 8 }}
  326. label="企业类型"
  327. >
  328. {getFieldDecorator('companyType', {
  329. initialValue: this.state.companyt
  330. })(
  331. <Select className="acc-edu-lvl">
  332. {
  333. mechanism.map(function (item) {
  334. return <Option key={item.key} >{item.key}</Option>
  335. })
  336. }
  337. </Select>
  338. )}
  339. </FormItem>
  340. <FormItem
  341. {...formItemLayout}
  342. label="单位名称"
  343. >
  344. {getFieldDecorator('unitName', {
  345. initialValue: this.state.unitName
  346. })(
  347. <Input />
  348. )}
  349. </FormItem>
  350. <FormItem
  351. {...formItemLayout}
  352. label="所在地"
  353. >
  354. {getFieldDecorator('province', {
  355. initialValue: this.state.province || []
  356. })(
  357. <Cascader options={areaSelect()} placeholder="请选择所在地" />
  358. )}
  359. </FormItem>
  360. <FormItem
  361. labelCol={{ span: 3 }}
  362. wrapperCol={{ span: 20 }}
  363. label="单位简介"
  364. >
  365. {getFieldDecorator('unitIntro', {
  366. initialValue: this.state.unitIntro
  367. })(
  368. <Input type="textarea"
  369. placeholder="全面介绍自己,让商友更深入了解您,内容长度不超过1000个字。"
  370. rows={6} />
  371. )}
  372. <p>还可输入{
  373. (() => {
  374. if (_me.props.form.getFieldValue('unitIntro') && _me.props.form.getFieldValue('unitIntro').length) {
  375. return 1000 - _me.props.form.getFieldValue('unitIntro').length;
  376. } else {
  377. return 1000;
  378. }
  379. })()
  380. }字/1000</p>
  381. </FormItem>
  382. <FormItem
  383. {...formItemLayout}
  384. label="归属单位"
  385. >
  386. {getFieldDecorator('unitFrom', {
  387. initialValue: this.state.unitFrom
  388. })(
  389. <Input placeholder="非法人单位填写。" />
  390. )}
  391. </FormItem>
  392. <FormItem style={{ 'display': this.state.companyDis }}
  393. labelCol={{ span: 3 }}
  394. wrapperCol={{ span: 8 }}
  395. label="企业资质"
  396. >
  397. {getFieldDecorator('qiyezizhi', {
  398. initialValue: this.state.qiyezizhi
  399. })(
  400. <Select className="acc-edu-lvl">
  401. {
  402. zizhiArr.map(function (item, i) {
  403. return <Option key={i} value={item} >{item}</Option>
  404. })
  405. }
  406. </Select>
  407. )}
  408. </FormItem>
  409. <FormItem style={{ 'display': this.state.schoolDis }}
  410. labelCol={{ span: 3 }}
  411. wrapperCol={{ span: 8 }}
  412. label="院校属性"
  413. >
  414. {getFieldDecorator('schoolProp', {
  415. initialValue: this.state.schoolProp
  416. })(
  417. <Select className="acc-edu-lvl">
  418. {
  419. schoolArr.map(function (item, i) {
  420. return <Option key={i} value={item} >{item}</Option>
  421. })
  422. }
  423. </Select>
  424. )}
  425. </FormItem>
  426. <FormItem style={{ 'display': this.state.schoolDis }}
  427. {...formItemLayout}
  428. label="创办时间"
  429. >
  430. {getFieldDecorator('schoolTime', {
  431. initialValue: this.state.schoolTime || 0
  432. })(
  433. <InputNumber />
  434. )}
  435. <span>年</span>
  436. </FormItem>
  437. <div className="school-props clearfix" style={{ 'display': this.state.schoolDis }}>
  438. <FormItem
  439. labelCol={{ span: 10 }}
  440. wrapperCol={{ span: 12 }}
  441. label="院士"
  442. >
  443. {getFieldDecorator('aca', {
  444. initialValue: this.state.aca || 0
  445. })(
  446. <InputNumber />
  447. )}
  448. <span>人</span>
  449. </FormItem>
  450. <FormItem
  451. labelCol={{ span: 10 }}
  452. wrapperCol={{ span: 12 }}
  453. label="博士生导师"
  454. >
  455. {getFieldDecorator('PhDTutor', {
  456. initialValue: this.state.PhDTutor || 0
  457. })(
  458. <InputNumber />
  459. )}
  460. <span>人</span>
  461. </FormItem>
  462. <FormItem
  463. labelCol={{ span: 10 }}
  464. wrapperCol={{ span: 12 }}
  465. label="硕士生导师"
  466. >
  467. {getFieldDecorator('MSTutor', {
  468. initialValue: this.state.MSTutor || 0
  469. })(
  470. <InputNumber />
  471. )}
  472. <span>人</span>
  473. </FormItem>
  474. <FormItem
  475. labelCol={{ span: 10 }}
  476. wrapperCol={{ span: 12 }}
  477. label="其他专家"
  478. >
  479. {getFieldDecorator('otherExperts', {
  480. initialValue: this.state.otherExperts || 0
  481. })(
  482. <InputNumber />
  483. )}
  484. <span>人</span>
  485. </FormItem>
  486. <FormItem
  487. labelCol={{ span: 10 }}
  488. wrapperCol={{ span: 12 }}
  489. label="国家级重点实验室"
  490. >
  491. {getFieldDecorator('StateKeyLab', {
  492. initialValue: this.state.StateKeyLab || 0
  493. })(
  494. <InputNumber />
  495. )}
  496. <span>所</span>
  497. </FormItem>
  498. <FormItem
  499. labelCol={{ span: 10 }}
  500. wrapperCol={{ span: 12 }}
  501. label="教育部重点实验室"
  502. >
  503. {getFieldDecorator('EduKeyLab', {
  504. initialValue: this.state.EduKeyLab || 0
  505. })(
  506. <InputNumber />
  507. )}
  508. <span>所</span>
  509. </FormItem>
  510. <FormItem
  511. labelCol={{ span: 10 }}
  512. wrapperCol={{ span: 12 }}
  513. label="企业共建研究中心"
  514. >
  515. {getFieldDecorator('ComCenter', {
  516. initialValue: this.state.ComCenter || 0
  517. })(
  518. <InputNumber />
  519. )}
  520. <span>所</span>
  521. </FormItem>
  522. <FormItem
  523. labelCol={{ span: 10 }}
  524. wrapperCol={{ span: 12 }}
  525. label="其他研究中心"
  526. >
  527. {getFieldDecorator('otherCenter', {
  528. initialValue: this.state.otherCenter || 0
  529. })(
  530. <InputNumber />
  531. )}
  532. <span>所</span>
  533. </FormItem>
  534. </div>
  535. <FormItem style={{ 'display': this.state.resDis }}
  536. {...formItemLayout}
  537. label="创办时间"
  538. >
  539. {getFieldDecorator('resTime', {
  540. initialValue: this.state.resTime || 0
  541. })(
  542. <InputNumber />
  543. )}
  544. <span>年</span>
  545. </FormItem>
  546. <FormItem
  547. {...formItemLayout}
  548. label="LOGO"
  549. labelCol={{ span: 3 }}
  550. wrapperCol={{ span: 20 }}
  551. >
  552. {getFieldDecorator('avatar')(
  553. <Avatar name="companyLogo" urlData={this.companyLogoUrl} logoUrl={this.state.logoUrl} />
  554. )}
  555. </FormItem>
  556. <div className="set-explain">
  557. <p>上传的照片图片格式应为jpg格式,大小在2M以内</p>
  558. </div>
  559. <FormItem
  560. labelCol={{ span: 3 }}
  561. wrapperCol={{ span: 21 }}
  562. label="宣传图片"
  563. >
  564. {getFieldDecorator('companyLifePic')(
  565. <PicturesWall fileList={this.companyLifePicUrl} lifePhotoList={this.state.companyLifePicList} />
  566. )}
  567. </FormItem>
  568. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  569. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  570. </FormItem>
  571. </Form >
  572. );
  573. },
  574. }));
  575. const Person = React.createClass({
  576. getInitialState() {
  577. return {
  578. loading: false
  579. };
  580. },
  581. spinChange(e) {
  582. this.setState({
  583. loading: e
  584. });
  585. },
  586. render() {
  587. return (
  588. <Spin spinning={this.state.loading} className='spin-box'>
  589. <div className="set-person">
  590. <div className="acc-detail">
  591. <p className="acc-title">单位资料</p>
  592. <PersonFrom spinState={this.spinChange} />
  593. </div>
  594. </div>
  595. </Spin>
  596. )
  597. }
  598. });
  599. export default Person;