my.vue 4.7 KB

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