authentication.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <view>
  3. <navbar :config="config" backColor="#999999"></navbar>
  4. <view class="box">
  5. <u-form :model="form" ref="uForm" label-width="156">
  6. <u-form-item label="真实姓名">
  7. <u-input v-model="form.realName" placeholder="请输入真实姓名" />
  8. </u-form-item>
  9. <u-form-item label="身份证号">
  10. <u-input v-model="form.identityNumber" placeholder="请输入身份号码" />
  11. </u-form-item>
  12. <u-form-item label="验证码">
  13. <u-input v-model="form.captcha" placeholder="本账户手机验证码" />
  14. <!-- <template v-slot:right> -->
  15. <view class="get-code" @click.stop="getCode()">{{ captchaText }}</view>
  16. <!-- </template> -->
  17. </u-form-item>
  18. </u-form>
  19. <view class="agreement-box" @click.stop="readAgreement()">
  20. <text :class="['agreement-select' , readStatus ? 'read-agreement' : '']"></text>
  21. <text class="agreement-text">已阅读并同意</text>
  22. <text class="agreement-info" @click.stop="openAgreement()">《用户隐私协议》</text>
  23. </view>
  24. <view class="submit-btn" @click.stop="setRealNameAuth()">
  25. 确认提交
  26. </view>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. import {
  32. realNameAuth,
  33. getVerifyCodeByParam
  34. } from "@/api/personal-center.js"
  35. export default {
  36. data() {
  37. return {
  38. config: {
  39. back: true, //false是tolbar页面 是则不写
  40. title: '实名认证',
  41. color: '#1A1A1A',
  42. // autoBack:true,
  43. //背景颜色;参数一:透明度(0-1);参数二:背景颜色(array则为线性渐变,string为单色背景)
  44. backgroundColor: [1, "#fff"],
  45. statusBarFontColor: '#1A1A1A'
  46. },
  47. mobile: '',
  48. readStatus: false, // 协议阅读状态
  49. form: {
  50. realName: '',
  51. identityNumber: '',
  52. captcha: ''
  53. },
  54. captchaText: '获取验证码',
  55. captchaInterval: null,
  56. realNameAuthLoading: false
  57. }
  58. },
  59. created() {
  60. // this.getCode()
  61. },
  62. onShow() {
  63. this.getUserInfo()
  64. },
  65. methods: {
  66. // 查看协议
  67. openAgreement(){
  68. uni.navigateTo({
  69. url:'/pages/protocol/index?code=privacy-agreement'
  70. })
  71. },
  72. readAgreement() {
  73. this.readStatus = !this.readStatus
  74. console.log('this.readStatus = ', this.readStatus)
  75. },
  76. //获取个人信息
  77. getUserInfo() {
  78. let personal = uni.getStorageSync('personal')
  79. this.mobile = personal ? personal.mobile : '';
  80. },
  81. getCode() {
  82. this.getUserInfo()
  83. if (!this.mobile) {
  84. uni.showToast({
  85. title: '当前账号暂未绑定手机号',
  86. icon: 'none'
  87. });
  88. return false
  89. }
  90. if (this.captchaText !== '获取验证码') {
  91. return false
  92. }
  93. this.captchaText = '获取中...'
  94. try {
  95. clearInterval(this.captchaInterval)
  96. } catch {}
  97. try {
  98. this.$http.post(getVerifyCodeByParam, {
  99. mobile: this.mobile,
  100. verifyCodeType: 1
  101. }).then(res => {
  102. let num = 60
  103. this.captchaInterval = setInterval(() => {
  104. this.captchaText = `${num}s`;
  105. num--;
  106. if (num < 0) {
  107. clearInterval(this.captchaInterval)
  108. this.captchaText = '获取验证码'
  109. }
  110. }, 1000)
  111. }).catch(err => {
  112. this.captchaText = '获取验证码'
  113. })
  114. } catch (err) {
  115. this.captchaText = '获取验证码'
  116. }
  117. },
  118. // 实名认证
  119. setRealNameAuth() {
  120. if (this.realNameAuthLoading) {
  121. return false;
  122. }
  123. if (!this.readStatus) {
  124. uni.showToast({
  125. title: '请先阅读协议',
  126. icon: 'none'
  127. });
  128. return false;
  129. }
  130. this.realNameAuthLoading = true;
  131. try {
  132. if (!this.form.realName) {
  133. uni.showToast({
  134. title: '请填写真实姓名',
  135. icon: 'none'
  136. });
  137. throw new Error()
  138. }
  139. if (!this.form.identityNumber) {
  140. this.$mUtil.toast("请填写身份证号")
  141. throw new Error()
  142. }
  143. if (!(this.form.identityNumber.match(this.$mConfig.telIdentity))) {
  144. this.$mUtil.toast("请输入正确的身份证号")
  145. return false
  146. }
  147. if (!this.form.captcha) {
  148. uni.showToast({
  149. title: '请填写验证码',
  150. icon: 'none'
  151. });
  152. throw new Error()
  153. };
  154. this.$http.post(realNameAuth, this.form).then(res => {
  155. console.log('realNameAuth = res', res)
  156. uni.showToast({
  157. title: '绑定成功',
  158. icon: 'none'
  159. });
  160. this.realNameAuthLoading = false;
  161. uni.navigateBack()
  162. }).catch(err => {
  163. this.realNameAuthLoading = false;
  164. })
  165. } catch (err) {
  166. this.realNameAuthLoading = false;
  167. }
  168. }
  169. }
  170. }
  171. </script>
  172. <style lang="scss" scoped>
  173. .box {
  174. padding: 88rpx 50rpx 0;
  175. }
  176. .get-code {
  177. width: 200rpx;
  178. text-align: center;
  179. height: 70rpx;
  180. background: #e7eefc;
  181. border: 1px solid #3775f6;
  182. border-radius: 8rpx;
  183. font-size: 28rpx;
  184. font-family: PingFang SC, PingFang SC-Regular;
  185. font-weight: 400;
  186. color: #FA6138;
  187. }
  188. .agreement-box {
  189. width: 100%;
  190. display: flex;
  191. justify-content: center;
  192. align-items: center;
  193. margin: 97rpx 0 22rpx;
  194. font-size: 24rpx;
  195. font-family: PingFang SC, PingFang SC-Regular;
  196. font-weight: 400;
  197. color: #999999;
  198. .agreement-select {
  199. width: 25rpx;
  200. height: 25rpx;
  201. background: #ffffff;
  202. border: 1rpx solid #0043fb;
  203. border-radius: 6rpx;
  204. margin-right: 8rpx;
  205. }
  206. .read-agreement {
  207. position: relative;
  208. &:before {
  209. content: '';
  210. position: absolute;
  211. left: 50%;
  212. top: 50%;
  213. transform: translate(-50%, -50%);
  214. width: 15rpx;
  215. height: 15rpx;
  216. background-color: #0043fb;
  217. }
  218. }
  219. .agreement-info {
  220. color: #004BFB;
  221. }
  222. }
  223. .submit-btn {
  224. width: 630rpx;
  225. height: 90rpx;
  226. background: #3d93fc;
  227. border-radius: 45rpx;
  228. text-align: center;
  229. line-height: 90rpx;
  230. font-size: 32rpx;
  231. font-family: PingFang SC, PingFang SC-Regular;
  232. font-weight: 400;
  233. color: #ffffff;
  234. }
  235. </style>