company.jsx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  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, } from '../../tools.js';
  7. import { edulvlArr, zizhiArr, schoolArr } from '../../dataDic.js';
  8. function getBase64(img, callback) {
  9. const reader = new FileReader();
  10. reader.addEventListener('load', () => callback(reader.result));
  11. reader.readAsDataURL(img);
  12. };
  13. function beforeUpload(file) {
  14. const isJPG = file.type === 'image/jpeg';
  15. if (!isJPG) {
  16. message.error('You can only upload JPG file!');
  17. }
  18. const isLt2M = file.size / 1024 / 1024 < 2;
  19. if (!isLt2M) {
  20. message.error('Image must smaller than 2MB!');
  21. }
  22. return isJPG && isLt2M;
  23. };
  24. class Avatar extends React.Component {
  25. constructor(props) {
  26. super(props);
  27. this.state = {
  28. imageUrl: ''
  29. }
  30. }
  31. handleChange(info) {
  32. if (info.file.status === 'done') {
  33. // Get this url from response in real world.
  34. getBase64(info.file.originFileObj, imageUrl => this.setState({ imageUrl }));
  35. this.props.urlData(info.file.response.data);
  36. }
  37. }
  38. render() {
  39. const imageUrl = this.state.imageUrl;
  40. return (
  41. <Upload
  42. className="avatar-uploader"
  43. name="avatar"
  44. showUploadList={false}
  45. action={globalConfig.context + "/api/user/avatar/uploadReplace"}
  46. data={{ 'sign': this.props.name }}
  47. beforeUpload={beforeUpload}
  48. onChange={this.handleChange.bind(this)}
  49. >
  50. {
  51. imageUrl ?
  52. <img src={imageUrl} role="presentation" className="avatar" /> :
  53. <Icon type="plus" className="avatar-uploader-trigger" />
  54. }
  55. </Upload>
  56. );
  57. }
  58. };
  59. class PicturesWall extends React.Component {
  60. constructor(props) {
  61. super(props);
  62. this.state = {
  63. previewVisible: false,
  64. propsbool: true,
  65. previewImage: '',
  66. fileList: [],
  67. }
  68. }
  69. handleCancel() {
  70. this.setState({ previewVisible: false })
  71. }
  72. handlePreview(file) {
  73. this.setState({
  74. previewImage: file.url || file.thumbUrl,
  75. previewVisible: true,
  76. });
  77. }
  78. handleChange(info) {
  79. let fileList = info.fileList;
  80. this.setState({ fileList });
  81. this.props.fileList(fileList);
  82. }
  83. componentWillReceiveProps(nextProps) {
  84. if (nextProps.lifePhotoList && this.state.propsbool) {
  85. this.state.fileList = nextProps.lifePhotoList;
  86. this.state.propsbool = false;
  87. }
  88. }
  89. render() {
  90. const { previewVisible, previewImage, fileList } = this.state;
  91. const uploadButton = (
  92. <div>
  93. <Icon type="plus" />
  94. <div className="ant-upload-text">Upload</div>
  95. </div>
  96. );
  97. return (
  98. <div className="clearfix">
  99. <Upload
  100. action={globalConfig.context + "/api/user/avatar/upload"}
  101. listType="picture-card"
  102. fileList={fileList}
  103. onPreview={this.handlePreview}
  104. onChange={this.handleChange.bind(this)}
  105. >
  106. {fileList.length >= 9 ? null : uploadButton}
  107. </Upload>
  108. <Modal visible={previewVisible} footer={null} onCancel={this.handleCancel}>
  109. <img alt="example" style={{ width: '100%' }} src={previewImage} />
  110. </Modal>
  111. </div>
  112. );
  113. }
  114. };
  115. const PersonFrom = Form.create()(React.createClass({
  116. getData() {
  117. this.props.spinState(true);
  118. $.ajax({
  119. method: "get",
  120. dataType: "json",
  121. url: globalConfig.context + "/api/user/member",
  122. success: function (data) {
  123. if (data.data && data.data.info && data.data.pro) {
  124. addressInit('cmbProvince', 'cmbCity', 'cmbArea',
  125. data.data.locationProvince, data.data.locationCity, data.data.locationArea);
  126. let theArr = splitUrl(data.data.info.publicityPictureUrl, ',', globalConfig.staticHost + '/upload');
  127. this.setState({
  128. idttType: data.data.info.identityType,
  129. unitName: data.data.info.companyName,
  130. unitNumber: data.data.info.unitSize,
  131. unitIntro: data.data.info.companyIntroduction,
  132. unitFrom: data.data.info.homeUnit,
  133. companyLifePicList: theArr,
  134. qiyezizhi: data.data.pro.qualification,
  135. turnover: data.data.pro.turnover,
  136. schoolProp: data.data.pro.collegeAttribute,
  137. schoolTime: data.data.pro.collegeEstablishTime,
  138. aca: data.data.pro.academician,
  139. PhDTutor: data.data.pro.doctoralTutor,
  140. MSTutor: data.data.pro.masterTutor,
  141. otherExperts: data.data.pro.otherExpert,
  142. StateKeyLab: data.data.pro.nationalLab,
  143. EduKeyLab: data.data.pro.educationLab,
  144. ComCenter: data.data.pro.enterpriseCenter,
  145. otherCenter: data.data.pro.otherCenter,
  146. resTime: data.data.pro.institutionEstablishTime
  147. });
  148. this.idttTypeChange(data.data.info.identityType);
  149. };
  150. }.bind(this),
  151. }).always(function () {
  152. this.props.spinState(false);
  153. }.bind(this));
  154. },
  155. getInitialState() {
  156. return {
  157. loading: false,
  158. idttType: '企业',
  159. companyDis: 'block',
  160. schoolDis: 'none',
  161. resDis: 'none',
  162. companyLifePicObj: [],
  163. aca: 0,
  164. PhDTutor: 0,
  165. MSTutor: 0,
  166. otherExperts: 0,
  167. StateKeyLab: 0,
  168. EduKeyLab: 0,
  169. ComCenter: 0,
  170. otherCenter: 0
  171. };
  172. },
  173. handleSubmit(e) {
  174. e.preventDefault();
  175. this.props.form.validateFields((err, values) => {
  176. //地址值
  177. let cmbP = document.getElementById('cmbProvince').value;
  178. let cmbC = document.getElementById('cmbCity').value;
  179. let cmbA = document.getElementById('cmbArea').value;
  180. //
  181. let leftPicArr = [];
  182. this.state.companyLifePicObj.map(function (item) {
  183. leftPicArr.push(item.response.data);
  184. });
  185. let lifePhotoUrl = leftPicArr.join(",");
  186. if (!err) {
  187. this.props.spinState(true);
  188. $.ajax({
  189. method: "POST",
  190. dataType: "json",
  191. crossDomain: false,
  192. url: globalConfig.context + "/api/user/orgPro",
  193. data: {
  194. "info.identityType": values.identityType,
  195. "info.companyName": values.unitName,
  196. "info.locationProvince": cmbP,
  197. "info.locationCity": cmbC,
  198. "info.locationArea": cmbA,
  199. "info.unitSize": values.unitNumber,
  200. "info.companyIntroduction": values.unitIntro,
  201. "info.homeUnit": values.unitFrom,
  202. "info.logoUrl": this.state.companyLogoUrl,
  203. "info.publicityPictureUrl": lifePhotoUrl,
  204. "pro.qualification": values.qiyezizhi,
  205. "pro.turnover": values.turnover,
  206. "pro.collegeAttribute": values.schoolProp,
  207. "pro.collegeEstablishTime": values.schoolTime,
  208. "pro.academician": this.state.aca,
  209. "pro.doctoralTutor": this.state.PhDTutor,
  210. "pro.masterTutor": this.state.MSTutor,
  211. "pro.otherExpert": this.state.otherExperts,
  212. "pro.nationalLab": this.state.StateKeyLab,
  213. "pro.educationLab": this.state.EduKeyLab,
  214. "pro.enterpriseCenter": this.state.ComCenter,
  215. "pro.otherCenter": this.state.otherCenter,
  216. "pro.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. edulvlArr.map(function (item, i) {
  296. return <Option key={i} value={item} >{item}</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
  396. })(
  397. <InputNumber />
  398. )}
  399. <span>年</span>
  400. </FormItem>
  401. <FormItem style={{ 'display': this.state.schoolDis }}
  402. labelCol={{ span: 3 }}
  403. wrapperCol={{ span: 21, offset: 3 }}
  404. label=""
  405. >
  406. <div className="school-props clearfix">
  407. <div><span>院士:</span><InputNumber value={this.state.aca} onChange={function (e) { this.setState({ aca: e }) }.bind(this)} />人</div>
  408. <div><span>博士生导师:</span><InputNumber value={this.state.PhDTutor} onChange={function (e) { this.setState({ PhDTutor: e }) }.bind(this)} />人</div>
  409. <div><span>硕士生导师:</span><InputNumber value={this.state.MSTutor} onChange={function (e) { this.setState({ MSTutor: e }) }.bind(this)} />人</div>
  410. <div><span>其他专家:</span><InputNumber value={this.state.otherExperts} onChange={function (e) { this.setState({ otherExperts: e }) }.bind(this)} />人</div>
  411. <div><span>国家级重点实验室:</span><InputNumber value={this.state.StateKeyLab} onChange={function (e) { this.setState({ StateKeyLab: e }) }.bind(this)} />所</div>
  412. <div><span>教育部重点实验室:</span><InputNumber value={this.state.EduKeyLab} onChange={function (e) { this.setState({ EduKeyLab: e }) }.bind(this)} />所</div>
  413. <div><span>企业共建研究中心:</span><InputNumber value={this.state.ComCenter} onChange={function (e) { this.setState({ ComCenter: e }) }.bind(this)} />所</div>
  414. <div><span>其他研究中心:</span><InputNumber value={this.state.otherCenter} onChange={function (e) { this.setState({ otherCenter: e }) }.bind(this)} />所</div>
  415. </div>
  416. </FormItem>
  417. <FormItem style={{ 'display': this.state.resDis }}
  418. {...formItemLayout}
  419. label="创办时间"
  420. >
  421. {getFieldDecorator('resTime', {
  422. initialValue: this.state.resTime
  423. })(
  424. <InputNumber />
  425. )}
  426. <span>年</span>
  427. </FormItem>
  428. <FormItem
  429. {...formItemLayout}
  430. label="LOGO"
  431. labelCol={{ span: 3 }}
  432. wrapperCol={{ span: 20 }}
  433. >
  434. {getFieldDecorator('avatar')(
  435. <Avatar name="companyLogo" urlData={this.companyLogoUrl} />
  436. )}
  437. </FormItem>
  438. <div className="set-explain">
  439. <p>上传的照片图片格式应为jpg格式,大小在2M以内</p>
  440. </div>
  441. <FormItem
  442. labelCol={{ span: 3 }}
  443. wrapperCol={{ span: 21 }}
  444. label="宣传图片"
  445. >
  446. {getFieldDecorator('companyLifePic')(
  447. <PicturesWall fileList={this.companyLifePicUrl} lifePhotoList={this.state.companyLifePicList} />
  448. )}
  449. </FormItem>
  450. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  451. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  452. </FormItem>
  453. </Form >
  454. );
  455. },
  456. }));
  457. const Person = React.createClass({
  458. getInitialState() {
  459. return {
  460. loading: false
  461. };
  462. },
  463. spinChange(e) {
  464. this.setState({
  465. loading: e
  466. });
  467. },
  468. render() {
  469. return (
  470. <Spin spinning={this.state.loading} className='spin-box'>
  471. <div className="set-person">
  472. <div className="acc-detail">
  473. <p className="acc-title">单位资料</p>
  474. <PersonFrom spinState={this.spinChange} />
  475. </div>
  476. </div>
  477. </Spin>
  478. )
  479. }
  480. });
  481. export default Person;
  482. // <FormItem
  483. // {...formItemLayout}
  484. // label="单位规模"
  485. // >
  486. // {getFieldDecorator('unitNumber', {
  487. // initialValue: this.state.unitNumber
  488. // })(
  489. // <InputNumber />
  490. // )}
  491. // <span>人</span>
  492. // </FormItem>
  493. // <FormItem style={{ 'display': this.state.companyDis }}
  494. // labelCol={{ span: 3 }}
  495. // wrapperCol={{ span: 6 }}
  496. // label="年营业额"
  497. // >
  498. // {getFieldDecorator('turnover', {
  499. // initialValue: this.state.turnover
  500. // })(
  501. // <InputNumber />
  502. // )}
  503. // <span>万元</span>
  504. // </FormItem>