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