edu.jsx 10 KB

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