company.jsx 22 KB

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