company.jsx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  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. }
  149. }.bind(this),
  150. }).always(function () {
  151. this.props.spinState(false);
  152. }.bind(this));
  153. },
  154. getInitialState() {
  155. return {
  156. loading: false,
  157. idttType: '企业',
  158. companyDis: 'block',
  159. schoolDis: 'none',
  160. resDis: 'none',
  161. companyLifePicObj:[],
  162. aca: 0,
  163. PhDTutor: 0,
  164. MSTutor: 0,
  165. otherExperts: 0,
  166. StateKeyLab: 0,
  167. EduKeyLab: 0,
  168. ComCenter: 0,
  169. otherCenter: 0
  170. };
  171. },
  172. handleSubmit(e) {
  173. e.preventDefault();
  174. this.props.form.validateFields((err, values) => {
  175. //地址值
  176. let cmbP = document.getElementById('cmbProvince').value;
  177. let cmbC = document.getElementById('cmbCity').value;
  178. let cmbA = document.getElementById('cmbArea').value;
  179. //
  180. let leftPicArr = [];
  181. this.state.companyLifePicObj.map(function (item) {
  182. leftPicArr.push(item.response.data);
  183. });
  184. let lifePhotoUrl = leftPicArr.join(",");
  185. if (!err) {
  186. this.props.spinState(true);
  187. $.ajax({
  188. method: "POST",
  189. dataType: "json",
  190. crossDomain: false,
  191. url: globalConfig.context + "/api/user/orgPro",
  192. data: {
  193. "info.identityType": values.identityType,
  194. "info.companyName": values.unitName,
  195. "info.locationProvince": cmbP,
  196. "info.locationCity": cmbC,
  197. "info.locationArea": cmbA,
  198. "info.unitSize": values.unitNumber,
  199. "info.companyIntroduction": values.unitIntro,
  200. "info.homeUnit": values.unitFrom,
  201. "info.logoUrl": this.state.companyLogoUrl,
  202. "info.publicityPictureUrl": lifePhotoUrl,
  203. "pro.qualification": values.qiyezizhi,
  204. "pro.turnover": values.turnover,
  205. "pro.collegeAttribute": values.schoolProp,
  206. "pro.collegeEstablishTime": values.schoolTime,
  207. "pro.academician": this.state.aca,
  208. "pro.doctoralTutor": this.state.PhDTutor,
  209. "pro.masterTutor": this.state.MSTutor,
  210. "pro.otherExpert": this.state.otherExperts,
  211. "pro.nationalLab": this.state.StateKeyLab,
  212. "pro.educationLab": this.state.EduKeyLab,
  213. "pro.enterpriseCenter": this.state.ComCenter,
  214. "pro.otherCenter": this.state.otherCenter,
  215. "pro.institutionEstablishTime": values.resTime
  216. }
  217. }).done(function (data) {
  218. if (!data.error.length) {
  219. message.success('保存成功!');
  220. } else {
  221. message.warning(data.error[0].message);
  222. }
  223. }.bind(this)).always(function () {
  224. this.props.spinState(false);
  225. }.bind(this));
  226. }
  227. });
  228. },
  229. idttTypeChange(e) {
  230. if (e === '企业') {
  231. this.props.form.setFieldsValue({ 'indentityType': e });
  232. this.setState({
  233. companyDis: 'block',
  234. schoolDis: 'none',
  235. resDis: 'none'
  236. });
  237. } else if (e === '院校') {
  238. this.props.form.setFieldsValue({ 'indentityType': e });
  239. this.setState({
  240. companyDis: 'none',
  241. schoolDis: 'block',
  242. resDis: 'none'
  243. });
  244. } else if (e === '研究机构') {
  245. this.props.form.setFieldsValue({ 'indentityType': e });
  246. this.setState({
  247. companyDis: 'none',
  248. schoolDis: 'none',
  249. resDis: 'block'
  250. });
  251. } else {
  252. this.props.form.setFieldsValue({ 'indentityType': e });
  253. this.setState({
  254. companyDis: 'none',
  255. schoolDis: 'none',
  256. resDis: 'none'
  257. });
  258. }
  259. },
  260. downloadPic(type) {
  261. window.open(globalConfig.context + "/open/downLoadPicture?path=" + type)
  262. },
  263. companyLogoUrl(e) {
  264. this.state.companyLogoUrl = e;
  265. },
  266. companyLifePicUrl(e) {
  267. this.state.companyLifePicObj = e;
  268. },
  269. componentDidMount() {
  270. addressInit('cmbProvince', 'cmbCity', 'cmbArea');
  271. this.getData();
  272. },
  273. render() {
  274. const FormItem = Form.Item;
  275. const Option = Select.Option;
  276. const { getFieldDecorator } = this.props.form;
  277. const formItemLayout = {
  278. labelCol: { span: 3 },
  279. wrapperCol: { span: 12 },
  280. };
  281. const _me = this;
  282. return (
  283. <Form horizontal onSubmit={this.handleSubmit} className="person-form">
  284. <FormItem
  285. labelCol={{ span: 3 }}
  286. wrapperCol={{ span: 8 }}
  287. label="身份类型"
  288. >
  289. {getFieldDecorator('identityType', {
  290. initialValue: this.state.idttType
  291. })(
  292. <Select className="acc-edu-lvl" onChange={this.idttTypeChange}>
  293. {
  294. edulvlArr.map(function (item, i) {
  295. return <Option key={i} value={item} >{item}</Option>
  296. })
  297. }
  298. </Select>
  299. )}
  300. </FormItem>
  301. <FormItem
  302. {...formItemLayout}
  303. label="单位名称"
  304. >
  305. {getFieldDecorator('unitName', {
  306. initialValue: this.state.unitName
  307. })(
  308. <Input />
  309. )}
  310. </FormItem>
  311. <FormItem
  312. {...formItemLayout}
  313. label="所在地"
  314. >
  315. {getFieldDecorator('province')(
  316. <div>
  317. <select id="cmbProvince" name="cmbProvince"></select>
  318. <select id="cmbCity" name="cmbCity"></select>
  319. <select id="cmbArea" name="cmbArea"></select>
  320. </div>
  321. )}
  322. </FormItem>
  323. <FormItem
  324. {...formItemLayout}
  325. label="单位规模"
  326. >
  327. {getFieldDecorator('unitNumber', {
  328. initialValue: this.state.unitNumber
  329. })(
  330. <InputNumber />
  331. )}
  332. <span>人</span>
  333. </FormItem>
  334. <FormItem
  335. labelCol={{ span: 3 }}
  336. wrapperCol={{ span: 20 }}
  337. label="单位简介"
  338. >
  339. {getFieldDecorator('unitIntro', {
  340. initialValue: this.state.unitIntro
  341. })(
  342. <Input type="textarea"
  343. placeholder="全面介绍自己,让商友更深入了解您,内容长度不超过1000个字。"
  344. rows={6} />
  345. )}
  346. <p>还可输入{
  347. (() => {
  348. if (_me.props.form.getFieldValue('unitIntro') && _me.props.form.getFieldValue('unitIntro').length) {
  349. return 1000 - _me.props.form.getFieldValue('unitIntro').length;
  350. } else {
  351. return 1000;
  352. }
  353. })()
  354. }字/1000</p>
  355. </FormItem>
  356. <FormItem
  357. {...formItemLayout}
  358. label="归属单位"
  359. >
  360. {getFieldDecorator('unitFrom', {
  361. initialValue: this.state.unitFrom
  362. })(
  363. <Input placeholder="非法人单位填写。" />
  364. )}
  365. </FormItem>
  366. <FormItem style={{ 'display': this.state.companyDis }}
  367. labelCol={{ span: 3 }}
  368. wrapperCol={{ span: 8 }}
  369. label="企业资质"
  370. >
  371. {getFieldDecorator('qiyezizhi', {
  372. initialValue: this.state.qiyezizhi
  373. })(
  374. <Select className="acc-edu-lvl">
  375. {
  376. zizhiArr.map(function (item, i) {
  377. return <Option key={i} value={item} >{item}</Option>
  378. })
  379. }
  380. </Select>
  381. )}
  382. </FormItem>
  383. <FormItem style={{ 'display': this.state.companyDis }}
  384. labelCol={{ span: 3 }}
  385. wrapperCol={{ span: 6 }}
  386. label="年营业额"
  387. >
  388. {getFieldDecorator('turnover', {
  389. initialValue: this.state.turnover
  390. })(
  391. <InputNumber />
  392. )}
  393. <span>万元</span>
  394. </FormItem>
  395. <FormItem style={{ 'display': this.state.schoolDis }}
  396. labelCol={{ span: 3 }}
  397. wrapperCol={{ span: 8 }}
  398. label="院校属性"
  399. >
  400. {getFieldDecorator('schoolProp', {
  401. initialValue: this.state.schoolProp
  402. })(
  403. <Select className="acc-edu-lvl">
  404. {
  405. schoolArr.map(function (item, i) {
  406. return <Option key={i} value={item} >{item}</Option>
  407. })
  408. }
  409. </Select>
  410. )}
  411. </FormItem>
  412. <FormItem style={{ 'display': this.state.schoolDis }}
  413. {...formItemLayout}
  414. label="创办时间"
  415. >
  416. {getFieldDecorator('schoolTime', {
  417. initialValue: this.state.schoolTime
  418. })(
  419. <InputNumber />
  420. )}
  421. <span>年</span>
  422. </FormItem>
  423. <FormItem style={{ 'display': this.state.schoolDis }}
  424. labelCol={{ span: 3 }}
  425. wrapperCol={{ span: 21, offset: 3 }}
  426. label=""
  427. >
  428. <div className="school-props clearfix">
  429. <div><span>院士:</span><InputNumber value={this.state.aca} onChange={function (e) { this.setState({ aca: e }) }.bind(this)} />人</div>
  430. <div><span>博士生导师:</span><InputNumber value={this.state.PhDTutor} onChange={function (e) { this.setState({ PhDTutor: e }) }.bind(this)} />人</div>
  431. <div><span>硕士生导师:</span><InputNumber value={this.state.MSTutor} onChange={function (e) { this.setState({ MSTutor: e }) }.bind(this)} />人</div>
  432. <div><span>其他专家:</span><InputNumber value={this.state.otherExperts} onChange={function (e) { this.setState({ otherExperts: e }) }.bind(this)} />人</div>
  433. <div><span>国家级重点实验室:</span><InputNumber value={this.state.StateKeyLab} onChange={function (e) { this.setState({ StateKeyLab: e }) }.bind(this)} />所</div>
  434. <div><span>教育部重点实验室:</span><InputNumber value={this.state.EduKeyLab} onChange={function (e) { this.setState({ EduKeyLab: e }) }.bind(this)} />所</div>
  435. <div><span>企业共建研究中心:</span><InputNumber value={this.state.ComCenter} onChange={function (e) { this.setState({ ComCenter: e }) }.bind(this)} />所</div>
  436. <div><span>其他研究中心:</span><InputNumber value={this.state.otherCenter} onChange={function (e) { this.setState({ otherCenter: e }) }.bind(this)} />所</div>
  437. </div>
  438. </FormItem>
  439. <FormItem style={{ 'display': this.state.resDis }}
  440. {...formItemLayout}
  441. label="创办时间"
  442. >
  443. {getFieldDecorator('resTime', {
  444. initialValue: this.state.resTime
  445. })(
  446. <InputNumber />
  447. )}
  448. <span>年</span>
  449. </FormItem>
  450. <FormItem
  451. {...formItemLayout}
  452. label="LOGO"
  453. labelCol={{ span: 3 }}
  454. wrapperCol={{ span: 20 }}
  455. >
  456. {getFieldDecorator('avatar')(
  457. <Avatar name="companyLogo" urlData={this.companyLogoUrl} />
  458. )}
  459. </FormItem>
  460. <div className="set-explain">
  461. <p>上传的照片图片格式应为jpg格式,大小在2M以内</p>
  462. </div>
  463. <FormItem
  464. labelCol={{ span: 3 }}
  465. wrapperCol={{ span: 21 }}
  466. label="宣传图片"
  467. >
  468. {getFieldDecorator('companyLifePic')(
  469. <PicturesWall fileList={this.companyLifePicUrl} lifePhotoList={this.state.companyLifePicList} />
  470. )}
  471. </FormItem>
  472. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  473. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  474. </FormItem>
  475. </Form >
  476. );
  477. },
  478. }));
  479. const Person = React.createClass({
  480. getInitialState() {
  481. return {
  482. loading: false
  483. };
  484. },
  485. spinChange(e) {
  486. this.setState({
  487. loading: e
  488. });
  489. },
  490. render() {
  491. return (
  492. <Spin spinning={this.state.loading} className='spin-box'>
  493. <div className="set-person">
  494. <div className="acc-detail">
  495. <p className="acc-title">单位资料</p>
  496. <PersonFrom spinState={this.spinChange} />
  497. </div>
  498. </div>
  499. </Spin>
  500. )
  501. }
  502. });
  503. export default Person;