company.jsx 22 KB

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