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. labelCol={{ span: 3 }}
  325. wrapperCol={{ span: 20 }}
  326. label="单位简介"
  327. >
  328. {getFieldDecorator('unitIntro', {
  329. initialValue: this.state.unitIntro
  330. })(
  331. <Input type="textarea"
  332. placeholder="全面介绍自己,让商友更深入了解您,内容长度不超过1000个字。"
  333. rows={6} />
  334. )}
  335. <p>还可输入{
  336. (() => {
  337. if (_me.props.form.getFieldValue('unitIntro') && _me.props.form.getFieldValue('unitIntro').length) {
  338. return 1000 - _me.props.form.getFieldValue('unitIntro').length;
  339. } else {
  340. return 1000;
  341. }
  342. })()
  343. }字/1000</p>
  344. </FormItem>
  345. <FormItem
  346. {...formItemLayout}
  347. label="归属单位"
  348. >
  349. {getFieldDecorator('unitFrom', {
  350. initialValue: this.state.unitFrom
  351. })(
  352. <Input placeholder="非法人单位填写。" />
  353. )}
  354. </FormItem>
  355. <FormItem style={{ 'display': this.state.companyDis }}
  356. labelCol={{ span: 3 }}
  357. wrapperCol={{ span: 8 }}
  358. label="企业资质"
  359. >
  360. {getFieldDecorator('qiyezizhi', {
  361. initialValue: this.state.qiyezizhi
  362. })(
  363. <Select className="acc-edu-lvl">
  364. {
  365. zizhiArr.map(function (item, i) {
  366. return <Option key={i} value={item} >{item}</Option>
  367. })
  368. }
  369. </Select>
  370. )}
  371. </FormItem>
  372. <FormItem style={{ 'display': this.state.schoolDis }}
  373. labelCol={{ span: 3 }}
  374. wrapperCol={{ span: 8 }}
  375. label="院校属性"
  376. >
  377. {getFieldDecorator('schoolProp', {
  378. initialValue: this.state.schoolProp
  379. })(
  380. <Select className="acc-edu-lvl">
  381. {
  382. schoolArr.map(function (item, i) {
  383. return <Option key={i} value={item} >{item}</Option>
  384. })
  385. }
  386. </Select>
  387. )}
  388. </FormItem>
  389. <FormItem style={{ 'display': this.state.schoolDis }}
  390. {...formItemLayout}
  391. label="创办时间"
  392. >
  393. {getFieldDecorator('schoolTime', {
  394. initialValue: this.state.schoolTime
  395. })(
  396. <InputNumber />
  397. )}
  398. <span>年</span>
  399. </FormItem>
  400. <FormItem style={{ 'display': this.state.schoolDis }}
  401. labelCol={{ span: 3 }}
  402. wrapperCol={{ span: 21, offset: 3 }}
  403. label=""
  404. >
  405. <div className="school-props clearfix">
  406. <div><span>院士:</span><InputNumber value={this.state.aca} onChange={function (e) { this.setState({ aca: e }) }.bind(this)} />人</div>
  407. <div><span>博士生导师:</span><InputNumber value={this.state.PhDTutor} onChange={function (e) { this.setState({ PhDTutor: e }) }.bind(this)} />人</div>
  408. <div><span>硕士生导师:</span><InputNumber value={this.state.MSTutor} onChange={function (e) { this.setState({ MSTutor: e }) }.bind(this)} />人</div>
  409. <div><span>其他专家:</span><InputNumber value={this.state.otherExperts} onChange={function (e) { this.setState({ otherExperts: e }) }.bind(this)} />人</div>
  410. <div><span>国家级重点实验室:</span><InputNumber value={this.state.StateKeyLab} onChange={function (e) { this.setState({ StateKeyLab: e }) }.bind(this)} />所</div>
  411. <div><span>教育部重点实验室:</span><InputNumber value={this.state.EduKeyLab} onChange={function (e) { this.setState({ EduKeyLab: e }) }.bind(this)} />所</div>
  412. <div><span>企业共建研究中心:</span><InputNumber value={this.state.ComCenter} onChange={function (e) { this.setState({ ComCenter: e }) }.bind(this)} />所</div>
  413. <div><span>其他研究中心:</span><InputNumber value={this.state.otherCenter} onChange={function (e) { this.setState({ otherCenter: e }) }.bind(this)} />所</div>
  414. </div>
  415. </FormItem>
  416. <FormItem style={{ 'display': this.state.resDis }}
  417. {...formItemLayout}
  418. label="创办时间"
  419. >
  420. {getFieldDecorator('resTime', {
  421. initialValue: this.state.resTime
  422. })(
  423. <InputNumber />
  424. )}
  425. <span>年</span>
  426. </FormItem>
  427. <FormItem
  428. {...formItemLayout}
  429. label="LOGO"
  430. labelCol={{ span: 3 }}
  431. wrapperCol={{ span: 20 }}
  432. >
  433. {getFieldDecorator('avatar')(
  434. <Avatar name="companyLogo" urlData={this.companyLogoUrl} />
  435. )}
  436. </FormItem>
  437. <div className="set-explain">
  438. <p>上传的照片图片格式应为jpg格式,大小在2M以内</p>
  439. </div>
  440. <FormItem
  441. labelCol={{ span: 3 }}
  442. wrapperCol={{ span: 21 }}
  443. label="宣传图片"
  444. >
  445. {getFieldDecorator('companyLifePic')(
  446. <PicturesWall fileList={this.companyLifePicUrl} lifePhotoList={this.state.companyLifePicList} />
  447. )}
  448. </FormItem>
  449. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  450. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  451. </FormItem>
  452. </Form >
  453. );
  454. },
  455. }));
  456. const Person = React.createClass({
  457. getInitialState() {
  458. return {
  459. loading: false
  460. };
  461. },
  462. spinChange(e) {
  463. this.setState({
  464. loading: e
  465. });
  466. },
  467. render() {
  468. return (
  469. <Spin spinning={this.state.loading} className='spin-box'>
  470. <div className="set-person">
  471. <div className="acc-detail">
  472. <p className="acc-title">单位资料</p>
  473. <PersonFrom spinState={this.spinChange} />
  474. </div>
  475. </div>
  476. </Spin>
  477. )
  478. }
  479. });
  480. export default Person;
  481. // <FormItem
  482. // {...formItemLayout}
  483. // label="单位规模"
  484. // >
  485. // {getFieldDecorator('unitNumber', {
  486. // initialValue: this.state.unitNumber
  487. // })(
  488. // <InputNumber />
  489. // )}
  490. // <span>人</span>
  491. // </FormItem>
  492. // <FormItem style={{ 'display': this.state.companyDis }}
  493. // labelCol={{ span: 3 }}
  494. // wrapperCol={{ span: 6 }}
  495. // label="年营业额"
  496. // >
  497. // {getFieldDecorator('turnover', {
  498. // initialValue: this.state.turnover
  499. // })(
  500. // <InputNumber />
  501. // )}
  502. // <span>万元</span>
  503. // </FormItem>