company.jsx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  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 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. } else {
  222. message.warning(data.error[0].message);
  223. }
  224. }.bind(this)).always(function () {
  225. this.props.spinState(false);
  226. }.bind(this));
  227. }
  228. });
  229. },
  230. idttTypeChange(e) {
  231. if (e === '企业') {
  232. this.props.form.setFieldsValue({ 'indentityType': e });
  233. this.setState({
  234. companyDis: 'block',
  235. schoolDis: 'none',
  236. resDis: 'none'
  237. });
  238. } else if (e === '院校') {
  239. this.props.form.setFieldsValue({ 'indentityType': e });
  240. this.setState({
  241. companyDis: 'none',
  242. schoolDis: 'block',
  243. resDis: 'none'
  244. });
  245. } else if (e === '研究机构') {
  246. this.props.form.setFieldsValue({ 'indentityType': e });
  247. this.setState({
  248. companyDis: 'none',
  249. schoolDis: 'none',
  250. resDis: 'block'
  251. });
  252. } else {
  253. this.props.form.setFieldsValue({ 'indentityType': e });
  254. this.setState({
  255. companyDis: 'none',
  256. schoolDis: 'none',
  257. resDis: 'none'
  258. });
  259. }
  260. },
  261. downloadPic(type) {
  262. window.open(globalConfig.context + "/open/downLoadPicture?path=" + type)
  263. },
  264. companyLogoUrl(e) {
  265. this.state.companyLogoUrl = e;
  266. },
  267. companyLifePicUrl(e) {
  268. this.state.companyLifePicObj = e;
  269. },
  270. componentDidMount() {
  271. addressInit('cmbProvince', 'cmbCity', 'cmbArea');
  272. this.getData();
  273. },
  274. render() {
  275. const FormItem = Form.Item;
  276. const Option = Select.Option;
  277. const { getFieldDecorator } = this.props.form;
  278. const formItemLayout = {
  279. labelCol: { span: 3 },
  280. wrapperCol: { span: 12 },
  281. };
  282. const _me = this;
  283. return (
  284. <Form horizontal onSubmit={this.handleSubmit} className="person-form">
  285. <FormItem
  286. labelCol={{ span: 3 }}
  287. wrapperCol={{ span: 8 }}
  288. label="身份类型"
  289. >
  290. {getFieldDecorator('identityType', {
  291. initialValue: this.state.idttType
  292. })(
  293. <Select className="acc-edu-lvl" onChange={this.idttTypeChange}>
  294. {
  295. eduLevelList.map(function (item, i) {
  296. return <Option key={i} value={item.value} >{item.key}</Option>
  297. })
  298. }
  299. </Select>
  300. )}
  301. </FormItem>
  302. <FormItem
  303. {...formItemLayout}
  304. label="单位名称"
  305. >
  306. {getFieldDecorator('unitName', {
  307. initialValue: this.state.unitName
  308. })(
  309. <Input />
  310. )}
  311. </FormItem>
  312. <FormItem
  313. {...formItemLayout}
  314. label="所在地"
  315. >
  316. {getFieldDecorator('province')(
  317. <div>
  318. <select id="cmbProvince" name="cmbProvince"></select>
  319. <select id="cmbCity" name="cmbCity"></select>
  320. <select id="cmbArea" name="cmbArea"></select>
  321. </div>
  322. )}
  323. </FormItem>
  324. <FormItem
  325. labelCol={{ span: 3 }}
  326. wrapperCol={{ span: 20 }}
  327. label="单位简介"
  328. >
  329. {getFieldDecorator('unitIntro', {
  330. initialValue: this.state.unitIntro
  331. })(
  332. <Input type="textarea"
  333. placeholder="全面介绍自己,让商友更深入了解您,内容长度不超过1000个字。"
  334. rows={6} />
  335. )}
  336. <p>还可输入{
  337. (() => {
  338. if (_me.props.form.getFieldValue('unitIntro') && _me.props.form.getFieldValue('unitIntro').length) {
  339. return 1000 - _me.props.form.getFieldValue('unitIntro').length;
  340. } else {
  341. return 1000;
  342. }
  343. })()
  344. }字/1000</p>
  345. </FormItem>
  346. <FormItem
  347. {...formItemLayout}
  348. label="归属单位"
  349. >
  350. {getFieldDecorator('unitFrom', {
  351. initialValue: this.state.unitFrom
  352. })(
  353. <Input placeholder="非法人单位填写。" />
  354. )}
  355. </FormItem>
  356. <FormItem style={{ 'display': this.state.companyDis }}
  357. labelCol={{ span: 3 }}
  358. wrapperCol={{ span: 8 }}
  359. label="企业资质"
  360. >
  361. {getFieldDecorator('qiyezizhi', {
  362. initialValue: this.state.qiyezizhi
  363. })(
  364. <Select className="acc-edu-lvl">
  365. {
  366. zizhiArr.map(function (item, i) {
  367. return <Option key={i} value={item} >{item}</Option>
  368. })
  369. }
  370. </Select>
  371. )}
  372. </FormItem>
  373. <FormItem style={{ 'display': this.state.schoolDis }}
  374. labelCol={{ span: 3 }}
  375. wrapperCol={{ span: 8 }}
  376. label="院校属性"
  377. >
  378. {getFieldDecorator('schoolProp', {
  379. initialValue: this.state.schoolProp
  380. })(
  381. <Select className="acc-edu-lvl">
  382. {
  383. schoolArr.map(function (item, i) {
  384. return <Option key={i} value={item} >{item}</Option>
  385. })
  386. }
  387. </Select>
  388. )}
  389. </FormItem>
  390. <FormItem style={{ 'display': this.state.schoolDis }}
  391. {...formItemLayout}
  392. label="创办时间"
  393. >
  394. {getFieldDecorator('schoolTime', {
  395. initialValue: this.state.schoolTime || 0
  396. })(
  397. <InputNumber />
  398. )}
  399. <span>年</span>
  400. </FormItem>
  401. <div className="school-props clearfix" style={{ 'display': this.state.schoolDis }}>
  402. <FormItem
  403. labelCol={{ span: 10 }}
  404. wrapperCol={{ span: 12 }}
  405. label="院士"
  406. >
  407. {getFieldDecorator('aca', {
  408. initialValue: this.state.aca || 0
  409. })(
  410. <InputNumber />
  411. )}
  412. <span>人</span>
  413. </FormItem>
  414. <FormItem
  415. labelCol={{ span: 10 }}
  416. wrapperCol={{ span: 12 }}
  417. label="博士生导师"
  418. >
  419. {getFieldDecorator('PhDTutor', {
  420. initialValue: this.state.PhDTutor || 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('MSTutor', {
  432. initialValue: this.state.MSTutor || 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('otherExperts', {
  444. initialValue: this.state.otherExperts || 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('StateKeyLab', {
  456. initialValue: this.state.StateKeyLab || 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('EduKeyLab', {
  468. initialValue: this.state.EduKeyLab || 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('ComCenter', {
  480. initialValue: this.state.ComCenter || 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('otherCenter', {
  492. initialValue: this.state.otherCenter || 0
  493. })(
  494. <InputNumber />
  495. )}
  496. <span>所</span>
  497. </FormItem>
  498. </div>
  499. <FormItem style={{ 'display': this.state.resDis }}
  500. {...formItemLayout}
  501. label="创办时间"
  502. >
  503. {getFieldDecorator('resTime', {
  504. initialValue: this.state.resTime || 0
  505. })(
  506. <InputNumber />
  507. )}
  508. <span>年</span>
  509. </FormItem>
  510. <FormItem
  511. {...formItemLayout}
  512. label="LOGO"
  513. labelCol={{ span: 3 }}
  514. wrapperCol={{ span: 20 }}
  515. >
  516. {getFieldDecorator('avatar')(
  517. <Avatar name="companyLogo" urlData={this.companyLogoUrl} logoUrl={this.state.logoUrl} />
  518. )}
  519. </FormItem>
  520. <div className="set-explain">
  521. <p>上传的照片图片格式应为jpg格式,大小在2M以内</p>
  522. </div>
  523. <FormItem
  524. labelCol={{ span: 3 }}
  525. wrapperCol={{ span: 21 }}
  526. label="宣传图片"
  527. >
  528. {getFieldDecorator('companyLifePic')(
  529. <PicturesWall fileList={this.companyLifePicUrl} lifePhotoList={this.state.companyLifePicList} />
  530. )}
  531. </FormItem>
  532. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  533. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  534. </FormItem>
  535. </Form >
  536. );
  537. },
  538. }));
  539. const Person = React.createClass({
  540. getInitialState() {
  541. return {
  542. loading: false
  543. };
  544. },
  545. spinChange(e) {
  546. this.setState({
  547. loading: e
  548. });
  549. },
  550. render() {
  551. return (
  552. <Spin spinning={this.state.loading} className='spin-box'>
  553. <div className="set-person">
  554. <div className="acc-detail">
  555. <p className="acc-title">单位资料</p>
  556. <PersonFrom spinState={this.spinChange} />
  557. </div>
  558. </div>
  559. </Spin>
  560. )
  561. }
  562. });
  563. export default Person;