edu.jsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. this.getData();
  131. } else {
  132. message.warning(data.error[0].message);
  133. }
  134. }.bind(this)).always(function () {
  135. this.props.spinState(false);
  136. }.bind(this));
  137. }
  138. });
  139. },
  140. downloadPic(type) {
  141. window.open(globalConfig.context + "/open/downLoadPicture?path=" + type)
  142. },
  143. handleyear(e) {
  144. this.state.graduationTimeYear = e;
  145. },
  146. xueliPicUrl(e) {
  147. this.state.xueliPicUrl = e;
  148. },
  149. xueweiPicUrl(e) {
  150. this.state.xueweiPicUrl = e;
  151. },
  152. professional(e1, e2) {
  153. this.state.eduPfsA = e1;
  154. this.state.eduPfsB = e2;
  155. },
  156. render() {
  157. const { getFieldDecorator } = this.props.form;
  158. const formItemLayout = {
  159. labelCol: { span: 4 },
  160. wrapperCol: { span: 12 },
  161. };
  162. const _me = this;
  163. return (
  164. <Form horizontal onSubmit={this.handleSubmit} className="edu-form">
  165. <FormItem
  166. labelCol={{ span: 4 }}
  167. wrapperCol={{ span: 6 }}
  168. label="学历"
  169. >
  170. {getFieldDecorator('edulvl', {
  171. initialValue: this.state.edulvl || null
  172. })(
  173. <Select className="acc-edu-lvl">
  174. {
  175. edulvlArr.map(function (item, i) {
  176. return <Option key={i} value={item} >{item}</Option>
  177. })
  178. }
  179. </Select>
  180. )}
  181. </FormItem>
  182. <FormItem
  183. {...formItemLayout}
  184. label="专业"
  185. >
  186. {getFieldDecorator('edupfs')(
  187. <EduPfsSelect defValue={this.state.eduPfs} Professional={this.professional} />
  188. )}
  189. </FormItem>
  190. <FormItem
  191. {...formItemLayout}
  192. label="毕业学校"
  193. >
  194. {getFieldDecorator('schoolname', {
  195. initialValue: this.state.schoolname || null
  196. })(
  197. <Input />
  198. )}
  199. </FormItem>
  200. <FormItem
  201. {...formItemLayout}
  202. labelCol={{ span: 4 }}
  203. wrapperCol={{ span: 4 }}
  204. label="毕业时间"
  205. >
  206. {getFieldDecorator('graduationTimeYear')(
  207. <YearSelect defValue={this.state.graduationTimeYear || null} handleyear={this.handleyear} />
  208. )}
  209. </FormItem>
  210. <FormItem
  211. {...formItemLayout}
  212. label="学历证书"
  213. >
  214. {getFieldDecorator('xueliPic')(
  215. <Avatar name="xueliPic" urlData={this.xueliPicUrl} picUrl={this.state.xueliPicUrl} />
  216. )}
  217. <p>{this.state.xueliPicUrl !== "" ? <Button onClick={this.downloadPic.bind(this, this.state.xueliPicUrl)}>下载证书</Button> : ""}</p>
  218. </FormItem>
  219. <FormItem
  220. {...formItemLayout}
  221. label="学历证书编号"
  222. >
  223. {getFieldDecorator('edunum', {
  224. initialValue: this.state.edunum || null
  225. })(
  226. <Input />
  227. )}
  228. </FormItem>
  229. <FormItem
  230. {...formItemLayout}
  231. label="学位证书"
  232. hasFeedback
  233. >
  234. {getFieldDecorator('xueweiPic')(
  235. <Avatar name="xueweiPic" urlData={this.xueweiPicUrl} picUrl={this.state.xueweiPicUrl} />
  236. )}
  237. <p>{this.state.xueweiPicUrl !== "" ? <Button onClick={this.downloadPic.bind(this, this.state.xueweiPicUrl)}>下载证书</Button> : ""}</p>
  238. </FormItem>
  239. <FormItem
  240. {...formItemLayout}
  241. label="学位证书编号"
  242. >
  243. {getFieldDecorator('degreenum', {
  244. initialValue: this.state.degreenum || null
  245. })(
  246. <Input />
  247. )}
  248. </FormItem>
  249. <div className="set-explain">
  250. <p>要求2M 以下的jpg、jpeg格式的图片。该资料不会公开展示,仅作为审核材料使用。</p>
  251. </div>
  252. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  253. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  254. </FormItem>
  255. </Form >
  256. );
  257. },
  258. }));
  259. const Person = React.createClass({
  260. getInitialState() {
  261. return {
  262. loading: false
  263. };
  264. },
  265. spinChange(e) {
  266. this.setState({
  267. loading: e
  268. });
  269. },
  270. render() {
  271. return (
  272. <Spin spinning={this.state.loading} className='spin-box'>
  273. <div className="set-edu">
  274. <div className="acc-detail">
  275. <p className="acc-title">最高学历</p>
  276. <EduFrom spinState={this.spinChange} />
  277. </div>
  278. </div>
  279. </Spin>
  280. )
  281. }
  282. });
  283. export default Person;