edu.jsx 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. import React from 'react';
  2. import { Input, Button, Form, Select, Upload, Icon, Spin, message } from 'antd';
  3. import './edu.less';
  4. import ajax from 'jquery/src/ajax/xhr.js'
  5. import $ from 'jquery/src/ajax';
  6. import EduPfsSelect from './eduPfsSelect.jsx';
  7. import YearSelect from '../../yearSelect.jsx';
  8. const FormItem = Form.Item;
  9. const Option = Select.Option;
  10. const edulvlArr = ["博士研究生", "硕士研究生", "本科", "大专及以下"];
  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 EduFrom = 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/educate",
  69. success: function (data) {
  70. if (data.data) {
  71. this.setState({
  72. edulvl: data.data.education,
  73. eduPfs: [parseInt(data.data.majorCategory), parseInt(data.data.majorName)],
  74. schoolname: data.data.graduateSchool,
  75. graduationTimeYear: data.data.graduationTimeYear,
  76. edunum: data.data.diplomaCode,
  77. degreenum: data.data.degreeCode,
  78. xueliPicUrl: data.data.diplomaUrl,
  79. xueweiPicUrl: data.data.degreeDiplomaUrl
  80. });
  81. };
  82. }.bind(this),
  83. }).always(function () {
  84. this.props.spinState(false);
  85. }.bind(this));
  86. },
  87. getInitialState() {
  88. return {
  89. loading: false,
  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. "education": values.edulvl,
  107. "majorCategory": this.state.eduPfsA,
  108. "majorName": this.state.eduPfsB,
  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. } else {
  120. message.warning(data.error[0].message);
  121. }
  122. }.bind(this)).always(function () {
  123. this.props.spinState(false);
  124. }.bind(this));
  125. }
  126. });
  127. },
  128. downloadPic(type) {
  129. window.open(globalConfig.context + "/open/downLoadPicture?path="+type)
  130. },
  131. handleyear(e) {
  132. this.state.graduationTimeYear = e;
  133. },
  134. xueliPicUrl(e) {
  135. this.state.xueliPicUrl = e;
  136. },
  137. xueweiPicUrl(e) {
  138. this.state.xueweiPicUrl = e;
  139. },
  140. professional(e1, e2) {
  141. this.state.eduPfsA = e1;
  142. this.state.eduPfsB = e2;
  143. },
  144. render() {
  145. const { getFieldDecorator } = this.props.form;
  146. const formItemLayout = {
  147. labelCol: { span: 4 },
  148. wrapperCol: { span: 12 },
  149. };
  150. const _me = this;
  151. return (
  152. <Form horizontal onSubmit={this.handleSubmit} className="edu-form">
  153. <FormItem
  154. labelCol={{ span: 4 }}
  155. wrapperCol={{ span: 6 }}
  156. label="学历"
  157. >
  158. {getFieldDecorator('edulvl', {
  159. initialValue: this.state.edulvl || null
  160. })(
  161. <Select className="acc-edu-lvl">
  162. {
  163. edulvlArr.map(function (item, i) {
  164. return <Option key={i} value={item} >{item}</Option>
  165. })
  166. }
  167. </Select>
  168. )}
  169. </FormItem>
  170. <FormItem
  171. {...formItemLayout}
  172. label="专业"
  173. >
  174. {getFieldDecorator('edupfs')(
  175. <EduPfsSelect defValue={this.state.eduPfs} Professional={this.professional} />
  176. )}
  177. </FormItem>
  178. <FormItem
  179. {...formItemLayout}
  180. label="毕业学校"
  181. >
  182. {getFieldDecorator('schoolname', {
  183. initialValue: this.state.schoolname || null
  184. })(
  185. <Input />
  186. )}
  187. </FormItem>
  188. <FormItem
  189. {...formItemLayout}
  190. labelCol={{ span: 4 }}
  191. wrapperCol={{ span: 4 }}
  192. label="毕业时间"
  193. >
  194. {getFieldDecorator('graduationTimeYear')(
  195. <YearSelect defValue={this.state.graduationTimeYear || null} handleyear={this.handleyear} />
  196. )}
  197. </FormItem>
  198. <FormItem
  199. {...formItemLayout}
  200. label="学历证书"
  201. >
  202. {getFieldDecorator('xueliPic')(
  203. <Avatar name="xueliPic" urlData={this.xueliPicUrl} />
  204. )}
  205. <p>{this.state.xueweiPicUrl !== "" ? <Button onClick={this.downloadPic.bind(this,this.state.xueliPicUrl)}>下载证书</Button> : ""}</p>
  206. </FormItem>
  207. <FormItem
  208. {...formItemLayout}
  209. label="学历证书编号"
  210. >
  211. {getFieldDecorator('edunum', {
  212. initialValue: this.state.edunum || null
  213. })(
  214. <Input />
  215. )}
  216. </FormItem>
  217. <FormItem
  218. {...formItemLayout}
  219. label="学位证书"
  220. hasFeedback
  221. >
  222. {getFieldDecorator('xueweiPic')(
  223. <Avatar name="xueweiPic" urlData={this.xueweiPicUrl} />
  224. )}
  225. <p>{this.state.xueweiPicUrl !== "" ? <Button onClick={this.downloadPic.bind(this,this.state.xueweiPicUrl)}>下载证书</Button> : ""}</p>
  226. </FormItem>
  227. <FormItem
  228. {...formItemLayout}
  229. label="学位证书编号"
  230. >
  231. {getFieldDecorator('degreenum', {
  232. initialValue: this.state.degreenum || null
  233. })(
  234. <Input />
  235. )}
  236. </FormItem>
  237. <div className="set-explain">
  238. <p>要求2M 以下的jpg、jpeg格式的图片。该资料不会公开展示,仅作为审核材料使用。</p>
  239. </div>
  240. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  241. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  242. </FormItem>
  243. </Form >
  244. );
  245. },
  246. }));
  247. const Person = React.createClass({
  248. getInitialState() {
  249. return {
  250. loading: false
  251. };
  252. },
  253. spinChange(e) {
  254. this.setState({
  255. loading: e
  256. });
  257. },
  258. render() {
  259. return (
  260. <Spin spinning={this.state.loading} className='spin-box'>
  261. <div className="set-edu">
  262. <div className="acc-detail">
  263. <p className="acc-title">最高学历</p>
  264. <EduFrom spinState={this.spinChange} />
  265. </div>
  266. </div>
  267. </Spin>
  268. )
  269. }
  270. });
  271. export default Person;