pfs.jsx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. import React from 'react';
  2. import { Input, Button, Form, Select, Upload, Icon, Spin, message, Radio, InputNumber } from 'antd';
  3. import './pfs.less';
  4. import ajax from 'jquery/src/ajax/xhr.js'
  5. import $ from 'jquery/src/ajax';
  6. import YearSelect from '../../yearSelect.jsx';
  7. import { jingli_yuanxiao, jingli_shehui, chengjiu_yuanxiao, chengjiu_shehui } from '../../dataDic.js';
  8. const FormItem = Form.Item;
  9. const RadioButton = Radio.Button;
  10. const RadioGroup = Radio.Group;
  11. function getBase64(img, callback) {
  12. const reader = new FileReader();
  13. reader.addEventListener('load', () => callback(reader.result));
  14. reader.readAsDataURL(img);
  15. };
  16. function beforeUpload(file) {
  17. const isJPG = file.type === 'image/jpeg';
  18. if (!isJPG) {
  19. message.error('You can only upload JPG file!');
  20. }
  21. const isLt2M = file.size / 1024 / 1024 < 2;
  22. if (!isLt2M) {
  23. message.error('Image must smaller than 2MB!');
  24. }
  25. return isJPG && isLt2M;
  26. };
  27. class Avatar extends React.Component {
  28. constructor(props) {
  29. super(props);
  30. this.state = {
  31. imageUrl: '',
  32. propsbool: true,
  33. }
  34. }
  35. handleChange(info) {
  36. if (info.file.status === 'done') {
  37. // Get this url from response in real world.
  38. getBase64(info.file.originFileObj, imageUrl => this.setState({ imageUrl }));
  39. this.props.urlData(info.file.response.data);
  40. }
  41. }
  42. componentWillReceiveProps(nextProps) {
  43. debugger
  44. if (nextProps.picUrl && this.state.propsbool) {
  45. this.state.imageUrl = globalConfig.avatarHost + "/upload" + nextProps.picUrl;
  46. this.state.propsbool = false;
  47. }
  48. }
  49. render() {
  50. const imageUrl = this.state.imageUrl;
  51. return (
  52. <Upload
  53. className="avatar-uploader"
  54. name="avatar"
  55. showUploadList={false}
  56. action={globalConfig.context + "/api/user/avatar/uploadReplace"}
  57. data={{ 'sign': this.props.name }}
  58. beforeUpload={beforeUpload}
  59. onChange={this.handleChange.bind(this)}
  60. >
  61. {
  62. imageUrl ?
  63. <img src={imageUrl} role="presentation" className="avatar" /> :
  64. <Icon type="plus" className="avatar-uploader-trigger" />
  65. }
  66. </Upload>
  67. );
  68. }
  69. };
  70. const PfsFrom = Form.create()(React.createClass({
  71. getData() {
  72. this.props.spinState(true);
  73. $.ajax({
  74. method: "get",
  75. dataType: "json",
  76. url: globalConfig.context + "/api/user/job",
  77. success: function (data) {
  78. if (data.data) {
  79. this.setState({
  80. lingyu: data.data.engagedField,
  81. gongling: data.data.workingAge,
  82. zhichengname: data.data.professionalTitle,
  83. zhichengyear: data.data.professionalTitleGettime,
  84. zhichengPicUrl: data.data.professionalCertificateUrl,
  85. zigename: data.data.qualification,
  86. zigeyear: data.data.qualificationGettime,
  87. zigePicUrl: data.data.qualificationCertificateUrl,
  88. danwei: data.data.workUnit,
  89. touxian: data.data.position,
  90. jingli: data.data.experiences,
  91. chengjiu: data.data.achievement
  92. });
  93. };
  94. }.bind(this),
  95. }).always(function () {
  96. this.props.spinState(false);
  97. }.bind(this));
  98. },
  99. getInitialState() {
  100. return {
  101. loading: false,
  102. zigePicUrl: '',
  103. zhichengPicUrl: ''
  104. };
  105. },
  106. componentWillMount() {
  107. this.getData();
  108. },
  109. handleSubmit(e) {
  110. e.preventDefault();
  111. this.props.form.validateFields((err, values) => {
  112. if (!err) {
  113. this.props.spinState(true);
  114. $.ajax({
  115. method: "POST",
  116. dataType: "json",
  117. crossDomain: false,
  118. url: globalConfig.context + "/api/user/userCareer",
  119. data: {
  120. "engagedField": values.lingyu,
  121. "workingAge": values.gongling,
  122. "professionalTitle": values.zhichengname,
  123. "professionalTitleGettime": this.state.zhichengyear,
  124. "professionalCertificateUrl": this.state.zhichengPicUrl,
  125. "qualification": values.zigename,
  126. "qualificationGettime": this.state.zigeyear,
  127. "qualificationCertificateUrl": this.state.zigePicUrl,
  128. "workUnit": values.danwei,
  129. "position": values.touxian,
  130. "experiences": values.jingli,
  131. "achievement": values.chengjiu
  132. }
  133. }).done(function (data) {
  134. if (!data.error.length) {
  135. message.success('保存成功!');
  136. } else {
  137. message.warning(data.error[0].message);
  138. }
  139. }.bind(this)).always(function () {
  140. this.props.spinState(false);
  141. }.bind(this));
  142. }
  143. });
  144. },
  145. zhichengPic(e) {
  146. this.state.zhichengPicUrl = e;
  147. },
  148. zhichengyear(e) {
  149. this.state.zhichengyear = e;
  150. },
  151. zigePic(e) {
  152. this.state.zigePicUrl = e;
  153. },
  154. zigeyear(e) {
  155. this.state.zigeyear = e;
  156. },
  157. jingliChange(e) {
  158. if (e.target.value == "a") {
  159. this.props.form.setFieldsValue({ 'jingli': this.state.jingli || '' })
  160. } else if (e.target.value == "b") {
  161. this.props.form.setFieldsValue({
  162. 'jingli': jingli_yuanxiao
  163. })
  164. } else if (e.target.value == "c") {
  165. this.props.form.setFieldsValue({
  166. 'jingli': jingli_shehui
  167. })
  168. }
  169. },
  170. chengjiuChange(e) {
  171. if (e.target.value == "a") {
  172. this.props.form.setFieldsValue({ 'chengjiu': this.state.chengjiu || '' })
  173. } else if (e.target.value == "b") {
  174. this.props.form.setFieldsValue({
  175. 'chengjiu': chengjiu_yuanxiao
  176. })
  177. } else if (e.target.value == "c") {
  178. this.props.form.setFieldsValue({
  179. 'chengjiu': chengjiu_shehui
  180. })
  181. }
  182. },
  183. downloadPic(type) {
  184. window.open(globalConfig.context + "/open/downLoadPicture?path=" + type)
  185. },
  186. render() {
  187. const { getFieldDecorator } = this.props.form;
  188. const formItemLayout = {
  189. labelCol: { span: 3 },
  190. wrapperCol: { span: 12 },
  191. };
  192. const _me = this;
  193. return (
  194. <Form horizontal onSubmit={this.handleSubmit} className="pfs-form">
  195. <FormItem
  196. {...formItemLayout}
  197. label="从事领域"
  198. help={'请输入所从事领域的名称,多个领域请以逗号隔开'}
  199. >
  200. {getFieldDecorator('lingyu', {
  201. initialValue: this.state.lingyu || null
  202. })(
  203. <Input />
  204. )}
  205. </FormItem>
  206. <FormItem
  207. labelCol={{ span: 3 }}
  208. wrapperCol={{ span: 4 }}
  209. label="从业工龄"
  210. >
  211. {getFieldDecorator('gongling', {
  212. initialValue: this.state.gongling
  213. })(
  214. <InputNumber />
  215. )}
  216. <span>年</span>
  217. </FormItem>
  218. <FormItem
  219. {...formItemLayout}
  220. label="职称名字"
  221. >
  222. {getFieldDecorator('zhichengname', {
  223. initialValue: this.state.zhichengname || null
  224. })(
  225. <Input />
  226. )}
  227. </FormItem>
  228. <FormItem
  229. labelCol={{ span: 3 }}
  230. wrapperCol={{ span: 6 }}
  231. label="取得时间"
  232. hasFeedback
  233. >
  234. {getFieldDecorator('zhichengyear')(
  235. <YearSelect defValue={this.state.zhichengyear} handleyear={this.zhichengyear} />
  236. )}
  237. </FormItem>
  238. <FormItem
  239. {...formItemLayout}
  240. label="职称证书"
  241. hasFeedback
  242. >
  243. {getFieldDecorator('zhichengPic')(
  244. <Avatar name="zhichengPic" urlData={this.zhichengPic} picUrl={this.state.zhichengPicUrl}/>
  245. )}
  246. </FormItem>
  247. <div className="set-explain">
  248. <p>要求2M 以下的jpg、jpeg格式的图片。该资料不会公开展示,仅作为审核材料使用。</p>
  249. <p>{this.state.zhichengPicUrl !== "" ? <Button onClick={this.downloadPic.bind(this, this.state.zhichengPicUrl)}>下载证书</Button> : ""}</p>
  250. </div>
  251. <FormItem
  252. {...formItemLayout}
  253. label="执业资格"
  254. >
  255. {getFieldDecorator('zigename', {
  256. initialValue: this.state.zigename
  257. })(
  258. <Input />
  259. )}
  260. </FormItem>
  261. <FormItem
  262. labelCol={{ span: 3 }}
  263. wrapperCol={{ span: 6 }}
  264. label="取得时间"
  265. hasFeedback
  266. >
  267. {getFieldDecorator('zigeyear')(
  268. <YearSelect defValue={this.state.zigeyear} handleyear={this.zigeyear} />
  269. )}
  270. </FormItem>
  271. <FormItem
  272. {...formItemLayout}
  273. label="资格证明"
  274. hasFeedback
  275. >
  276. {getFieldDecorator('zigePic')(
  277. <Avatar name="zigePic" urlData={this.zigePic} picUrl={this.state.zigePicUrl}/>
  278. )}
  279. </FormItem>
  280. <div className="set-explain">
  281. <p>要求2M 以下的jpg、jpeg格式的图片。该资料不会公开展示,仅作为审核材料使用。</p>
  282. <p>{this.state.zigePicUrl !== "" ? <Button onClick={this.downloadPic.bind(this, this.state.zigePicUrl)}>下载证书</Button> : ""}</p>
  283. </div>
  284. <FormItem
  285. {...formItemLayout}
  286. label="工作单位"
  287. >
  288. {getFieldDecorator('danwei', {
  289. initialValue: this.state.danwei || null
  290. })(
  291. <Input />
  292. )}
  293. </FormItem>
  294. <FormItem
  295. {...formItemLayout}
  296. label="职位头衔"
  297. >
  298. {getFieldDecorator('touxian', {
  299. initialValue: this.state.touxian || null
  300. })(
  301. <Input />
  302. )}
  303. </FormItem>
  304. <div className="textarea-title">
  305. <span>从业经历</span>
  306. <RadioGroup className="set-radio-button" onChange={this.jingliChange} defaultValue="a">
  307. <RadioButton value="a">自定义</RadioButton>
  308. <RadioButton value="b">院校专家模板</RadioButton>
  309. <RadioButton value="c">企业或社会专家模板</RadioButton>
  310. </RadioGroup>
  311. </div>
  312. <div className="set-explain">
  313. <p>您可使用模板直接编辑调整!</p>
  314. </div>
  315. <FormItem
  316. labelCol={{ span: 3 }}
  317. wrapperCol={{ span: 20, offset: 3 }}
  318. help={
  319. <div>
  320. <p>还可输入{
  321. (() => {
  322. if (_me.props.form.getFieldValue('jingli') && _me.props.form.getFieldValue('jingli').length) {
  323. return 1000 - _me.props.form.getFieldValue('jingli').length;
  324. } else {
  325. return 1000;
  326. }
  327. })()
  328. }字/1000</p>
  329. <p>描述您主要的从业履历,包括职业,最有亮点的社会兼职。可自定义或选择模板后直接编辑</p>
  330. </div>
  331. }
  332. label=""
  333. >
  334. {getFieldDecorator('jingli', {
  335. initialValue: this.state.jingli || null
  336. })(
  337. <Input type="textarea"
  338. rows={6} />
  339. )}
  340. </FormItem>
  341. <div className="textarea-title">
  342. <span>个人成就</span>
  343. <RadioGroup className="set-radio-button" onChange={this.chengjiuChange} defaultValue="a">
  344. <RadioButton value="a">自定义</RadioButton>
  345. <RadioButton value="b">院校专家模板</RadioButton>
  346. <RadioButton value="c">企业或社会专家模板</RadioButton>
  347. </RadioGroup>
  348. </div>
  349. <div className="set-explain">
  350. <p>您可使用模板直接编辑调整!</p>
  351. </div>
  352. <FormItem
  353. labelCol={{ span: 3 }}
  354. wrapperCol={{ span: 20, offset: 3 }}
  355. help={
  356. <div>
  357. <p>还可输入{
  358. (() => {
  359. if (_me.props.form.getFieldValue('chengjiu') && _me.props.form.getFieldValue('chengjiu').length) {
  360. return 1000 - _me.props.form.getFieldValue('chengjiu').length;
  361. } else {
  362. return 1000;
  363. }
  364. })()
  365. }字/1000</p>
  366. <p>描述您主要的从业履历,包括职业,最有亮点的社会兼职。可自定义或选择模板后直接编辑</p>
  367. </div>
  368. }
  369. label=""
  370. >
  371. {getFieldDecorator('chengjiu', {
  372. initialValue: this.state.chengjiu || null
  373. })(
  374. <Input type="textarea"
  375. rows={6} />
  376. )}
  377. </FormItem>
  378. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  379. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  380. </FormItem>
  381. </Form >
  382. );
  383. },
  384. }));
  385. const Pfs = React.createClass({
  386. getInitialState() {
  387. return {
  388. loading: false
  389. };
  390. },
  391. spinChange(e) {
  392. this.setState({
  393. loading: e
  394. });
  395. },
  396. render() {
  397. return (
  398. <Spin spinning={this.state.loading} className='spin-box'>
  399. <div className="set-pfs">
  400. <div className="acc-detail">
  401. <p className="acc-title">职业信息</p>
  402. <PfsFrom spinState={this.spinChange} />
  403. </div>
  404. </div>
  405. </Spin>
  406. )
  407. }
  408. });
  409. export default Pfs;