pfs.jsx 16 KB

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