company.jsx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  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. function getBase64(img, callback) {
  8. const reader = new FileReader();
  9. reader.addEventListener('load', () => callback(reader.result));
  10. reader.readAsDataURL(img);
  11. };
  12. function beforeUpload(file) {
  13. const isJPG = file.type === 'image/jpeg';
  14. if (!isJPG) {
  15. message.error('You can only upload JPG file!');
  16. }
  17. const isLt2M = file.size / 1024 / 1024 < 2;
  18. if (!isLt2M) {
  19. message.error('Image must smaller than 2MB!');
  20. }
  21. return isJPG && isLt2M;
  22. };
  23. class Avatar extends React.Component {
  24. constructor(props) {
  25. super(props);
  26. this.state = {
  27. imageUrl: ''
  28. }
  29. }
  30. handleChange(info) {
  31. if (info.file.status === 'done') {
  32. // Get this url from response in real world.
  33. getBase64(info.file.originFileObj, imageUrl => this.setState({ imageUrl }));
  34. this.props.urlData(info.file.response.data);
  35. }
  36. }
  37. render() {
  38. const imageUrl = this.state.imageUrl;
  39. return (
  40. <Upload
  41. className="avatar-uploader"
  42. name="avatar"
  43. showUploadList={false}
  44. action={globalConfig.context + "/api/user/avatar/uploadReplace"}
  45. data={{ 'sign': this.props.name }}
  46. beforeUpload={beforeUpload}
  47. onChange={this.handleChange.bind(this)}
  48. >
  49. {
  50. imageUrl ?
  51. <img src={imageUrl} role="presentation" className="avatar" /> :
  52. <Icon type="plus" className="avatar-uploader-trigger" />
  53. }
  54. </Upload>
  55. );
  56. }
  57. };
  58. class PicturesWall extends React.Component {
  59. constructor(props) {
  60. super(props);
  61. this.state = {
  62. previewVisible: false,
  63. propsbool: true,
  64. previewImage: '',
  65. fileList: [],
  66. }
  67. }
  68. handleCancel() {
  69. this.setState({ previewVisible: false })
  70. }
  71. handlePreview(file) {
  72. this.setState({
  73. previewImage: file.url || file.thumbUrl,
  74. previewVisible: true,
  75. });
  76. }
  77. handleChange(info) {
  78. let fileList = info.fileList;
  79. this.setState({ fileList });
  80. this.props.fileList(fileList);
  81. }
  82. componentWillReceiveProps(nextProps) {
  83. if ( nextProps.lifePhotoList && this.state.propsbool) {
  84. this.state.fileList = nextProps.lifePhotoList;
  85. this.state.propsbool = false;
  86. }
  87. }
  88. render() {
  89. const { previewVisible, previewImage, fileList } = this.state;
  90. const uploadButton = (
  91. <div>
  92. <Icon type="plus" />
  93. <div className="ant-upload-text">Upload</div>
  94. </div>
  95. );
  96. return (
  97. <div className="clearfix">
  98. <Upload
  99. action={globalConfig.context + "/api/user/avatar/upload"}
  100. listType="picture-card"
  101. fileList={fileList}
  102. onPreview={this.handlePreview}
  103. onChange={this.handleChange.bind(this)}
  104. >
  105. {fileList.length >= 9 ? null : uploadButton}
  106. </Upload>
  107. <Modal visible={previewVisible} footer={null} onCancel={this.handleCancel}>
  108. <img alt="example" style={{ width: '100%' }} src={previewImage} />
  109. </Modal>
  110. </div>
  111. );
  112. }
  113. };
  114. const PersonFrom = Form.create()(React.createClass({
  115. getData() {
  116. this.props.spinState(true);
  117. $.ajax({
  118. method: "get",
  119. dataType: "json",
  120. url: globalConfig.context + "/api/user/member",
  121. success: function (data) {
  122. if (data.data && data.data.info && data.data.pro) {
  123. addressInit('cmbProvince', 'cmbCity', 'cmbArea',
  124. data.data.locationProvince, data.data.locationCity, data.data.locationArea);
  125. let theArr = splitUrl(data.data.info.publicityPictureUrl, ',', globalConfig.staticHost + '/upload');
  126. this.setState({
  127. idttType: data.data.info.identityType,
  128. unitName: data.data.info.companyName,
  129. unitNumber: data.data.info.unitSize,
  130. unitIntro: data.data.info.companyIntroduction,
  131. unitFrom: data.data.info.homeUnit,
  132. companyLifePicUrl: theArr,
  133. qiyezizhi: data.data.pro.qualification,
  134. turnover: data.data.pro.turnover,
  135. schoolProp: data.data.pro.collegeAttribute,
  136. schoolTime: data.data.pro.collegeEstablishTime,
  137. aca: data.data.pro.academician,
  138. PhDTutor: data.data.pro.doctoralTutor,
  139. MSTutor: data.data.pro.masterTutor,
  140. otherExperts: data.data.pro.otherExpert,
  141. StateKeyLab: data.data.pro.nationalLab,
  142. EduKeyLab: data.data.pro.educationLab,
  143. ComCenter: data.data.pro.enterpriseCenter,
  144. otherCenter: data.data.pro.otherCenter,
  145. resTime: data.data.pro.institutionEstablishTime
  146. });
  147. }
  148. }.bind(this),
  149. }).always(function () {
  150. this.props.spinState(false);
  151. }.bind(this));
  152. },
  153. getInitialState() {
  154. return {
  155. loading: false,
  156. idttType: '企业',
  157. companyDis: 'block',
  158. schoolDis: 'none',
  159. resDis: 'none',
  160. aca: 0,
  161. PhDTutor: 0,
  162. MSTutor: 0,
  163. otherExperts: 0,
  164. StateKeyLab: 0,
  165. EduKeyLab: 0,
  166. ComCenter: 0,
  167. otherCenter: 0
  168. };
  169. },
  170. handleSubmit(e) {
  171. e.preventDefault();
  172. this.props.form.validateFields((err, values) => {
  173. //地址值
  174. let cmbP = document.getElementById('cmbProvince').value;
  175. let cmbC = document.getElementById('cmbCity').value;
  176. let cmbA = document.getElementById('cmbArea').value;
  177. //
  178. let leftPicArr = [];
  179. this.state.companyLifePicObj.map(function (item) {
  180. leftPicArr.push(item.response.data);
  181. });
  182. let lifePhotoUrl = leftPicArr.join(",");
  183. if (!err) {
  184. this.props.spinState(true);
  185. $.ajax({
  186. method: "POST",
  187. dataType: "json",
  188. crossDomain: false,
  189. url: globalConfig.context + "/api/user/orgPro",
  190. data: {
  191. "info.identityType": values.identityType,
  192. "info.companyName": values.unitName,
  193. "info.locationProvince": cmbP,
  194. "info.locationCity": cmbC,
  195. "info.locationArea": cmbA,
  196. "info.unitSize": values.unitNumber,
  197. "info.companyIntroduction": values.unitIntro,
  198. "info.homeUnit": values.unitFrom,
  199. "info.logoUrl": this.state.companyLogoUrl,
  200. "info.publicityPictureUrl": lifePhotoUrl,
  201. "pro.qualification": values.qiyezizhi,
  202. "pro.turnover": values.turnover,
  203. "pro.collegeAttribute": values.schoolProp,
  204. "pro.collegeEstablishTime": values.schoolTime,
  205. "pro.academician": this.state.aca,
  206. "pro.doctoralTutor": this.state.PhDTutor,
  207. "pro.masterTutor": this.state.MSTutor,
  208. "pro.otherExpert": this.state.otherExperts,
  209. "pro.nationalLab": this.state.StateKeyLab,
  210. "pro.educationLab": this.state.EduKeyLab,
  211. "pro.enterpriseCenter": this.state.ComCenter,
  212. "pro.otherCenter": this.state.otherCenter,
  213. "pro.institutionEstablishTime": values.resTime
  214. }
  215. }).done(function (data) {
  216. if (!data.error.length) {
  217. message.success('保存成功!');
  218. } else {
  219. message.warning(data.error[0].message);
  220. }
  221. }.bind(this)).always(function () {
  222. this.props.spinState(false);
  223. }.bind(this));
  224. }
  225. });
  226. },
  227. idttTypeChange(e) {
  228. if (e === '企业') {
  229. this.props.form.setFieldsValue({ 'indentityType': e });
  230. this.setState({
  231. companyDis: 'block',
  232. schoolDis: 'none',
  233. resDis: 'none'
  234. });
  235. } else if (e === '院校') {
  236. this.props.form.setFieldsValue({ 'indentityType': e });
  237. this.setState({
  238. companyDis: 'none',
  239. schoolDis: 'block',
  240. resDis: 'none'
  241. });
  242. } else if (e === '研究机构') {
  243. this.props.form.setFieldsValue({ 'indentityType': e });
  244. this.setState({
  245. companyDis: 'none',
  246. schoolDis: 'none',
  247. resDis: 'block'
  248. });
  249. } else {
  250. this.props.form.setFieldsValue({ 'indentityType': e });
  251. this.setState({
  252. companyDis: 'none',
  253. schoolDis: 'none',
  254. resDis: 'none'
  255. });
  256. }
  257. },
  258. downloadPic(type) {
  259. window.open(globalConfig.context + "/open/downLoadPicture?path="+type)
  260. },
  261. companyLogoUrl(e) {
  262. this.state.companyLogoUrl = e;
  263. },
  264. companyLifePicUrl(e) {
  265. this.state.companyLifePicObj = e;
  266. },
  267. componentDidMount() {
  268. addressInit('cmbProvince', 'cmbCity', 'cmbArea');
  269. this.getData();
  270. },
  271. render() {
  272. const FormItem = Form.Item;
  273. const Option = Select.Option;
  274. const edulvlArr = ["企业", "院校", "研究机构", "政府部门", "非法人团体"];
  275. const zizhiArr = ["高新技术型企业", "创新型企业", "双软企业", "小心微利企业", "科技部认定示范企业", "其他"];
  276. const schoolArr = ["普通本科院校", "高职专科院校", "独立学院", "中央部署院校", "地方所属院校", "211工程院校", "985工程院校"];
  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. {...formItemLayout}
  326. label="单位规模"
  327. >
  328. {getFieldDecorator('unitNumber', {
  329. initialValue: this.state.unitNumber
  330. })(
  331. <InputNumber />
  332. )}
  333. <span>人</span>
  334. </FormItem>
  335. <FormItem
  336. labelCol={{ span: 3 }}
  337. wrapperCol={{ span: 20 }}
  338. label="单位简介"
  339. >
  340. {getFieldDecorator('unitIntro', {
  341. initialValue: this.state.unitIntro
  342. })(
  343. <Input type="textarea"
  344. placeholder="全面介绍自己,让商友更深入了解您,内容长度不超过1000个字。"
  345. rows={6} />
  346. )}
  347. <p>还可输入{
  348. (() => {
  349. if (_me.props.form.getFieldValue('intro') && _me.props.form.getFieldValue('intro').length) {
  350. return 1000 - _me.props.form.getFieldValue('intro').length;
  351. } else {
  352. return 1000;
  353. }
  354. })()
  355. }字/1000</p>
  356. </FormItem>
  357. <FormItem
  358. {...formItemLayout}
  359. label="归属单位"
  360. >
  361. {getFieldDecorator('unitFrom', {
  362. initialValue: this.state.unitFrom
  363. })(
  364. <Input placeholder="非法人单位填写。" />
  365. )}
  366. </FormItem>
  367. <FormItem style={{ 'display': this.state.companyDis }}
  368. labelCol={{ span: 3 }}
  369. wrapperCol={{ span: 8 }}
  370. label="企业资质"
  371. >
  372. {getFieldDecorator('qiyezizhi', {
  373. initialValue: this.state.qiyezizhi
  374. })(
  375. <Select className="acc-edu-lvl">
  376. {
  377. zizhiArr.map(function (item, i) {
  378. return <Option key={i} value={item} >{item}</Option>
  379. })
  380. }
  381. </Select>
  382. )}
  383. </FormItem>
  384. <FormItem style={{ 'display': this.state.companyDis }}
  385. labelCol={{ span: 3 }}
  386. wrapperCol={{ span: 6 }}
  387. label="年营业额"
  388. >
  389. {getFieldDecorator('turnover', {
  390. initialValue: this.state.turnover
  391. })(
  392. <InputNumber />
  393. )}
  394. <span>万元</span>
  395. </FormItem>
  396. <FormItem style={{ 'display': this.state.schoolDis }}
  397. labelCol={{ span: 3 }}
  398. wrapperCol={{ span: 8 }}
  399. label="院校属性"
  400. >
  401. {getFieldDecorator('schoolProp', {
  402. initialValue: this.state.schoolProp
  403. })(
  404. <Select className="acc-edu-lvl">
  405. {
  406. schoolArr.map(function (item, i) {
  407. return <Option key={i} value={item} >{item}</Option>
  408. })
  409. }
  410. </Select>
  411. )}
  412. </FormItem>
  413. <FormItem style={{ 'display': this.state.schoolDis }}
  414. {...formItemLayout}
  415. label="创办时间"
  416. >
  417. {getFieldDecorator('schoolTime', {
  418. initialValue: this.state.schoolTime
  419. })(
  420. <InputNumber />
  421. )}
  422. <span>年</span>
  423. </FormItem>
  424. <FormItem style={{ 'display': this.state.schoolDis }}
  425. labelCol={{ span: 3 }}
  426. wrapperCol={{ span: 21, offset: 3 }}
  427. label=""
  428. >
  429. <div className="school-props clearfix">
  430. <div><span>院士:</span><InputNumber value={this.state.aca} onChange={function (e) { this.setState({ aca: e }) }.bind(this)} />人</div>
  431. <div><span>博士生导师:</span><InputNumber value={this.state.PhDTutor} onChange={function (e) { this.setState({ PhDTutor: e }) }.bind(this)} />人</div>
  432. <div><span>硕士生导师:</span><InputNumber value={this.state.MSTutor} onChange={function (e) { this.setState({ MSTutor: e }) }.bind(this)} />人</div>
  433. <div><span>其他专家:</span><InputNumber value={this.state.otherExperts} onChange={function (e) { this.setState({ otherExperts: e }) }.bind(this)} />人</div>
  434. <div><span>国家级重点实验室:</span><InputNumber value={this.state.StateKeyLab} onChange={function (e) { this.setState({ StateKeyLab: e }) }.bind(this)} />所</div>
  435. <div><span>教育部重点实验室:</span><InputNumber value={this.state.EduKeyLab} onChange={function (e) { this.setState({ EduKeyLab: e }) }.bind(this)} />所</div>
  436. <div><span>企业共建研究中心:</span><InputNumber value={this.state.ComCenter} onChange={function (e) { this.setState({ ComCenter: e }) }.bind(this)} />所</div>
  437. <div><span>其他研究中心:</span><InputNumber value={this.state.otherCenter} onChange={function (e) { this.setState({ otherCenter: e }) }.bind(this)} />所</div>
  438. </div>
  439. </FormItem>
  440. <FormItem style={{ 'display': this.state.resDis }}
  441. {...formItemLayout}
  442. label="创办时间"
  443. >
  444. {getFieldDecorator('resTime', {
  445. initialValue: this.state.resTime
  446. })(
  447. <InputNumber />
  448. )}
  449. <span>年</span>
  450. </FormItem>
  451. <FormItem
  452. {...formItemLayout}
  453. label="LOGO"
  454. labelCol={{ span: 3 }}
  455. wrapperCol={{ span: 20 }}
  456. >
  457. {getFieldDecorator('avatar')(
  458. <Avatar name="companyLogo" urlData={this.companyLogoUrl} />
  459. )}
  460. </FormItem>
  461. <div className="set-explain">
  462. <p>上传的照片图片格式应为jpg格式,大小在2M以内</p>
  463. </div>
  464. <FormItem
  465. labelCol={{ span: 3 }}
  466. wrapperCol={{ span: 21 }}
  467. label="宣传图片"
  468. >
  469. {getFieldDecorator('companyLifePic')(
  470. <PicturesWall fileList={this.companyLifePicUrl} lifePhotoList={this.state.companyLifePicUrl} />
  471. )}
  472. </FormItem>
  473. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  474. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  475. </FormItem>
  476. </Form >
  477. );
  478. },
  479. }));
  480. const Person = React.createClass({
  481. getInitialState() {
  482. return {
  483. loading: false
  484. };
  485. },
  486. spinChange(e) {
  487. this.setState({
  488. loading: e
  489. });
  490. },
  491. render() {
  492. return (
  493. <Spin spinning={this.state.loading} className='spin-box'>
  494. <div className="set-person">
  495. <div className="acc-detail">
  496. <p className="acc-title">单位资料</p>
  497. <PersonFrom spinState={this.spinChange} />
  498. </div>
  499. </div>
  500. </Spin>
  501. )
  502. }
  503. });
  504. export default Person;