personal.jsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. import React from 'react';
  2. import { Input, Button, Form, Upload, Icon, Spin, message, Row, Col ,Cascader} from 'antd';
  3. import './certify.less';
  4. import { getBase64, beforeUpload,provinceSelect } from '../tools.js';
  5. import ajax from 'jquery/src/ajax/xhr.js'
  6. import $ from 'jquery/src/ajax';
  7. import card1 from '../../../image/idcard1.jpg';
  8. import card2 from '../../../image/idcard2.jpg';
  9. class Avatar extends React.Component {
  10. constructor(props) {
  11. super(props);
  12. this.state = {
  13. imageUrl: ''
  14. }
  15. }
  16. handleChange(info) {
  17. if (info.file.status === 'done') {
  18. // Get this url from response in real world.
  19. getBase64(info.file.originFileObj, imageUrl => this.setState({ imageUrl }));
  20. this.props.urlData(info.file.response.data);
  21. }
  22. }
  23. render() {
  24. const imageUrl = this.state.imageUrl;
  25. return (
  26. <Upload
  27. className="avatar-uploader"
  28. name={this.props.name}
  29. showUploadList={false}
  30. action={globalConfig.context + "/api/user/identity/upload"}
  31. data={{ 'sign': this.props.name }}
  32. beforeUpload={beforeUpload}
  33. onChange={this.handleChange.bind(this)}
  34. >
  35. {
  36. imageUrl ?
  37. <img src={imageUrl} role="presentation" id={this.props.name} /> :
  38. <Icon type="plus" className="avatar-uploader-trigger" />
  39. }
  40. </Upload>
  41. );
  42. }
  43. };
  44. const Content = Form.create()(React.createClass({
  45. getData() {
  46. this.setState({
  47. loading: true
  48. });
  49. $.ajax({
  50. method: "get",
  51. dataType: "json",
  52. url: globalConfig.context + "/api/user/userPro",
  53. success: function (data) {
  54. if (data.data) {
  55. this.setState({
  56. positiveIdUrl: data.data.positiveIdUrl,
  57. oppositeIdUrl: data.data.oppositeIdUrl,
  58. address:[data.data.province,data.data.city,data.data.area],
  59. aftUsername: data.data.aftUsername,
  60. username: data.data.username,
  61. idNumber: data.data.idNumber,
  62. contactMobile: data.data.contactMobile
  63. });
  64. };
  65. }.bind(this),
  66. }).done(function (data) {
  67. if (data.error.length) {
  68. message.warning(data.error[0].message);
  69. }
  70. }.bind(this)).always(function () {
  71. this.setState({
  72. loading: false
  73. });
  74. }.bind(this));
  75. },
  76. getInitialState() {
  77. return {
  78. loading: false
  79. };
  80. },
  81. handleSubmit(e) {
  82. e.preventDefault();
  83. this.props.form.validateFields((err, values) => {
  84. if (!this.state.positiveIdUrl || !this.state.oppositeIdUrl) {
  85. message.warning("请上传身份证!");
  86. return;
  87. };
  88. if (!err) {
  89. this.setState({
  90. loading: true
  91. });
  92. $.ajax({
  93. method: "POST",
  94. dataType: "json",
  95. crossDomain: false,
  96. url: globalConfig.context + "/api/user/userNextPro",
  97. data: {
  98. verificationCode: values.captcha,
  99. aftUsername: values.aftUsername,
  100. username: values.username,
  101. idNumber: values.idNumber,
  102. positiveIdUrl: this.state.positiveIdUrl,
  103. oppositeIdUrl: this.state.oppositeIdUrl,
  104. province: values.address[0],
  105. city: values.address[1],
  106. area: values.address[2],
  107. contactMobile: values.contactMobile,
  108. process: 1
  109. }
  110. }).done(function (data) {
  111. if (!data.error.length) {
  112. message.success('保存成功!');
  113. this.props.changeStep(2);
  114. } else {
  115. message.warning(data.error[0].message);
  116. this.reloadVCode();
  117. this.setState({
  118. loading: false
  119. });
  120. }
  121. }.bind(this));
  122. }
  123. });
  124. },
  125. checkPhone(rule, value, callback) {
  126. const form = this.props.form;
  127. const _me = this;
  128. if (!(/^1[34578]\d{9}$/.test(value))) {
  129. callback('请输入正确的手机号码!');
  130. _me.setState({
  131. getCodeButton: true
  132. });
  133. } else {
  134. callback();
  135. _me.setState({
  136. getCodeButton: false
  137. });
  138. }
  139. },
  140. checkIdcardnum(rule, value, callback) {
  141. if (!/(^\d{15}$)|(^\d{17}(\d|X)$)/.test(value)) {
  142. callback('请输入正确的身份证号!');
  143. } else {
  144. callback();
  145. }
  146. },
  147. getIdCardUrl1(e) {
  148. this.state.positiveIdUrl = e;
  149. },
  150. getIdCardUrl2(e) {
  151. this.state.oppositeIdUrl = e;
  152. },
  153. componentWillMount() {
  154. this.getData();
  155. },
  156. reloadVCode(e) {
  157. e.target.src = globalConfig.context + '/open/getVCode?t=' + Math.random();
  158. },
  159. render() {
  160. const FormItem = Form.Item;
  161. const { getFieldDecorator } = this.props.form;
  162. const formItemLayout = {
  163. labelCol: { span: 4 },
  164. wrapperCol: { span: 12 },
  165. };
  166. const _me = this;
  167. return (
  168. <Spin spinning={this.state.loading} className="certify-spin">
  169. <Form horizontal onSubmit={this.handleSubmit} className="certify-form">
  170. <FormItem
  171. {...formItemLayout}
  172. label="用户名"
  173. extra={<span><Icon type="exclamation-circle" /> 建议字母、数字和符号两种以上组合,6-20个字符</span>}
  174. >
  175. {getFieldDecorator('aftUsername', {
  176. initialValue: this.state.aftUsername || null,
  177. rules: [{ required: true, message: '请输入用户名!' }]
  178. })(
  179. <Input />
  180. )}
  181. </FormItem>
  182. <FormItem
  183. {...formItemLayout}
  184. label="真实姓名"
  185. >
  186. {getFieldDecorator('username', {
  187. initialValue: this.state.username || null,
  188. rules: [{ required: true, message: '请输入真实姓名!' }]
  189. })(
  190. <Input />
  191. )}
  192. </FormItem>
  193. <FormItem
  194. labelCol={{ span: 4 }}
  195. wrapperCol={{ span: 18 }}
  196. label="所在地"
  197. >
  198. {getFieldDecorator('address',{
  199. initialValue: this.state.address || null,
  200. rules: [{type:'array', required: true, message: '请选择地址!' }]
  201. })(
  202. <Cascader options={provinceSelect()} placeholder="请选择" />
  203. )}
  204. </FormItem>
  205. <FormItem
  206. {...formItemLayout}
  207. label="身份证号"
  208. >
  209. {getFieldDecorator('idNumber', {
  210. rules: [{
  211. validator: this.checkIdcardnum,
  212. }],
  213. initialValue: this.state.idNumber || null
  214. })(
  215. <Input placeholder="请输入真实有效的身份证号码" />
  216. )}
  217. </FormItem>
  218. <FormItem wrapperCol={{ span: 21, offset: 4 }}>
  219. <p>请上传清晰的个人身份证正反面原件照片/扫描件 (不能截图、图片内容要求完整 ),</p>
  220. <p>要求2M 以下的jpg、jpeg、gif、png格式的图片。该资料不会公开展示,仅作为审核材料使用。</p>
  221. </FormItem>
  222. <FormItem
  223. labelCol={{ span: 4 }}
  224. wrapperCol={{ span: 18 }}
  225. label="身份证图片"
  226. >
  227. {getFieldDecorator('idcard')(
  228. <div>
  229. <Avatar name="idcard1" urlData={this.getIdCardUrl1} />
  230. <Avatar name="idcard2" urlData={this.getIdCardUrl2} />
  231. </div>
  232. )}
  233. </FormItem>
  234. <FormItem wrapperCol={{ span: 18, offset: 4 }}>
  235. <span className="idCard-text">上传身份证正面</span>
  236. <span className="idCard-text">上传身份证反面</span>
  237. </FormItem>
  238. <FormItem wrapperCol={{ span: 21, offset: 4 }}>
  239. <p className="acc-title">示例</p>
  240. <div className="idcard-img clearfix">
  241. <div>
  242. <div className="idcard-imgbox">
  243. <img src={card1} alt="" />
  244. </div>
  245. </div>
  246. <div>
  247. <div className="idcard-imgbox">
  248. <img src={card2} alt="" />
  249. </div>
  250. </div>
  251. </div>
  252. </FormItem>
  253. <FormItem
  254. {...formItemLayout}
  255. label="联系方式"
  256. extra={<span><Icon type="exclamation-circle" /> 请输入正确的手机号,暂不支持海外手机注册</span>}
  257. >
  258. {getFieldDecorator('contactMobile', {
  259. initialValue: this.state.contactMobile || null,
  260. rules: [{ validator: this.checkPhone }]
  261. })(
  262. <Input placeholder="建议使用常用手机" />
  263. )}
  264. </FormItem>
  265. <FormItem
  266. {...formItemLayout}
  267. label="验证码"
  268. extra={<span style={{ 'color': '#ea0862' }}><Icon type="exclamation-circle" /> 看不清?点击图片更换验证码</span>}
  269. >
  270. <Row gutter={8}>
  271. <Col span={16}>
  272. {getFieldDecorator('captcha', {
  273. rules: [{ required: true, message: '请输入图片中的验证码' }],
  274. })(
  275. <Input />
  276. )}
  277. </Col>
  278. <Col span={8}>
  279. <div className="getVcode">
  280. <img id="VCode"
  281. src={globalConfig.context + '/open/getVCode'}
  282. alt="看不清楚点击切换"
  283. onClick={this.reloadVCode} />
  284. </div>
  285. </Col>
  286. </Row>
  287. </FormItem>
  288. <FormItem wrapperCol={{ span: 12, offset: 4 }}>
  289. <Button className="set-submit" type="primary" htmlType="submit">下一步</Button>
  290. <Button className="exit" type="ghost">退出实名认证</Button>
  291. </FormItem>
  292. </Form >
  293. </Spin >
  294. );
  295. },
  296. }));
  297. export default Content;