company.jsx 22 KB

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