company.jsx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  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. $.ajax({
  260. method: "post",
  261. dataType: "json",
  262. url: globalConfig.context + "/open/downLoadPicture",
  263. data: {
  264. path: type,
  265. isPrivate: true
  266. },
  267. success: function (data) {
  268. }.bind(this),
  269. });
  270. },
  271. companyLogoUrl(e) {
  272. this.state.companyLogoUrl = e;
  273. },
  274. companyLifePicUrl(e) {
  275. this.state.companyLifePicObj = e;
  276. },
  277. componentDidMount() {
  278. addressInit('cmbProvince', 'cmbCity', 'cmbArea');
  279. this.getData();
  280. },
  281. render() {
  282. const FormItem = Form.Item;
  283. const Option = Select.Option;
  284. const edulvlArr = ["企业", "院校", "研究机构", "政府部门", "非法人团体"];
  285. const zizhiArr = ["高新技术型企业", "创新型企业", "双软企业", "小心微利企业", "科技部认定示范企业", "其他"];
  286. const schoolArr = ["普通本科院校", "高职专科院校", "独立学院", "中央部署院校", "地方所属院校", "211工程院校", "985工程院校"];
  287. const { getFieldDecorator } = this.props.form;
  288. const formItemLayout = {
  289. labelCol: { span: 3 },
  290. wrapperCol: { span: 12 },
  291. };
  292. const _me = this;
  293. return (
  294. <Form horizontal onSubmit={this.handleSubmit} className="person-form">
  295. <FormItem
  296. labelCol={{ span: 3 }}
  297. wrapperCol={{ span: 8 }}
  298. label="身份类型"
  299. >
  300. {getFieldDecorator('identityType', {
  301. initialValue: this.state.idttType
  302. })(
  303. <Select className="acc-edu-lvl" onChange={this.idttTypeChange}>
  304. {
  305. edulvlArr.map(function (item, i) {
  306. return <Option key={i} value={item} >{item}</Option>
  307. })
  308. }
  309. </Select>
  310. )}
  311. </FormItem>
  312. <FormItem
  313. {...formItemLayout}
  314. label="单位名称"
  315. >
  316. {getFieldDecorator('unitName', {
  317. initialValue: this.state.unitName
  318. })(
  319. <Input />
  320. )}
  321. </FormItem>
  322. <FormItem
  323. {...formItemLayout}
  324. label="所在地"
  325. >
  326. {getFieldDecorator('province')(
  327. <div>
  328. <select id="cmbProvince" name="cmbProvince"></select>
  329. <select id="cmbCity" name="cmbCity"></select>
  330. <select id="cmbArea" name="cmbArea"></select>
  331. </div>
  332. )}
  333. </FormItem>
  334. <FormItem
  335. {...formItemLayout}
  336. label="单位规模"
  337. >
  338. {getFieldDecorator('unitNumber', {
  339. initialValue: this.state.unitNumber
  340. })(
  341. <InputNumber />
  342. )}
  343. <span>人</span>
  344. </FormItem>
  345. <FormItem
  346. labelCol={{ span: 3 }}
  347. wrapperCol={{ span: 20 }}
  348. label="单位简介"
  349. >
  350. {getFieldDecorator('unitIntro', {
  351. initialValue: this.state.unitIntro
  352. })(
  353. <Input type="textarea"
  354. placeholder="全面介绍自己,让商友更深入了解您,内容长度不超过1000个字。"
  355. rows={6} />
  356. )}
  357. <p>还可输入{
  358. (() => {
  359. if (_me.props.form.getFieldValue('intro') && _me.props.form.getFieldValue('intro').length) {
  360. return 1000 - _me.props.form.getFieldValue('intro').length;
  361. } else {
  362. return 1000;
  363. }
  364. })()
  365. }字/1000</p>
  366. </FormItem>
  367. <FormItem
  368. {...formItemLayout}
  369. label="归属单位"
  370. >
  371. {getFieldDecorator('unitFrom', {
  372. initialValue: this.state.unitFrom
  373. })(
  374. <Input placeholder="非法人单位填写。" />
  375. )}
  376. </FormItem>
  377. <FormItem style={{ 'display': this.state.companyDis }}
  378. labelCol={{ span: 3 }}
  379. wrapperCol={{ span: 8 }}
  380. label="企业资质"
  381. >
  382. {getFieldDecorator('qiyezizhi', {
  383. initialValue: this.state.qiyezizhi
  384. })(
  385. <Select className="acc-edu-lvl">
  386. {
  387. zizhiArr.map(function (item, i) {
  388. return <Option key={i} value={item} >{item}</Option>
  389. })
  390. }
  391. </Select>
  392. )}
  393. </FormItem>
  394. <FormItem style={{ 'display': this.state.companyDis }}
  395. labelCol={{ span: 3 }}
  396. wrapperCol={{ span: 6 }}
  397. label="年营业额"
  398. >
  399. {getFieldDecorator('turnover', {
  400. initialValue: this.state.turnover
  401. })(
  402. <InputNumber />
  403. )}
  404. <span>万元</span>
  405. </FormItem>
  406. <FormItem style={{ 'display': this.state.schoolDis }}
  407. labelCol={{ span: 3 }}
  408. wrapperCol={{ span: 8 }}
  409. label="院校属性"
  410. >
  411. {getFieldDecorator('schoolProp', {
  412. initialValue: this.state.schoolProp
  413. })(
  414. <Select className="acc-edu-lvl">
  415. {
  416. schoolArr.map(function (item, i) {
  417. return <Option key={i} value={item} >{item}</Option>
  418. })
  419. }
  420. </Select>
  421. )}
  422. </FormItem>
  423. <FormItem style={{ 'display': this.state.schoolDis }}
  424. {...formItemLayout}
  425. label="创办时间"
  426. >
  427. {getFieldDecorator('schoolTime', {
  428. initialValue: this.state.schoolTime
  429. })(
  430. <InputNumber />
  431. )}
  432. <span>年</span>
  433. </FormItem>
  434. <FormItem style={{ 'display': this.state.schoolDis }}
  435. labelCol={{ span: 3 }}
  436. wrapperCol={{ span: 21, offset: 3 }}
  437. label=""
  438. >
  439. <div className="school-props clearfix">
  440. <div><span>院士:</span><InputNumber value={this.state.aca} onChange={function (e) { this.setState({ aca: e }) }.bind(this)} />人</div>
  441. <div><span>博士生导师:</span><InputNumber value={this.state.PhDTutor} onChange={function (e) { this.setState({ PhDTutor: e }) }.bind(this)} />人</div>
  442. <div><span>硕士生导师:</span><InputNumber value={this.state.MSTutor} onChange={function (e) { this.setState({ MSTutor: e }) }.bind(this)} />人</div>
  443. <div><span>其他专家:</span><InputNumber value={this.state.otherExperts} onChange={function (e) { this.setState({ otherExperts: e }) }.bind(this)} />人</div>
  444. <div><span>国家级重点实验室:</span><InputNumber value={this.state.StateKeyLab} onChange={function (e) { this.setState({ StateKeyLab: e }) }.bind(this)} />所</div>
  445. <div><span>教育部重点实验室:</span><InputNumber value={this.state.EduKeyLab} onChange={function (e) { this.setState({ EduKeyLab: e }) }.bind(this)} />所</div>
  446. <div><span>企业共建研究中心:</span><InputNumber value={this.state.ComCenter} onChange={function (e) { this.setState({ ComCenter: e }) }.bind(this)} />所</div>
  447. <div><span>其他研究中心:</span><InputNumber value={this.state.otherCenter} onChange={function (e) { this.setState({ otherCenter: e }) }.bind(this)} />所</div>
  448. </div>
  449. </FormItem>
  450. <FormItem style={{ 'display': this.state.resDis }}
  451. {...formItemLayout}
  452. label="创办时间"
  453. >
  454. {getFieldDecorator('resTime', {
  455. initialValue: this.state.resTime
  456. })(
  457. <InputNumber />
  458. )}
  459. <span>年</span>
  460. </FormItem>
  461. <FormItem
  462. {...formItemLayout}
  463. label="LOGO"
  464. labelCol={{ span: 3 }}
  465. wrapperCol={{ span: 20 }}
  466. >
  467. {getFieldDecorator('avatar')(
  468. <Avatar name="companyLogo" urlData={this.companyLogoUrl} />
  469. )}
  470. </FormItem>
  471. <div className="set-explain">
  472. <p>上传的照片图片格式应为jpg格式,大小在2M以内</p>
  473. </div>
  474. <FormItem
  475. labelCol={{ span: 3 }}
  476. wrapperCol={{ span: 21 }}
  477. label="宣传图片"
  478. >
  479. {getFieldDecorator('companyLifePic')(
  480. <PicturesWall fileList={this.companyLifePicUrl} lifePhotoList={this.state.companyLifePicUrl} />
  481. )}
  482. </FormItem>
  483. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  484. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  485. </FormItem>
  486. </Form >
  487. );
  488. },
  489. }));
  490. const Person = React.createClass({
  491. getInitialState() {
  492. return {
  493. loading: false
  494. };
  495. },
  496. spinChange(e) {
  497. this.setState({
  498. loading: e
  499. });
  500. },
  501. render() {
  502. return (
  503. <Spin spinning={this.state.loading} className='spin-box'>
  504. <div className="set-person">
  505. <div className="acc-detail">
  506. <p className="acc-title">单位资料</p>
  507. <PersonFrom spinState={this.spinChange} />
  508. </div>
  509. </div>
  510. </Spin>
  511. )
  512. }
  513. });
  514. export default Person;