edu.jsx 10 KB

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