edu.jsx 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. import React from 'react';
  2. import { Input, Button, Form, Select, Upload, Icon, Spin, message, Cascader } 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 { techFieldList } from '../../DicTechFieldList';
  8. import { getBase64, beforeUpload } from '../../tools'
  9. import YearSelect from '../../yearSelect.jsx';
  10. const FormItem = Form.Item;
  11. const Option = Select.Option;
  12. class Avatar extends React.Component {
  13. constructor(props) {
  14. super(props);
  15. this.state = {
  16. imageUrl: '',
  17. propsbool: true,
  18. }
  19. }
  20. handleChange(info) {
  21. if (info.file.status === 'done') {
  22. // Get this url from response in real world.
  23. getBase64(info.file.originFileObj, imageUrl => this.setState({ imageUrl }));
  24. this.props.urlData(info.file.response.data);
  25. }
  26. }
  27. componentWillReceiveProps(nextProps) {
  28. if (nextProps.picUrl && this.state.propsbool) {
  29. this.state.imageUrl = globalConfig.avatarHost + "/upload" + nextProps.picUrl;
  30. this.state.propsbool = false;
  31. }
  32. }
  33. render() {
  34. const imageUrl = this.state.imageUrl;
  35. return (
  36. <Upload
  37. className="avatar-uploader"
  38. name="avatar"
  39. showUploadList={false}
  40. action={globalConfig.context + "/api/user/avatar/uploadReplace"}
  41. data={{ 'sign': this.props.name }}
  42. beforeUpload={beforeUpload}
  43. onChange={this.handleChange.bind(this)}
  44. >
  45. {
  46. imageUrl ?
  47. <img src={imageUrl} role="presentation" className="avatar" /> :
  48. <Icon type="plus" className="avatar-uploader-trigger" />
  49. }
  50. </Upload>
  51. );
  52. }
  53. };
  54. const EduFrom = Form.create()(React.createClass({
  55. getData() {
  56. this.props.spinState(true);
  57. $.ajax({
  58. method: "get",
  59. dataType: "json",
  60. url: globalConfig.context + "/api/user/educate",
  61. success: function (data) {
  62. if (data.error && data.error.length) {
  63. message.warning(data.error[0].message);
  64. } else {
  65. this.setState({
  66. id: data.data.id,
  67. edulvl: data.data.education,
  68. eduPfs: data.data.majorCategory ? data.data.majorCategory.split(',') : [],
  69. schoolname: data.data.graduateSchool,
  70. graduationTimeYear: data.data.graduationTimeYear,
  71. edunum: data.data.diplomaCode,
  72. degreenum: data.data.degreeCode,
  73. xueliPicUrl: data.data.diplomaUrl,
  74. xueweiPicUrl: data.data.degreeDiplomaUrl
  75. });
  76. };
  77. }.bind(this),
  78. }).always(function () {
  79. this.props.spinState(false);
  80. }.bind(this));
  81. },
  82. getInitialState() {
  83. return {
  84. loading: false,
  85. xueweiPicUrl: '',
  86. xueliPicUrl: '',
  87. eduPfs: []
  88. };
  89. },
  90. componentDidMount() {
  91. this.getData();
  92. },
  93. handleSubmit(e) {
  94. e.preventDefault();
  95. this.props.form.validateFields((err, values) => {
  96. if (!err) {
  97. this.props.spinState(true);
  98. $.ajax({
  99. method: "POST",
  100. dataType: "json",
  101. crossDomain: false,
  102. url: globalConfig.context + "/api/user/userEdu",
  103. data: {
  104. "id": this.state.id,
  105. "education": values.edulvl,
  106. "majorCategory": values.eduPfs.join(','),
  107. "graduateSchool": values.schoolname,
  108. "graduationTimeYear": this.state.graduationTimeYear,
  109. "diplomaUrl": this.state.xueliPicUrl,
  110. "diplomaCode": values.edunum,
  111. "degreeDiplomaUrl": this.state.xueweiPicUrl,
  112. "degreeCode": values.degreenum
  113. }
  114. }).done(function (data) {
  115. if (!data.error.length) {
  116. message.success('保存成功!');
  117. this.getData();
  118. } else {
  119. message.warning(data.error[0].message);
  120. }
  121. }.bind(this)).always(function () {
  122. this.props.spinState(false);
  123. }.bind(this));
  124. }
  125. });
  126. },
  127. downloadPic(type) {
  128. window.open(globalConfig.context + "/open/downLoadPicture?path=" + type)
  129. },
  130. handleyear(e) {
  131. this.state.graduationTimeYear = e;
  132. },
  133. xueliPicUrl(e) {
  134. this.state.xueliPicUrl = e;
  135. },
  136. xueweiPicUrl(e) {
  137. this.state.xueweiPicUrl = e;
  138. },
  139. render() {
  140. const { getFieldDecorator } = this.props.form;
  141. const formItemLayout = {
  142. labelCol: { span: 4 },
  143. wrapperCol: { span: 12 },
  144. };
  145. const _me = this;
  146. return (
  147. <Form horizontal onSubmit={this.handleSubmit} className="edu-form">
  148. <FormItem
  149. labelCol={{ span: 4 }}
  150. wrapperCol={{ span: 6 }}
  151. label="学历"
  152. >
  153. {getFieldDecorator('edulvl', {
  154. initialValue: this.state.edulvl || null
  155. })(
  156. <Select className="acc-edu-lvl">
  157. {
  158. edulvlArr.map(function (item, i) {
  159. return <Option key={i} value={item} >{item}</Option>
  160. })
  161. }
  162. </Select>
  163. )}
  164. </FormItem>
  165. <FormItem
  166. {...formItemLayout}
  167. label="专业领域"
  168. >
  169. {getFieldDecorator('eduPfs', {
  170. initialValue: this.state.eduPfs || []
  171. })(
  172. <Cascader placeholder="请选择专业领域" options={techFieldList} style={{ width: 300 }} />
  173. )}
  174. </FormItem>
  175. <FormItem
  176. {...formItemLayout}
  177. label="毕业学校"
  178. >
  179. {getFieldDecorator('schoolname', {
  180. initialValue: this.state.schoolname || null
  181. })(
  182. <Input />
  183. )}
  184. </FormItem>
  185. <FormItem
  186. {...formItemLayout}
  187. labelCol={{ span: 4 }}
  188. wrapperCol={{ span: 4 }}
  189. label="毕业时间"
  190. >
  191. {getFieldDecorator('graduationTimeYear')(
  192. <YearSelect defValue={this.state.graduationTimeYear || null} handleyear={this.handleyear} />
  193. )}
  194. </FormItem>
  195. <FormItem
  196. {...formItemLayout}
  197. label="学历证书"
  198. >
  199. {getFieldDecorator('xueliPic')(
  200. <Avatar name="xueliPic" urlData={this.xueliPicUrl} picUrl={this.state.xueliPicUrl} />
  201. )}
  202. <p>{this.state.xueliPicUrl !== "" ? <Button onClick={this.downloadPic.bind(this, this.state.xueliPicUrl)}>下载证书</Button> : ""}</p>
  203. </FormItem>
  204. <FormItem
  205. {...formItemLayout}
  206. label="学历证书编号"
  207. >
  208. {getFieldDecorator('edunum', {
  209. initialValue: this.state.edunum || null
  210. })(
  211. <Input />
  212. )}
  213. </FormItem>
  214. <FormItem
  215. {...formItemLayout}
  216. label="学位证书"
  217. hasFeedback
  218. >
  219. {getFieldDecorator('xueweiPic')(
  220. <Avatar name="xueweiPic" urlData={this.xueweiPicUrl} picUrl={this.state.xueweiPicUrl} />
  221. )}
  222. <p>{this.state.xueweiPicUrl !== "" ? <Button onClick={this.downloadPic.bind(this, this.state.xueweiPicUrl)}>下载证书</Button> : ""}</p>
  223. </FormItem>
  224. <FormItem
  225. {...formItemLayout}
  226. label="学位证书编号"
  227. >
  228. {getFieldDecorator('degreenum', {
  229. initialValue: this.state.degreenum || null
  230. })(
  231. <Input />
  232. )}
  233. </FormItem>
  234. <div className="set-explain">
  235. <p>要求2M 以下的jpg、jpeg格式的图片。该资料不会公开展示,仅作为审核材料使用。</p>
  236. </div>
  237. <FormItem wrapperCol={{ span: 12, offset: 3 }}>
  238. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  239. </FormItem>
  240. </Form >
  241. );
  242. },
  243. }));
  244. const Person = React.createClass({
  245. getInitialState() {
  246. return {
  247. loading: false
  248. };
  249. },
  250. spinChange(e) {
  251. this.setState({
  252. loading: e
  253. });
  254. },
  255. render() {
  256. return (
  257. <Spin spinning={this.state.loading} className='spin-box'>
  258. <div className="set-edu">
  259. <div className="acc-detail">
  260. <p className="acc-title">最高学历</p>
  261. <EduFrom spinState={this.spinChange} />
  262. </div>
  263. </div>
  264. </Spin>
  265. )
  266. }
  267. });
  268. export default Person;