company.jsx 23 KB

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