base.jsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. import React from 'react';
  2. import { Input, Button, Form, Radio, Upload, Icon, DatePicker, Spin, message } from 'antd';
  3. import moment from 'moment';
  4. import './base.less';
  5. import ajax from 'jquery/src/ajax/xhr.js'
  6. import $ from 'jquery/src/ajax';
  7. import ChangePw from './changePassword.jsx';
  8. import ChangeMobile from './changeMobile.jsx';
  9. const FormItem = Form.Item;
  10. const RadioGroup = Radio.Group;
  11. const { MonthPicker, RangePicker } = DatePicker
  12. import weixin from '../../../../image/weixin-w.png';
  13. import qq from '../../../../image/qq-w.png';
  14. import weibo from '../../../../image/weibo-w.png';
  15. import card1 from '../../../../image/idcard1.jpg';
  16. import card2 from '../../../../image/idcard2.jpg';
  17. function getBase64(img, callback) {
  18. const reader = new FileReader();
  19. reader.addEventListener('load', () => callback(reader.result));
  20. reader.readAsDataURL(img);
  21. };
  22. function beforeUpload(file) {
  23. const isJPG = file.type === 'image/jpeg';
  24. if (!isJPG) {
  25. message.error('You can only upload JPG file!');
  26. }
  27. const isLt2M = file.size / 1024 / 1024 < 2;
  28. if (!isLt2M) {
  29. message.error('Image must smaller than 2MB!');
  30. }
  31. return isJPG && isLt2M;
  32. };
  33. class Avatar extends React.Component {
  34. constructor(props) {
  35. super(props);
  36. this.state = {
  37. imageUrl: ''
  38. }
  39. }
  40. handleChange(info) {
  41. if (info.file.status === 'done') {
  42. // Get this url from response in real world.
  43. getBase64(info.file.originFileObj, imageUrl => this.setState({ imageUrl }));
  44. this.props.urlData(info.file.response.data);
  45. }
  46. }
  47. render() {
  48. const imageUrl = this.state.imageUrl;
  49. return (
  50. <Upload
  51. className="avatar-uploader"
  52. name={this.props.name}
  53. showUploadList={false}
  54. action={globalConfig.context + "/api/user/identity/upload"}
  55. data={{ 'sign': this.props.name }}
  56. beforeUpload={beforeUpload}
  57. onChange={this.handleChange.bind(this)}
  58. >
  59. {
  60. imageUrl ?
  61. <img src={imageUrl} role="presentation" id={this.props.name} /> :
  62. <Icon type="plus" className="avatar-uploader-trigger" />
  63. }
  64. </Upload>
  65. );
  66. }
  67. };
  68. const BaseFrom = Form.create()(React.createClass({
  69. getData() {
  70. this.props.spinState(true);
  71. $.ajax({
  72. method: "get",
  73. dataType: "json",
  74. url: globalConfig.context + "/api/user/base",
  75. success: function (data) {
  76. if (data.data) {
  77. let d = new Date()
  78. if (data.data.dateOfBirthMonth && data.data.dateOfBirthYear) {
  79. d.setMonth(data.data.dateOfBirthMonth - 1);
  80. d.setYear(parseInt(data.data.dateOfBirthYear));
  81. };
  82. this.setState({
  83. id: data.data.id || null,
  84. username: data.data.username,
  85. sex: data.data.sex,
  86. birth: d,
  87. idnumber: data.data.idNumber,
  88. //oppositeIdUrl: data.data.oppositeIdUrl,
  89. //positiveIdUrl: data.data.positiveIdUrl,
  90. auditStatus: data.data.auditStatus
  91. })
  92. };
  93. }.bind(this),
  94. }).done(function (data) {
  95. if (data.error.length) {
  96. message.warning(data.error[0].message);
  97. }
  98. }.bind(this)).always(function () {
  99. this.props.spinState(false);
  100. }.bind(this));
  101. },
  102. getInitialState() {
  103. return {
  104. };
  105. },
  106. componentDidMount() {
  107. this.getData();
  108. },
  109. handleSubmit(e) {
  110. e.preventDefault();
  111. this.props.form.validateFields((err, values) => {
  112. if (!err) {
  113. this.props.spinState(true);
  114. $.ajax({
  115. method: "POST",
  116. dataType: "json",
  117. crossDomain: false,
  118. url: globalConfig.context + "/api/user/userIndentity",
  119. data: {
  120. "id": this.state.id,
  121. "username": values.username,
  122. "sex": values.sex,
  123. "dateOfBirthYear": values.birth ? values.birth._d.getFullYear() : undefined,
  124. "dateOfBirthMonth": values.birth ? values.birth._d.getMonth() + 1 : undefined,
  125. "idNumber": values.idcardnum,
  126. //"positiveIdUrl": this.state.positiveIdUrl,
  127. //"oppositeIdUrl": this.state.positiveIdUrl
  128. }
  129. }).done(function (data) {
  130. if (!data.error.length) {
  131. message.success('保存成功!');
  132. this.getData();
  133. } else {
  134. message.warning(data.error[0].message);
  135. }
  136. }.bind(this)).always(function () {
  137. this.props.spinState(false);
  138. }.bind(this));
  139. }
  140. });
  141. },
  142. checkIdcardnum(rule, value, callback) {
  143. if (!/(^\d{15}$)|(^\d{17}(\d|X)$)/.test(value)) {
  144. callback('请输入正确的身份证号!');
  145. } else {
  146. callback();
  147. }
  148. },
  149. urlData1(e) {
  150. this.state.oppositeIdUrl = e;
  151. },
  152. urlData2(e) {
  153. this.state.positiveIdUrl = e;
  154. },
  155. render() {
  156. const { getFieldDecorator } = this.props.form;
  157. const formItemLayout = {
  158. labelCol: { span: 4 },
  159. wrapperCol: { span: 12 },
  160. };
  161. return (
  162. <Form horizontal onSubmit={this.handleSubmit} className="base-form">
  163. <FormItem
  164. {...formItemLayout}
  165. label="姓名"
  166. >
  167. {getFieldDecorator('username', {
  168. initialValue: this.state.username || null
  169. })(
  170. this.state.auditStatus == 5 ? <span>{this.state.username}</span> : <Input />
  171. )}
  172. </FormItem>
  173. <FormItem
  174. {...formItemLayout}
  175. label="性别"
  176. >
  177. {getFieldDecorator('sex', {
  178. initialValue: this.state.sex || null
  179. })(
  180. <RadioGroup>
  181. <Radio value="男">男</Radio>
  182. <Radio value="女">女</Radio>
  183. </RadioGroup>
  184. )}
  185. </FormItem>
  186. <FormItem
  187. {...formItemLayout}
  188. label="出生日期"
  189. >
  190. {getFieldDecorator('birth', {
  191. initialValue: !this.state.birth ? null : moment(this.state.birth, 'YYYY/MM')
  192. })(
  193. <MonthPicker />
  194. )}
  195. </FormItem>
  196. <FormItem
  197. {...formItemLayout}
  198. label="身份证号"
  199. >
  200. {getFieldDecorator('idcardnum', {
  201. initialValue: this.state.idnumber || null
  202. })(
  203. this.state.auditStatus == 5 ? <span>{this.state.idnumber}</span> : <Input />
  204. )}
  205. </FormItem>
  206. <FormItem wrapperCol={{ span: 12, offset: 4 }}>
  207. <Button className="set-submit" type="primary" htmlType="submit">保存</Button>
  208. </FormItem>
  209. </Form >
  210. );
  211. },
  212. }));
  213. const Base = React.createClass({
  214. getInitialState() {
  215. return {
  216. loading: false
  217. };
  218. },
  219. spinChange(e) {
  220. this.setState({
  221. loading: e
  222. });
  223. },
  224. render() {
  225. return (
  226. <Spin spinning={this.state.loading} className='spin-box'>
  227. <div className="set-base">
  228. <div className="acc-detail">
  229. <p className="acc-title">您登录的账号</p>
  230. <p>阿凡提号: <span>{userData.number || undefined}</span></p>
  231. <p>登录手机号: <span>{userData.mobile || undefined}</span></p>
  232. <p>认证状态: <span>{userData.lvl == '1' ? <span>已认证</span> : <span>未认证 <a href={globalConfig.context + '/user/certify'}> 马上认证</a></span>}</span></p>
  233. <div className="clearfix">
  234. <ChangeMobile />
  235. <ChangePw />
  236. </div>
  237. </div>
  238. <div className="acc-bind" style={{ 'display': 'none' }}>
  239. <p className="acc-title">绑定账号 <span>绑定后,可使用第三方账号直接登录阿凡提网</span></p>
  240. <p>
  241. <Button className="relateqq"><img src={qq} alt="" /> QQ账号登录</Button>
  242. <Button className="relateweibo"><img src={weibo} alt="" />微博账号登录</Button>
  243. <Button className="relateweixin"><img src={weixin} alt="" />微信账号登录</Button>
  244. </p>
  245. </div>
  246. <div className="acc-info">
  247. <p className="acc-title">身份信息 <span>提供正确的身份信息,有助于进行身份验证,提升信用形象</span></p>
  248. <BaseFrom spinState={this.spinChange} />
  249. </div>
  250. </div>
  251. </Spin>
  252. )
  253. }
  254. });
  255. export default Base;
  256. // <FormItem wrapperCol={{ span: 21, offset: 4 }}>
  257. // <p>请上传清晰的个人身份证正反面原件照片/扫描件 (不能截图、图片内容要求完整 ),</p>
  258. // <p>要求2M 以下的jpg、jpeg、gif、png格式的图片。该资料不会公开展示,仅作为审核材料使用。</p>
  259. // </FormItem>
  260. // <FormItem
  261. // {...formItemLayout}
  262. // label="身份证正面"
  263. // >
  264. // {getFieldDecorator('oppositeIdUrl')(
  265. // <Avatar name="oppositeIdUrl" urlData={this.urlData1} />
  266. // )}
  267. // <p>{
  268. // this.state.oppositeIdUrl !== "" && this.state.oppositeIdUrl !== undefined && this.state.oppositeIdUrl !== null ?
  269. // <span><Icon style={{ 'color': '#79b5ff', 'fontSize': '14px', 'margin': '0 6px' }} type="check-circle" />已上传</span> :
  270. // <span><Icon style={{ 'color': '#fa0', 'fontSize': '14px', 'margin': '0 6px' }} type="exclamation-circle" /><Icon type="exclamation-circle" style={{ color: '#ffbf00', marginRight: '6px' }} />未上传</span>
  271. // }
  272. // </p>
  273. // </FormItem>
  274. // <FormItem
  275. // {...formItemLayout}
  276. // label="身份证反面"
  277. // >
  278. // {getFieldDecorator('positiveIdUrl')(
  279. // <Avatar name="positiveIdUrl" urlData={this.urlData2} />
  280. // )}
  281. // <p>{
  282. // this.state.positiveIdUrl !== "" && this.state.positiveIdUrl !== undefined && this.state.positiveIdUrl !== null ?
  283. // <span><Icon style={{ 'color': '#79b5ff', 'fontSize': '14px', 'margin': '0 6px' }} type="check-circle" />已上传</span> :
  284. // <span><Icon style={{ 'color': '#fa0', 'fontSize': '14px', 'margin': '0 6px' }} type="exclamation-circle" /><Icon type="exclamation-circle" style={{ color: '#ffbf00', marginRight: '6px' }} />未上传</span>
  285. // }
  286. // </p>
  287. // </FormItem>
  288. // <FormItem wrapperCol={{ span: 21, offset: 4 }}>
  289. // <p className="acc-title">示例</p>
  290. // <div className="idcard-img clearfix">
  291. // <div>
  292. // <div className="idcard-imgbox">
  293. // <img src={card1} alt="" />
  294. // </div>
  295. // </div>
  296. // <div>
  297. // <div className="idcard-imgbox">
  298. // <img src={card2} alt="" />
  299. // </div>
  300. // </div>
  301. // </div>
  302. // </FormItem>