factorauth.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <view class="pages">
  3. <u-navbar
  4. title="实名认证"
  5. :placeholder="true"
  6. :autoBack="true"
  7. @leftClick="leftClick"
  8. :safeAreaInsetTop="true"
  9. >
  10. </u-navbar>
  11. <view class="page-wrap">
  12. <view class="login-box">
  13. <u--form labelPosition="left" labelWidth="200rpx" :model="form" :rules="rules" ref="uForm" >
  14. <u-form-item label="真实姓名" prop="name" borderBottom ref="name" >
  15. <u--input
  16. v-model="form.name"
  17. placeholder="真实姓名"
  18. border="none"
  19. :customStyle="inputCustomStyle"
  20. ></u--input>
  21. </u-form-item>
  22. <u-form-item label="身份证号码" prop="idcard" ref="idcard" >
  23. <u--input
  24. v-model="form.idcard"
  25. border="none"
  26. placeholder="身份证号码"
  27. :customStyle="inputCustomStyle"
  28. ></u--input>
  29. </u-form-item>
  30. </u--form>
  31. <u-button
  32. @click="submit"
  33. text="提交认证"
  34. type="error"
  35. shape="circle"
  36. :customStyle="{'margin-top':'60rpx',height:'98rpx','box-sizing':'border-box'}">
  37. </u-button>
  38. </view>
  39. </view>
  40. <u-toast ref="uToast"></u-toast>
  41. </view>
  42. </template>
  43. <script>
  44. export default {
  45. data() {
  46. return {
  47. backUrl:'',
  48. form:{
  49. name:'',
  50. idcard:''
  51. },
  52. rules: {
  53. name: {
  54. type: 'string',
  55. required: true,
  56. message: '请填写真实姓名',
  57. trigger: ['blur', 'change']
  58. },
  59. idcard:[
  60. {
  61. type: 'string',
  62. required: true,
  63. message: '请填身份证号码',
  64. trigger: ['blur', 'change']
  65. },
  66. // {
  67. // validator: (rule, value, callback) => {
  68. // // 上面有说,返回true表示校验通过,返回false表示不通过
  69. // // uni.$u.test.mobile()就是返回true或者false的
  70. // return uni.$u.test.idCard(value);
  71. // },
  72. // message: '身份证号码不正确',
  73. // // 触发器可以同时用blur和change
  74. // trigger: ['change','blur'],
  75. // }
  76. ]
  77. },
  78. inputCustomStyle:{}
  79. }
  80. },
  81. onShow() {
  82. },
  83. onReady() {
  84. //onReady 为uni-app支持的生命周期之一
  85. this.$refs.uForm.setRules(this.rules)
  86. },
  87. onLoad(page) {
  88. console.log('page',page);
  89. this.backUrl = decodeURIComponent(page.backUrl)||'/center/center';
  90. console.log('this.backUrl',this.backUrl);
  91. },
  92. methods: {
  93. leftClick(){
  94. let pages = getCurrentPages();
  95. if(pages.length==1){
  96. uni.$u.route('/pages/index/index')
  97. }else{
  98. uni.navigateBack()
  99. };
  100. },
  101. submit(){
  102. // console.log('form',this.form);
  103. // if(!this.form.idcard.startsWith("52")){
  104. // uni.$u.toast('仅允许以52开头的身份证')
  105. // return
  106. // }
  107. this.$refs.uForm.validate().then(res => {
  108. // uni.$u.toast('校验通过')
  109. this.$u.api.factorAuth(this.form).then(res=>{
  110. this.getMemberInfo()
  111. // console.log('res',res.data);
  112. }).catch(err=>{
  113. // this.$refs.uToast.show({
  114. // type: 'error',
  115. // icon: false,
  116. // title: '认证失败',
  117. // message: err.msg,
  118. // })
  119. console.log('login',err);
  120. })
  121. }).catch(errors => {
  122. uni.$u.toast('请正确填写表单')
  123. })
  124. },
  125. getMemberInfo(){
  126. let that = this;
  127. this.$u.api.memberInfo({id:this.vuex_user_info.userid}).then(res=>{
  128. this.$u.vuex('vuex_member_info', res.data);
  129. uni.showToast({
  130. title:'认证成功',
  131. icon:'success'
  132. })
  133. setTimeout(()=>{
  134. // console.log('this.backUrl',this.backUrl);
  135. // uni.reLaunch({url: this.backUrl});
  136. that.leftClick();
  137. },1000)
  138. // console.log('memberInfo',this.memberInfo);
  139. }).catch(err=>{
  140. // console.log('memberInfo',err.data);
  141. })
  142. },
  143. }
  144. }
  145. </script>
  146. <style lang="scss" scoped>
  147. </style>