海南旅游项目 前端仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

170 lines
4.9 KiB

4 years ago
  1. <template>
  2. <view>
  3. <view class="lf-row-center lf-flex-column box">
  4. <!-- <image class="img" :src="userInfo.avatar" v-if="userInfo.avatar"></image> -->
  5. <!-- <image class="img" src="../../static/logo.png" v-else></image> -->
  6. <image class="img" src="../../static/logo.png" ></image>
  7. <view class="lf-m-t-30 lf-font-32" v-if="type == 'phone'">{{ userInfo.nickname || '游客用户' }}</view>
  8. <block v-if="type == 'userinfo'">
  9. <button class="btn" @click="getUserProfile">
  10. <text class="lf-iconfont lf-icon-weixin lf-font-60 lf-text-vertical"></text>
  11. <text class="lf-m-l-20">微信快捷登录</text>
  12. </button>
  13. <!-- <view class="lf-m-t-40 lf-font-28" @click="$toBack()">暂不绑定继续操作</view> -->
  14. <view class="mask" v-if="!checked" @click="$msg('您未同意协议条款')"></view>
  15. </block>
  16. <block v-else-if="type == 'phone'">
  17. <button class="btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
  18. <text class="lf-iconfont lf-icon-weixin lf-font-60 lf-text-vertical"></text>
  19. <text class="lf-m-l-20">绑定手机号</text>
  20. </button>
  21. <!-- <view class="lf-m-t-40 lf-font-28" @click="$url('/pages/login/accountLogin')">使用手机号登录</view> -->
  22. <view class="mask" v-if="!checked" @click="$msg('您未同意协议条款')"></view>
  23. </block>
  24. </view>
  25. <!-- 服务条款 -->
  26. <view class="fixed-bottom lf-flex">
  27. <checkbox-group @change="checkboxChange" style="display: inline-block;">
  28. <checkbox class="lf-text-vertical" :checked="checked"></checkbox>
  29. </checkbox-group>
  30. <view class="lf-m-l-10 lf-font-24 lf-color-gray" style="display: inline-block;">
  31. <text>请认真阅读并同意</text>
  32. <text @click="enterAgree" class="text-orange">用户协议</text>
  33. <text>在小程序下单购买即表示您已默认同意</text>
  34. <text @click="enterAgree" class="text-orange">用户协议</text>
  35. <text>的所有条款</text>
  36. </view>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. export default {
  42. data(){
  43. return {
  44. checked: false, // 是否勾选协议
  45. isLogin: false, // 是否已登录
  46. userInfo: {},
  47. type: 'userinfo', // 页面授权类型 phone获取手机号 | userinfo获取用户信息
  48. agreement: {} // 协议
  49. }
  50. },
  51. onLoad(options){
  52. this.type = options.type || this.type;
  53. getApp().globalData.wxlogin().then(res => {
  54. this.userInfo = res;
  55. });
  56. },
  57. methods: {
  58. // 进入查看协议
  59. enterAgree(){
  60. this.$url('/pages/about/register_agree');
  61. },
  62. // 勾选协议发生变化
  63. checkboxChange(event){
  64. this.checked = event.detail.value.length > 0;
  65. },
  66. // 微信快捷登录获取手机号
  67. getPhoneNumber(event){
  68. console.log('=====',this.API.API_GETUSERINFO)
  69. console.log(event);
  70. if(event.detail.errMsg == 'getPhoneNumber:ok'){
  71. let encryptedData = event.detail.encryptedData;
  72. let iv = event.detail.iv;
  73. // let userInfo = uni.getStorageSync('userinfo') || {};
  74. this.$http(this.API.API_GETUSERINFO, {
  75. encryptedData,
  76. iv,
  77. // token: userInfo.token // 已在公共参数传
  78. }).then(res => {
  79. console.log("更新手机号", res);
  80. this.$msg('更新成功', {icon: 'success'});
  81. uni.setStorageSync('userinfo', res.data);
  82. setTimeout(() => {
  83. this.$toBack();
  84. }, 1000);
  85. })
  86. }
  87. },
  88. // 获取用户信息
  89. getUserProfile(){
  90. uni.getUserProfile({
  91. desc: '您的信息将用于小程序显示',
  92. lang: 'zh_CN',
  93. complete: result => {
  94. console.log(result)
  95. if(result.errMsg == 'getUserProfile:ok'){
  96. let encryptedData = result.encryptedData;
  97. let iv = result.iv;
  98. let signature = result.signature;
  99. // let userInfo = uni.getStorageSync('userinfo') || {};
  100. this.$http(this.API.API_GETUSERINFO, {
  101. encryptedData,
  102. iv,
  103. // token: userInfo.token // 已在公共参数传
  104. }).then(res => {
  105. console.log("更新用户信息", res);
  106. this.$msg('更新成功', {icon: 'success'});
  107. uni.setStorageSync('userinfo', res.data);
  108. setTimeout(() => {
  109. this.$toBack();
  110. }, 1000);
  111. })
  112. }
  113. }
  114. });
  115. }
  116. }
  117. }
  118. </script>
  119. <style>
  120. page{
  121. overflow: hidden;
  122. }
  123. </style>
  124. <style lang="scss" scoped="scoped">
  125. .box{
  126. padding: 60rpx 32rpx;
  127. width: 750rpx;
  128. height: auto;
  129. box-sizing: border-box;
  130. position: relative;
  131. .img{
  132. width: 180rpx;
  133. height: 180rpx;
  134. border-radius: 50%;
  135. }
  136. .btn{
  137. background-color: #09BB07;
  138. color: #FFFFFF;
  139. width: 100%;
  140. height: 88rpx;
  141. border-radius: 42rpx;
  142. font-size: 32rpx;
  143. line-height: 88rpx;
  144. margin-top: 80rpx;
  145. }
  146. }
  147. .fixed-bottom{
  148. position: fixed;
  149. bottom: 60rpx;
  150. left: 0;
  151. padding: 0 32rpx;
  152. .highlight{
  153. color: #1e90ff;
  154. }
  155. }
  156. .mask{
  157. position: absolute;
  158. bottom: 46rpx;
  159. left: 0;
  160. width: 100%;
  161. height: 190rpx;
  162. }
  163. .display-inline-block{
  164. display: inline-block;
  165. }
  166. </style>