company.jsx 22 KB

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