edu.jsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. import React from 'react';
  2. import { Input, Button, Form, Select, Upload, Icon, Spin, message, Cascader } from 'antd';
  3. import './edu.less';
  4. import { edulvlArr } from '../../dataDic.js';
  5. import ajax from 'jquery/src/ajax/xhr.js'
  6. import $ from 'jquery/src/ajax';
  7. import { techFieldList } from '../../DicTechFieldList';
  8. import { getBase64, beforeUpload } from '../../tools'
  9. import YearSelect from '../../yearSelect.jsx';
  10. const FormItem = Form.Item;
  11. const Option = Select.Option;
  12. class Avatar extends React.Component {
  13. constructor(props) {
  14. super(props);
  15. this.state = {
  16. imageUrl: '',
  17. propsbool: true,
  18. }
  19. }
  20. handleChange (info) {
  21. if (info.file.status === 'done') {
  22. // Get this url from response in real world.
  23. getBase64(info.file.originFileObj, imageUrl => this.setState({ imageUrl }));
  24. this.props.urlData(info.file.response.data);
  25. }
  26. }
  27. componentWillReceiveProps (nextProps) {
  28. if (nextProps.picUrl && this.state.propsbool) {
  29. this.state.imageUrl = globalConfig.context + "/open/downLoadPicture?path=" + nextProps.picUrl;
  30. this.state.propsbool = false;
  31. }
  32. }
  33. render () {
  34. const imageUrl = this.state.imageUrl;
  35. return (
  36. <Upload
  37. className="avatar-uploader"
  38. name="avatar"
  39. showUploadList={false}
  40. action={globalConfig.context + "/api/user/identity/upload"}
  41. data={{ 'sign': this.props.name }}
  42. beforeUpload={beforeUpload}
  43. onChange={this.handleChange.bind(this)}
  44. >
  45. {
  46. imageUrl ?
  47. <img src={imageUrl} role="presentation" className="avatar" /> :
  48. <Icon type="plus" className="avatar-uploader-trigger" />
  49. }
  50. </Upload>
  51. );
  52. }
  53. };
  54. const EduFrom = Form.create()(React.createClass({
  55. getData () {
  56. this.props.spinState(true);
  57. $.ajax({
  58. method: "get",
  59. dataType: "json",
  60. url: globalConfig.context + "/api/user/educate",
  61. success: function (data) {
  62. if (data.error && data.error.length) {
  63. message.warning(data.error[0].message);
  64. } else {
  65. if (data.data) {
  66. this.setState({
  67. id: data.data.id,
  68. edulvl: data.data.education,
  69. eduPfs: data.data.majorCategory ? data.data.majorCategory.split(',') : [],
  70. schoolname: data.data.graduateSchool,
  71. graduationTimeYear: data.data.graduationTimeYear,
  72. edunum: data.data.diplomaCode,
  73. degreenum: data.data.degreeCode,
  74. xueliPicUrl: data.data.diplomaUrl,
  75. xueweiPicUrl: data.data.degreeDiplomaUrl
  76. });
  77. };
  78. };
  79. }.bind(this),
  80. }).always(function () {
  81. this.props.spinState(false);
  82. }.bind(this));
  83. },
  84. getInitialState () {
  85. return {
  86. loading: false,
  87. xueweiPicUrl: '',
  88. xueliPicUrl: '',
  89. eduPfs: []
  90. };
  91. },
  92. componentDidMount () {
  93. this.getData();
  94. },
  95. handleSubmit (e) {
  96. e.preventDefault();
  97. this.props.form.validateFields((err, values) => {
  98. if (!err) {
  99. this.props.spinState(true);
  100. $.ajax({
  101. method: "POST",
  102. dataType: "json",
  103. crossDomain: false,
  104. url: globalConfig.context + "/api/user/userEdu",
  105. data: {
  106. "id": this.state.id,
  107. "education": values.edulvl,
  108. "majorCategory": values.eduPfs.join(','),
  109. "graduateSchool": values.schoolname,
  110. "graduationTimeYear": this.state.graduationTimeYear,
  111. "diplomaUrl": this.state.xueliPicUrl,
  112. "diplomaCode": values.edunum,
  113. "degreeDiplomaUrl": this.state.xueweiPicUrl,
  114. "degreeCode": values.degreenum
  115. }
  116. }).done(function (data) {
  117. if (!data.error.length) {
  118. message.success('保存成功!');
  119. this.getData();
  120. } else {
  121. message.warning(data.error[0].message);
  122. }
  123. }.bind(this)).always(function () {
  124. this.props.spinState(false);
  125. }.bind(this));
  126. }
  127. });
  128. },
  129. downloadPic (type) {
  130. window.open(globalConfig.context + "/open/downLoadPicture?path=" + type)
  131. },
  132. handleyear (e) {
  133. this.state.graduationTimeYear = e;
  134. },
  135. xueliPicUrl (e) {
  136. this.state.xueliPicUrl = e;
  137. },
  138. xueweiPicUrl (e) {
  139. this.state.xueweiPicUrl = e;
  140. },
  141. render () {
  142. const { getFieldDecorator } = this.props.form;
  143. const formItemLayout = {
  144. labelCol: { span: 4 },
  145. wrapperCol: { span: 12 },
  146. };
  147. const _me = this;
  148. return (
  149. <Form horizontal onSubmit={this.handleSubmit} className="edu-form">
  150. <FormItem
  151. labelCol={{ span: 4 }}
  152. wrapperCol={{ span: 6 }}
  153. label="学历"
  154. >
  155. {getFieldDecorator('edulvl', {
  156. initialValue: this.state.edulvl || null
  157. })(
  158. <Select className="acc-edu-lvl">
  159. {
  160. edulvlArr.map(function (item, i) {
  161. return <Option key={i} value={item} >{item}</Option>
  162. })
  163. }
  164. </Select>
  165. )}
  166. </FormItem>
  167. <FormItem
  168. {...formItemLayout}
  169. label="专业领域"
  170. >
  171. {getFieldDecorator('eduPfs', {
  172. initialValue: this.state.eduPfs || []
  173. })(
  174. <Cascader placeholder="请选择专业领域" options={techFieldList} style={{ width: 300 }} />
  175. )}
  176. </FormItem>
  177. <FormItem
  178. {...formItemLayout}
  179. label="毕业学校"
  180. >
  181. {getFieldDecorator('schoolname', {
  182. initialValue: this.state.schoolname || null
  183. })(
  184. <Input />
  185. )}
  186. </FormItem>
  187. <FormItem
  188. {...formItemLayout}
  189. labelCol={{ span: 4 }}
  190. wrapperCol={{ span: 4 }}
  191. label="毕业时间"
  192. >
  193. {getFieldDecorator('graduationTimeYear')(
  194. <YearSelect defValue={this.state.graduationTimeYear || null} handleyear={this.handleyear} />
  195. )}
  196. </FormItem>
  197. <FormItem
  198. {...formItemLayout}
  199. label="学历证书"
  200. >
  201. {getFieldDecorator('xueliPic')(
  202. <Avatar name="xueliPic" urlData={this.xueliPicUrl} picUrl={this.state.xueliPicUrl} />
  203. )}
  204. <p>{this.state.xueliPicUrl !== "" ? <Button onClick={this.downloadPic.bind(this, this.state.xueliPicUrl)}>下载证书</Button> : ""}</p>
  205. </FormItem>
  206. <FormItem
  207. {...formItemLayout}
  208. label="学历证书编号"
  209. >
  210. {getFieldDecorator('edunum', {
  211. initialValue: this.state.edunum || null
  212. })(
  213. <Input />
  214. )}
  215. </FormItem>
  216. <FormItem
  217. {...formItemLayout}
  218. label="学位证书"
  219. hasFeedback
  220. >
  221. {getFieldDecorator('xueweiPic')(
  222. <Avatar name="xueweiPic" urlData={this.xueweiPicUrl} picUrl={this.state.xueweiPicUrl} />
  223. )}
  224. <p>{this.state.xueweiPicUrl !== "" ? <Button onClick={this.downloadPic.bind(this, this.state.xueweiPicUrl)}>下载证书</Button> : ""}</p>
  225. </FormItem>
  226. <FormItem
  227. {...formItemLayout}
  228. label="学位证书编号"
  229. >
  230. {getFieldDecorator('degreenum', {
  231. initialValue: this.state.degreenum || null
  232. })(
  233. <Input />
  234. )}
  235. </FormItem>
  236. <div className="set-explain">
  237. <p>要求2M 以下的jpg、jpeg格式的图片。该资料不会公开展示,仅作为审核材料使用。</p>
  238. </div>
  239. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  240. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  241. </FormItem>
  242. </Form >
  243. );
  244. },
  245. }));
  246. const Person = React.createClass({
  247. getInitialState () {
  248. return {
  249. loading: false
  250. };
  251. },
  252. spinChange (e) {
  253. this.setState({
  254. loading: e
  255. });
  256. },
  257. render () {
  258. return (
  259. <Spin spinning={this.state.loading} className='spin-box'>
  260. <div className="set-edu">
  261. <div className="acc-detail">
  262. <p className="acc-title">最高学历</p>
  263. <EduFrom spinState={this.spinChange} />
  264. </div>
  265. </div>
  266. </Spin>
  267. )
  268. }
  269. });
  270. export default Person;