bindPhone.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <view class="page">
  3. <cu-custom :isBack="true" title="绑定手机号"></cu-custom>
  4. <view class="bind bg-white">
  5. <view class="bind-img">
  6. <image src="/static/imgs/phone.png" mode="widthFix" style="width:400rpx;" />
  7. </view>
  8. <view class="bind-text">请绑定手机号</view>
  9. <view class="bind-tip" style="margin-top:10px;"> 为向您提供更优质的交易相关基本功能,我们将会获取您的手机号。</view>
  10. <view class="bind-tip">
  11. 为了更好的保障个人权益,请您仔细阅读
  12. <text style="color:#02a5b1" class="text" @tap="goto('user')">《用户协议》</text>和
  13. <text style="color:#02a5b1" class="text" @tap="goto('privacy')">《隐私政策》</text>
  14. </view>
  15. <button class="bind-btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">立即绑定</button>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. import { _bindPhone, _login, _getBindPhone } from '@/api/auth'
  21. import { mapGetters } from 'vuex'
  22. export default {
  23. data () {
  24. return {
  25. key: '绑定手机号'
  26. }
  27. },
  28. computed: {
  29. ...mapGetters([
  30. 'token', 'session'
  31. ])
  32. },
  33. methods: {
  34. goto (type) {
  35. this.globalNavigateTo('agreement', { type })
  36. },
  37. getPhoneNumber (e) {
  38. const detail = e.detail
  39. if (!detail.iv) {
  40. return false
  41. }
  42. const _self = this
  43. const params = {
  44. iv: detail.iv,
  45. encryptedData: detail.encryptedData,
  46. token: this.token,
  47. code: this.globalApp.code
  48. }
  49. uni.checkSession({
  50. success () {
  51. params.session = _self.session
  52. _self.bindPhone(params)
  53. },
  54. fail () {
  55. uni.login({
  56. success: wxres => {
  57. _login({ code: wxres.code }).then(res => {
  58. params.session = res.data.session_key
  59. _self.$store.dispatch('setSession', res.data.session_key)
  60. _self.bindPhone(params)
  61. })
  62. }
  63. })
  64. }
  65. })
  66. },
  67. bindPhone (params) {
  68. _bindPhone(params).then(res => {
  69. uni.showToast({ title: res.msg, icon: 'none' })
  70. const token = res.data.token
  71. this.$store.dispatch('setToken', token).then(res => {
  72. this.getBindPhone()// 获取手机号
  73. setTimeout(() => {
  74. uni.navigateBack()
  75. }, 800)
  76. })
  77. })
  78. },
  79. getBindPhone () {
  80. _getBindPhone().then(res => {
  81. this.$store.dispatch('setPhone', res.data.mobile)
  82. })
  83. }
  84. }
  85. }
  86. </script>
  87. <style lang="scss" scoped>
  88. .bind {
  89. padding: 30px 44rpx 10px;
  90. }
  91. .bind-img {
  92. margin: 0 auto;
  93. text-align: center;
  94. }
  95. .bind-text {
  96. margin-top: 20px;
  97. color: #000;
  98. font-size: 18px;
  99. text-align: center;
  100. }
  101. .bind-tip {
  102. font-size: 14px;
  103. }
  104. .bind-btn {
  105. margin-top: 30px;
  106. background: #5fd0e4;
  107. border-radius: 4px;
  108. color: #fff;
  109. width: 100%;
  110. padding: 0;
  111. font-size: 14px;
  112. display: flex;
  113. justify-content: center;
  114. align-items: center;
  115. height: 10vw;
  116. }
  117. .bind-btn:hover {
  118. background: #3f8b97;
  119. }
  120. </style>