company.jsx 22 KB

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