my.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <view class="ezy-my-page">
  3. <view class="icon-title-navBar-box">
  4. <view class="nav-bar-title"></view>
  5. </view>
  6. <view class="my-page-box">
  7. <view class="my-head-box">
  8. <icon class="head-img-box" :style="{backgroundImage: 'url(' + myInfoData.icon + ')'}"></icon>
  9. <view class="head-content-box">
  10. <text>{{myInfoData.nickName}}</text>
  11. <!-- <view class="ezy-jf-box" v-if="loginFlag">
  12. <icon class="jf-icon"></icon>
  13. <text class="jf-text">{{myInfoData.credit}}</text>
  14. </view> -->
  15. </view>
  16. </view>
  17. <!-- 图 -->
  18. <view class="my-banner-img"></view>
  19. <!-- 设置 -->
  20. <view class="my-list-box">
  21. <view class="list-item" @click="ddBtn">
  22. <icon class="list-icon yysz-icon"></icon>
  23. <text>订单</text>
  24. </view>
  25. <view class="list-item" @click="yingyongshezhi">
  26. <icon class="list-icon yysz-icon"></icon>
  27. <text>应用设置</text>
  28. </view>
  29. <view class="list-item" @click="shangcheng">
  30. <icon class="list-icon yysz-icon"></icon>
  31. <text>商城</text>
  32. </view>
  33. <!-- <view v-if="appleCode=='true'&&currentPlatform=='ios' || currentPlatform=='android'" class="list-item" -->
  34. <view class="list-item"
  35. @click="duihuamaDuihuan">
  36. <icon class="list-icon yysz-icon"></icon>
  37. <text>兑换码</text>
  38. </view>
  39. </view>
  40. </view>
  41. <goLogin ref="loginRef" @success="handleSuccess"></goLogin>
  42. <!-- 底部 -->
  43. <custom-tab-bar :show="true" :current-index="currentTabIndex" />
  44. </view>
  45. </template>
  46. <script setup>
  47. import duihuanmaDialog from "./components/duihuanma/duihuanmaDialog.vue"
  48. import cacheManager from '@/utils/cacheManager';
  49. import {
  50. myInfo,
  51. zhuxiao,
  52. duihuanmaCode,
  53. myCardList,
  54. commonCardList
  55. } from '@/api/my.js'
  56. import CustomTabBar from '@/components/custom-tabbar/index.vue';
  57. import goLogin from "@/components/goLogin/goLogin.vue"
  58. import {
  59. onLoad,
  60. onShow
  61. } from '@dcloudio/uni-app';
  62. import {
  63. reactive,
  64. ref
  65. } from "vue";
  66. import {getUserIsYouke} from "../../utils/common";
  67. let appleCode =ref(null)
  68. let currentPlatform = ref(null);
  69. let authInfo = ref(null);
  70. let loginRef = ref(null);
  71. let currentTabIndex = ref(3)
  72. let myInfoData = reactive({
  73. userImg: '',
  74. userName: '',
  75. credit: '',
  76. vipFlag: '',
  77. nickName: '',
  78. icon: '',
  79. });
  80. let pageFrom = ref(null)
  81. onShow(() => {
  82. currentTabIndex.value = 3
  83. if(pageFrom.value ==='myInfo'){
  84. getMyInfo();
  85. }
  86. })
  87. /***************** 测试 ******************/
  88. const testRef = ref(null)
  89. function handleTest() {
  90. testRef.value.showPopup(7)
  91. }
  92. /***************** 测试 ******************/
  93. // 获取用户数据
  94. function getMyInfo() {
  95. myInfo({}).then(res => {
  96. myInfoData.userName = res.data.userName;
  97. myInfoData.nickName = res.data.nickName;
  98. pageFrom.value = ''
  99. appleCode.value = res.data.appleCode.toString()
  100. if (res.data.nickName) {
  101. myInfoData.nickName = res.data.nickName;
  102. } else {
  103. myInfoData.nickName = '鹅状元';
  104. }
  105. if (res.data.icon) {
  106. myInfoData.icon = res.data.icon;
  107. } else {
  108. getUserImg(res.data.growthType)
  109. }
  110. })
  111. }
  112. // 获取用户头像
  113. function getUserImg(data) {
  114. switch (data) {
  115. case 0:
  116. myInfoData.icon = 'static/images/my/head-img0.png'
  117. break;
  118. case 1:
  119. myInfoData.icon = 'static/images/my/head-img1.png'
  120. break;
  121. case 2:
  122. myInfoData.icon = 'static/images/my/head-img2.png'
  123. break;
  124. case 3:
  125. myInfoData.icon = 'static/images/my/head-img3.png'
  126. break;
  127. default:
  128. myInfoData.icon = 'static/images/my/head-unlogin-img.png'
  129. break;
  130. }
  131. }
  132. function yingyongshezhi() {
  133. pageFrom.value = 'myInfo'
  134. uni.navigateTo({
  135. url: '/pages/chanpinMy/myInfo'
  136. })
  137. }
  138. function ddBtn(){
  139. uni.navigateTo({
  140. url: '/pages/chanpinMy/order'
  141. })
  142. }
  143. function duihuamaDuihuan() {
  144. // 兑换码兑换策略
  145. if (getUserIsYouke()) {
  146. // 非登录 -- 登录
  147. loginRef.value.showDl()
  148. } else {
  149. // 已登录
  150. uni.navigateTo({
  151. url:'/pages/chanpinMy/duihuanma'
  152. })
  153. }
  154. }
  155. function handleSuccess(authInfo) {
  156. // 登录成功更改用户名
  157. myInfoData.userName = authInfo.userName;
  158. // 前往兑换码
  159. uni.navigateTo({
  160. url:'/pages/chanpinMy/duihuanma'
  161. })
  162. }
  163. onLoad((options) => {
  164. uni.hideTabBar()
  165. getAuthData();
  166. getMyInfo();
  167. isIOSorAndroid()
  168. })
  169. function isIOSorAndroid() {
  170. const systemInfo = uni.getSystemInfoSync();
  171. if (systemInfo.platform == 'ios') {
  172. currentPlatform.value = 'ios'
  173. } else {
  174. currentPlatform.value = 'android'
  175. }
  176. }
  177. function getAuthData() {
  178. authInfo.value = cacheManager.get('auth');
  179. }
  180. // 商城
  181. function shangcheng() {
  182. uni.navigateTo({
  183. url: '/pages/chanpinShop/index'
  184. })
  185. }
  186. </script>