company.jsx 22 KB

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