bindInfo.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <view class="flex-column" style="height: 100vh;">
  3. <u-navbar title="特困户看护平台" bg-color="transparent" auto-back :title-style="{fontWeight:'bold'}"></u-navbar>
  4. <view class="w-750 position-relative" style="height: 472rpx;">
  5. <image src="@/pages/subpack/static/images/header-login-pwd.png" style="width: 100%;height: 100%;"
  6. mode="aspectFill"></image>
  7. <view class="position-absolute top-0 left-0 w-750" style="height: 472rpx;">
  8. <view class="flex-column" style="margin-top: 262rpx;padding-left: 58rpx;">
  9. <text class="font-xxl text-black2 font-weight-bolder">您好!</text>
  10. <text class="font-md text-black2 mt-16">欢迎登录特困户看护平台!</text>
  11. </view>
  12. </view>
  13. </view>
  14. <view class="flex-column flex-1 bg-white align-center"
  15. style="margin-top: -24rpx;border-top-left-radius: 48rpx;border-top-right-radius: 48rpx; z-index: 1;">
  16. <button style="margin-top: 40rpx;border: none;padding: 0;width: 120rpx;height: 120rpx;"
  17. open-type="chooseAvatar" :hairline="false" @chooseavatar="onChooseAvatar">
  18. <image style="width: 120rpx;height: 120rpx;border-radius: 20rpx;" :src="avatarImg" mode="aspectFill">
  19. </image>
  20. </button>
  21. <!-- <view class="flex-row align-center border-top border-bottom px-2"
  22. style="width: 710rpx; height: 88rpx;margin-top: 40rpx;">
  23. <view style="width: 150rpx;">
  24. <text class="font font-weight-bolder text-black2">昵称</text>
  25. </view>
  26. <view style="margin-left: 20rpx;">
  27. <input v-model.trim="nickName" type="nickname" :maxlength="20"></input>
  28. </view>
  29. </view> -->
  30. <view class="flex-row align-center border-top border-bottom px-2"
  31. style="width: 710rpx; height: 88rpx;margin-top: 40rpx;">
  32. <view style="width: 150rpx;">
  33. <text class="font font-weight-bolder text-black2">手机号码</text>
  34. </view>
  35. <view style="margin-left: 20rpx;">
  36. <input v-model.trim="phone" type="number" placeholder="请输入手机号码" :maxlength="11"></input>
  37. </view>
  38. </view>
  39. <view class="flex-row align-center justify-center"
  40. style="width: 638rpx;height: 96rpx;margin-top: 280rpx;background: linear-gradient( 90deg, #2086FF 0%, #305BFF 100%);border-radius: 50rpx;box-shadow: 0rpx 8rpx 16rpx 0rpx rgba(48,91,255,0.32);border: 2rpx solid #FFFFFF;box-sizing: border-box;"
  41. @click="$u.throttle(handleLogin, 1000)">
  42. <text class="text-white font-md font-weight-500">立即进入</text>
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. import {
  49. bindInfoUrl,
  50. getUserInfoUrl
  51. } from '@/common/config/api.js'
  52. export default {
  53. data() {
  54. return {
  55. openId: '',
  56. phone: '',
  57. // nickName: '',
  58. avatarImg: '/pages/subpack/static/images/avatar.png',
  59. }
  60. },
  61. onLoad(options) {
  62. console.log('options: ', options);
  63. this.openId = options.openId;
  64. },
  65. methods: {
  66. onChooseAvatar(e) {
  67. console.log('头像选择', e);
  68. this.avatarImg = e.detail.avatarUrl
  69. },
  70. getUserInfo() {
  71. getUserInfoUrl({
  72. custom: {
  73. catch: true
  74. }
  75. })
  76. .then(res => {
  77. uni.hideLoading();
  78. console.log('用户信息', res);
  79. let user = {
  80. id: res.data.user.userId,
  81. avatar: this.avatarImg,
  82. nickName: res.data.user.nickName,
  83. phonenumber: res.data.user.phonenumber,
  84. roles: res.data.roles
  85. }
  86. this.$u.vuex('vuex_user', user);
  87. uni.switchTab({
  88. url: '/pages/tabbar/application/application'
  89. })
  90. })
  91. .catch(err => {
  92. uni.hideLoading();
  93. console.log(err);
  94. })
  95. },
  96. handleLogin() {
  97. // if (!this.nickName) {
  98. // return uni.$u.toast('请输入昵称')
  99. // }
  100. if (!this.phone) {
  101. return uni.$u.toast('请输入手机号码')
  102. }
  103. if (!uni.$u.test.mobile(this.phone)) {
  104. return uni.$u.toast('请输入正确的手机号码')
  105. }
  106. let avatar = '';
  107. if (this.avatarImg.startsWith('/')) {
  108. avatar = '';
  109. } else {
  110. avatar = this.avatarImg
  111. }
  112. uni.showLoading({
  113. title: '用户认证中...'
  114. })
  115. bindInfoUrl({
  116. params: {
  117. openId: this.openId,
  118. phone: this.phone,
  119. avatar
  120. }
  121. })
  122. .then(res => {
  123. console.log('绑定用户信息', res);
  124. this.$u.vuex('vuex_token', res.token);
  125. // 获取用户信息
  126. this.getUserInfo();
  127. })
  128. .catch(err => {
  129. uni.hideLoading();
  130. console.log(err);
  131. })
  132. // 跳转
  133. },
  134. }
  135. }
  136. </script>
  137. <style>
  138. </style>