edu.jsx 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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(globalConfig.uploadPrivatePath + info.file.response.data);
  39. }
  40. }
  41. theObj(e) {
  42. let _me = this;
  43. $.ajax({
  44. method: "POST",
  45. dataType: "json",
  46. crossDomain: false,
  47. url: globalConfig.context + "/api/user/identity/upload",
  48. data: {
  49. 'sign': _me.props.name
  50. }
  51. });
  52. }
  53. render() {
  54. const imageUrl = this.state.imageUrl;
  55. return (
  56. <Upload
  57. className="avatar-uploader"
  58. name={this.props.name}
  59. showUploadList={false}
  60. action={globalConfig.context + "/api/user/identity/upload"}
  61. data={this.theObj.bind(this)}
  62. beforeUpload={beforeUpload}
  63. onChange={this.handleChange.bind(this)}
  64. >
  65. {
  66. imageUrl ?
  67. <img src={imageUrl} role="presentation" id={this.props.name} /> :
  68. <Icon type="plus" className="avatar-uploader-trigger" />
  69. }
  70. </Upload>
  71. );
  72. }
  73. };
  74. const EduFrom = Form.create()(React.createClass({
  75. getData() {
  76. this.props.spinState(true);
  77. $.ajax({
  78. method: "get",
  79. dataType: "json",
  80. url: globalConfig.context + "/api/user/educate",
  81. success: function (data) {
  82. if (data.data) {
  83. this.setState({
  84. edulvl: data.data.education,
  85. eduPfs: [data.data.majorCategory, data.data.majorName],
  86. schoolname: data.data.graduateSchool,
  87. graduationTimeYear: data.data.graduationTimeYear,
  88. edunum: data.data.diplomaCode,
  89. degreenum: data.data.degreeCode
  90. //"diplomaUrl": "/indentity/4303502988132.jpg",
  91. //"degreeDiplomaUrl": "/indentity/4303502988133.jpg",
  92. });
  93. };
  94. }.bind(this),
  95. }).always(function () {
  96. this.props.spinState(false);
  97. }.bind(this));
  98. },
  99. getInitialState() {
  100. return {
  101. loading: false,
  102. };
  103. },
  104. componentDidMount() {
  105. this.getData();
  106. },
  107. handleSubmit(e) {
  108. e.preventDefault();
  109. this.props.form.validateFields((err, values) => {
  110. if (!err) {
  111. this.props.spinState(true);
  112. $.ajax({
  113. method: "POST",
  114. dataType: "json",
  115. crossDomain: false,
  116. url: globalConfig.context + "/api/user/userEdu",
  117. data: {
  118. "education": values.edulvl,
  119. "majorCategory": this.state.eduPfsA,
  120. "majorName": this.state.eduPfsB,
  121. "graduateSchool": values.schoolname,
  122. "graduationTimeYear": this.state.graduationTimeYear,
  123. //"diplomaUrl": "/indentity/4303502988132.jpg",
  124. "diplomaCode": values.edunum,
  125. //"degreeDiplomaUrl": "/indentity/4303502988133.jpg",
  126. "degreeCode": values.degreenum
  127. }
  128. }).done(function (data) {
  129. if (!data.error.length) {
  130. message.success('保存成功!');
  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. 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. introChange(e) {
  150. console.log(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.xueiPicUrl} />
  216. )}
  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} />
  235. )}
  236. </FormItem>
  237. <FormItem
  238. {...formItemLayout}
  239. label="学历证书编号"
  240. >
  241. {getFieldDecorator('degreenum', {
  242. initialValue: this.state.degreenum || null
  243. })(
  244. <Input />
  245. )}
  246. </FormItem>
  247. <div className="set-explain">
  248. <p>要求2M 以下的jpg、jpeg格式的图片。该资料不会公开展示,仅作为审核材料使用。</p>
  249. </div>
  250. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  251. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  252. </FormItem>
  253. </Form >
  254. );
  255. },
  256. }));
  257. const Person = React.createClass({
  258. getInitialState() {
  259. return {
  260. loading: false
  261. };
  262. },
  263. spinChange(e) {
  264. this.setState({
  265. loading: e
  266. });
  267. },
  268. render() {
  269. return (
  270. <Spin spinning={this.state.loading} className='spin-box'>
  271. <div className="set-edu">
  272. <div className="acc-detail">
  273. <p className="acc-title">最高学历</p>
  274. <EduFrom spinState={this.spinChange} />
  275. </div>
  276. </div>
  277. </Spin>
  278. )
  279. }
  280. });
  281. export default Person;