edu.jsx 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. xueweiPicUrl : '',
  91. xueliPicUrl : ''
  92. };
  93. },
  94. componentDidMount() {
  95. this.getData();
  96. },
  97. handleSubmit(e) {
  98. e.preventDefault();
  99. this.props.form.validateFields((err, values) => {
  100. if (!err) {
  101. this.props.spinState(true);
  102. $.ajax({
  103. method: "POST",
  104. dataType: "json",
  105. crossDomain: false,
  106. url: globalConfig.context + "/api/user/userEdu",
  107. data: {
  108. "education": values.edulvl,
  109. "majorCategory": this.state.eduPfsA,
  110. "majorName": this.state.eduPfsB,
  111. "graduateSchool": values.schoolname,
  112. "graduationTimeYear": this.state.graduationTimeYear,
  113. "diplomaUrl": this.state.xueliPicUrl,
  114. "diplomaCode": values.edunum,
  115. "degreeDiplomaUrl": this.state.xueweiPicUrl,
  116. "degreeCode": values.degreenum
  117. }
  118. }).done(function (data) {
  119. if (!data.error.length) {
  120. message.success('保存成功!');
  121. } else {
  122. message.warning(data.error[0].message);
  123. }
  124. }.bind(this)).always(function () {
  125. this.props.spinState(false);
  126. }.bind(this));
  127. }
  128. });
  129. },
  130. downloadPic(type) {
  131. window.open(globalConfig.context + "/open/downLoadPicture?path="+type)
  132. },
  133. handleyear(e) {
  134. this.state.graduationTimeYear = e;
  135. },
  136. xueliPicUrl(e) {
  137. this.state.xueliPicUrl = e;
  138. },
  139. xueweiPicUrl(e) {
  140. this.state.xueweiPicUrl = e;
  141. },
  142. professional(e1, e2) {
  143. this.state.eduPfsA = e1;
  144. this.state.eduPfsB = e2;
  145. },
  146. render() {
  147. const { getFieldDecorator } = this.props.form;
  148. const formItemLayout = {
  149. labelCol: { span: 4 },
  150. wrapperCol: { span: 12 },
  151. };
  152. const _me = this;
  153. return (
  154. <Form horizontal onSubmit={this.handleSubmit} className="edu-form">
  155. <FormItem
  156. labelCol={{ span: 4 }}
  157. wrapperCol={{ span: 6 }}
  158. label="学历"
  159. >
  160. {getFieldDecorator('edulvl', {
  161. initialValue: this.state.edulvl || null
  162. })(
  163. <Select className="acc-edu-lvl">
  164. {
  165. edulvlArr.map(function (item, i) {
  166. return <Option key={i} value={item} >{item}</Option>
  167. })
  168. }
  169. </Select>
  170. )}
  171. </FormItem>
  172. <FormItem
  173. {...formItemLayout}
  174. label="专业"
  175. >
  176. {getFieldDecorator('edupfs')(
  177. <EduPfsSelect defValue={this.state.eduPfs} Professional={this.professional} />
  178. )}
  179. </FormItem>
  180. <FormItem
  181. {...formItemLayout}
  182. label="毕业学校"
  183. >
  184. {getFieldDecorator('schoolname', {
  185. initialValue: this.state.schoolname || null
  186. })(
  187. <Input />
  188. )}
  189. </FormItem>
  190. <FormItem
  191. {...formItemLayout}
  192. labelCol={{ span: 4 }}
  193. wrapperCol={{ span: 4 }}
  194. label="毕业时间"
  195. >
  196. {getFieldDecorator('graduationTimeYear')(
  197. <YearSelect defValue={this.state.graduationTimeYear || null} handleyear={this.handleyear} />
  198. )}
  199. </FormItem>
  200. <FormItem
  201. {...formItemLayout}
  202. label="学历证书"
  203. >
  204. {getFieldDecorator('xueliPic')(
  205. <Avatar name="xueliPic" urlData={this.xueliPicUrl} />
  206. )}
  207. <p>{ this.state.xueliPicUrl !== "" ? <Button onClick={this.downloadPic.bind(this,this.state.xueliPicUrl)}>下载证书</Button> : ""}</p>
  208. </FormItem>
  209. <FormItem
  210. {...formItemLayout}
  211. label="学历证书编号"
  212. >
  213. {getFieldDecorator('edunum', {
  214. initialValue: this.state.edunum || null
  215. })(
  216. <Input />
  217. )}
  218. </FormItem>
  219. <FormItem
  220. {...formItemLayout}
  221. label="学位证书"
  222. hasFeedback
  223. >
  224. {getFieldDecorator('xueweiPic')(
  225. <Avatar name="xueweiPic" urlData={this.xueweiPicUrl} />
  226. )}
  227. <p>{this.state.xueweiPicUrl !== "" ? <Button onClick={this.downloadPic.bind(this,this.state.xueweiPicUrl)}>下载证书</Button> : ""}</p>
  228. </FormItem>
  229. <FormItem
  230. {...formItemLayout}
  231. label="学位证书编号"
  232. >
  233. {getFieldDecorator('degreenum', {
  234. initialValue: this.state.degreenum || null
  235. })(
  236. <Input />
  237. )}
  238. </FormItem>
  239. <div className="set-explain">
  240. <p>要求2M 以下的jpg、jpeg格式的图片。该资料不会公开展示,仅作为审核材料使用。</p>
  241. </div>
  242. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  243. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  244. </FormItem>
  245. </Form >
  246. );
  247. },
  248. }));
  249. const Person = React.createClass({
  250. getInitialState() {
  251. return {
  252. loading: false
  253. };
  254. },
  255. spinChange(e) {
  256. this.setState({
  257. loading: e
  258. });
  259. },
  260. render() {
  261. return (
  262. <Spin spinning={this.state.loading} className='spin-box'>
  263. <div className="set-edu">
  264. <div className="acc-detail">
  265. <p className="acc-title">最高学历</p>
  266. <EduFrom spinState={this.spinChange} />
  267. </div>
  268. </div>
  269. </Spin>
  270. )
  271. }
  272. });
  273. export default Person;