猎豆优选小程序

bindInviteCode.vue 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <view class="page-wrap">
  3. <!-- 顶部导航 -->
  4. <u-navbar class="navbar-wrap" title="绑定邀请码" title-color="#fff" :title-size="36" :title-bold="false" :is-back="true" back-icon-color="#fff" :background="navbarBackground" />
  5. <!-- 登录提示语 -->
  6. <view class="tips-wrap">
  7. <view class="title">请输入邀请信息</view>
  8. <!-- <view class="tips">
  9. <text>登录代表您已阅读并同意</text>
  10. <text class="link">《猎豆隐私协议》</text>
  11. </view> -->
  12. </view>
  13. <!-- 表单 -->
  14. <view class="form-wrap">
  15. <view class="form-item">
  16. <image class="item-img" src="https://ld.726p.com/ldyx_static/imgs/icon-invite.png" />
  17. <u-input class="item-input" v-model="form.inviteCode" maxlength="20" :border="false" placeholder="请输入邀请码或邀请人手机号" />
  18. </view>
  19. </view>
  20. <!-- 底部按钮 -->
  21. <view class="footer-wrap">
  22. <view class="btn" @click="onClickSkip">跳过</view>
  23. <view :class="['btn', 'disabled', form.inviteCode ? 'on' : '']" @click="onClickBind">开启优选之旅</view>
  24. <!-- <view class="footer-tips">未注册的手机号码验证后自动注册</view> -->
  25. </view>
  26. <!-- #ifdef H5 -->
  27. <icp style="position: fixed;bottom:100rpx"></icp>
  28. <!-- #endif -->
  29. </view>
  30. </template>
  31. <script>
  32. const app = getApp()
  33. const $router = app.globalData.$router
  34. export default {
  35. data() {
  36. return {
  37. statusBarHeight: app.globalData.statusBarHeight,
  38. navbarBackground: {
  39. background: 'linear-gradient(90deg, #F57C29 0%, #F13641 100%)'
  40. },
  41. form: {
  42. inviteCode: '', // 邀请码
  43. },
  44. };
  45. },
  46. methods: {
  47. // 监听点击“跳过”
  48. async onClickSkip() {
  49. // await app.handleShowModal('确定绑定"默认邀请码"吗?')
  50. this.handleBind({ isSkip: true })
  51. },
  52. // 监听点击“绑定邀请码”
  53. async onClickBind() {
  54. if (!this.form.inviteCode) {
  55. this.$u.toast('请输入邀请码');
  56. return false
  57. }
  58. await app.handleShowModal(`确定绑定"${ this.form.inviteCode }"吗?`)
  59. this.handleBind()
  60. },
  61. // 执行绑定邀请码
  62. async handleBind(options = {}) {
  63. try {
  64. const isSkip = options.isSkip
  65. const url = this.$api.login_mbindingInvitationCode
  66. const params = {
  67. code: isSkip ? uni.getStorageSync('default_invite_code') : this.form.inviteCode,
  68. user_id: uni.getStorageSync('user_id'),
  69. }
  70. uni.showLoading({ title: '加载中...', mask: true })
  71. const { data: res } = await this.$postJSON(url, params)
  72. uni.hideLoading()
  73. if (res && res.errno == 0) {
  74. const { data: { flag, info, token, sex, nickname, up_user_id } } = res.rst || {}
  75. if (flag == 1) { // 绑定成功
  76. uni.setStorageSync('token', token || '')
  77. uni.setStorageSync('sex', sex)
  78. uni.setStorageSync('nickname', nickname || '')
  79. uni.setStorageSync('up_user_id', up_user_id || '')
  80. await app.handleGetUserInfo() // 获取用户信息
  81. uni.showToast({ title: '登录成功', icon: 'none' })
  82. setTimeout(() => {
  83. // $router.switchTab({
  84. // url: '/pages/home/home'
  85. // })
  86. wx.navigateBack({delta: 2});
  87. uni.setStorageSync('loginPageBack',true)
  88. }, 1000);
  89. } else { // 绑定失败
  90. this.$u.toast(info || '操作失败');
  91. }
  92. } else {
  93. this.$u.toast(res.err || '操作失败')
  94. }
  95. } catch (error) {
  96. console.log('error => ', error)
  97. }
  98. },
  99. },
  100. }
  101. </script>
  102. <style lang="scss" scoped>
  103. .page-wrap {
  104. position: relative;
  105. min-height: 100vh;
  106. padding: 0 30rpx;
  107. .tips-wrap {
  108. margin-top: 60rpx;
  109. .title {
  110. font-size: 48rpx;
  111. color: #333;
  112. }
  113. .tips {
  114. margin-top: 30rpx;
  115. font-size: 26rpx;
  116. color: #666;
  117. .link {
  118. color: #51A6EF;
  119. }
  120. }
  121. }
  122. .form-wrap {
  123. margin-top: 100rpx;
  124. .form-item {
  125. display: flex;
  126. align-items: center;
  127. border-bottom: 2rpx solid #eee;
  128. padding: 20rpx 0;
  129. .item-img {
  130. margin-right: 30rpx;
  131. width: 45rpx;
  132. height: 45rpx;
  133. vertical-align: middle;
  134. }
  135. .item-label {
  136. width: 120rpx;
  137. font-size: 30rpx;
  138. color: #333;
  139. }
  140. .item-input {
  141. flex: 1;
  142. /deep/ .u-input__input {
  143. font-size: 30rpx;
  144. color: #333;
  145. }
  146. }
  147. .btn-text {
  148. padding: 0 10rpx 0 20rpx;
  149. color: #51A6EF;
  150. }
  151. }
  152. }
  153. .footer-wrap {
  154. margin-top: 100rpx;
  155. display: flex;
  156. flex-direction: column;
  157. align-items: center;
  158. .btn {
  159. margin-bottom: 40rpx;
  160. display: flex;
  161. align-items: center;
  162. justify-content: center;
  163. font-size: 32rpx;
  164. width: 600rpx;
  165. height: 84rpx;
  166. border-radius: 42rpx;
  167. color: #999;
  168. background: #fff;
  169. border: 2rpx solid #999;
  170. &.disabled {
  171. color: #fff;
  172. background: #D0D0D0;
  173. border: none;
  174. }
  175. &.on {
  176. color: #fff;
  177. background: linear-gradient(270deg, #FF4040 0%, #FF7E40 100%);
  178. border: none;
  179. }
  180. }
  181. .footer-tips {
  182. font-size: 28rpx;
  183. color: #ccc;
  184. }
  185. }
  186. }
  187. </style>