user.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <view>
  3. <view class="user-header" v-if="userInfo" @click="toLogin">
  4. <view class="avatar-btn">
  5. <image :src="userInfo?userInfo.avatar:'https://inmei-print.oss-cn-guangzhou.aliyuncs.com/logo.png'"></image>
  6. </view>
  7. <view class="user-info">
  8. <view class="name">{{userInfo.nickname?userInfo.nickname:'请先登录'}}</view>
  9. </view>
  10. </view>
  11. <view class="user-header" v-else>
  12. <view class="avatar-btn">
  13. <image src="https://inmei-print.oss-cn-guangzhou.aliyuncs.com/logo.png"></image>
  14. </view>
  15. <view class="user-info">
  16. <view class="name" @click="toLogin">请先登录</view>
  17. </view>
  18. </view>
  19. <view class="user-menu">
  20. <!-- <view class="menu-item">
  21. <view class="icon"><image src="/static/image/info.png"></image></view>
  22. <view class="name">个人信息</view>
  23. <view class="right"><image src="/static/image/right.png"></image></view>
  24. </view> -->
  25. <navigator hover-class="none" url="/pages/user/address?type=1" class="menu-item">
  26. <view class="icon"><image src="/static/image/address.png"></image></view>
  27. <view class="name">会员地址</view>
  28. <view class="right"><image src="/static/image/right.png"></image></view>
  29. </navigator>
  30. <!-- <view class="menu-item" @click="showService()">
  31. <view class="icon"><image src="/static/image/service.png"></image></view>
  32. <view class="name">客服</view>
  33. <view class="right"><image src="/static/image/right.png"></image></view>
  34. </view> -->
  35. <navigator hover-class="none" class="menu-item" url="/pages/user/license">
  36. <view class="icon"><image src="/static/image/zizhi.png"></image></view>
  37. <view class="name">服务资质</view>
  38. <view class="right"><image src="/static/image/right.png"></image></view>
  39. </navigator>
  40. <view class="menu-item" @click="outLogin">
  41. <view class="icon"><image src="/static/image/out.png"></image></view>
  42. <view class="name">退出</view>
  43. <view class="right"><image src="/static/image/right.png"></image></view>
  44. </view>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. var app;
  50. import * as Api from "@/static/api/user.js";
  51. export default {
  52. data() {
  53. return {
  54. userInfo:null
  55. }
  56. },
  57. onShow() {
  58. this.getData()
  59. },
  60. onLoad() {
  61. app = this;
  62. app.getData()
  63. },
  64. methods: {
  65. toLogin(){
  66. uni.getUserProfile({
  67. success(res) {
  68. var userInfo = res.userInfo;
  69. Api.save({"nickName":userInfo.nickName,"avatarUrl":userInfo.avatarUrl}).then((res)=>{
  70. if (res.code == 0) {
  71. return app.$dialog.showSuccess("登录失败")
  72. }
  73. app.userInfo = res.data;
  74. })
  75. },
  76. fail() {
  77. app.$dialog.showSuccess("登录失败")
  78. }
  79. })
  80. },
  81. getData(){
  82. Api.info({}).then((res)=>{
  83. if (res.code == 0) {
  84. return app.$dialog.showSuccess(res.msg)
  85. }
  86. app.userInfo = res.data;
  87. })
  88. },
  89. outLogin(order){
  90. app.$dialog.showError("确定要退出登录吗",function(res){
  91. if (res.confirm) {
  92. Api.save({"nickName":"","avatarUrl":""}).then((res)=>{
  93. if (res.code == 0) {
  94. return app.$dialog.showSuccess("登录失败")
  95. }
  96. app.userInfo = null;
  97. uni.clearStorageSync();
  98. uni.switchTab({
  99. url:"/pages/index/index"
  100. })
  101. })
  102. }
  103. })
  104. },
  105. callMobile(mobile){
  106. uni.makePhoneCall({
  107. phoneNumber:mobile,
  108. success(res) {
  109. console.log(res)
  110. },fail(res) {
  111. console.log(res)
  112. }
  113. })
  114. },
  115. showService(){
  116. }
  117. }
  118. }
  119. </script>
  120. <style>
  121. page{background-color: #f8f8f8;}
  122. .user-header{background-color: #fe2c56;padding: 40upx;display: flex;align-items: center;background: linear-gradient(to right, #094d89, #007aff);width: calc(95% - 80upx);margin: 40upx auto;border-radius: 10upx;}
  123. .user-header image{width: 100upx;height: 100upx;border-radius: 100upx;}
  124. .user-header .user-info{margin-left: 20upx;}
  125. .user-header .name{font-size: 32upx;color: #fff;}
  126. .user-header .desc{font-size: 24upx;color: #f8f8f8;margin-top: 20upx;}
  127. .user-menu{width: 95%;margin: 40upx auto;border-radius: 10upx;background-color: #fff;}
  128. .user-menu .menu-item{height: 100upx;line-height: 100upx;display: flex;align-items: center;font-size: 28upx;color: #333;padding: 0 20upx;border-bottom: 2upx solid #f8f8f8;}
  129. .user-menu .menu-item .icon{margin-right: 20upx;display: flex;align-items: center;justify-content: center;}
  130. .user-menu .menu-item .right{margin-right: 0;margin-left: auto;}
  131. .user-menu .menu-item .icon image{width: 40upx;height: 40upx;}
  132. .user-menu .menu-item .right image{width: 40upx;height: 40upx;}
  133. .service-popup .item{height: 100upx;line-height: 100upx;text-align: center;font-size: 28upx;color: #333;border-bottom: 2upx solid #f8f8f8;}
  134. .service-popup .item .btn{background-color: #fff;border: 0;height: 100upx;line-height: 100upx;text-align: center;font-size: 28upx;color: #333;}
  135. .service-popup .item .btn::after{border: 0;}
  136. .service-popup .foot{height: 100upx;line-height: 100upx;text-align: center;font-size: 28upx;color: #333;border-top: 20upx solid #f8f8f8;}
  137. </style>