pfs.jsx 16 KB

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