my.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 v-if="appleCode=='true'&&currentPlatform=='ios' || currentPlatform=='android'" class="list-item"
  30. @click="duihuamaDuihuan">
  31. <icon class="list-icon duihuanma-icon"></icon>
  32. <text>兑换码</text>
  33. </view>
  34. <view class="list-item" @click="test">
  35. <icon class="list-icon yysz-icon"></icon>
  36. <text>test</text>
  37. </view>
  38. </view>
  39. </view>
  40. <duihuanmaDialog ref="duihuanmaDialogRef" @confirm-btn="duihuanmaBtn" title="兑换"></duihuanmaDialog>
  41. <loginComp ref="loginRef"></loginComp>
  42. <!-- 底部 -->
  43. <custom-tab-bar :show="true" :current-index="currentTabIndex" />
  44. </view>
  45. </template>
  46. <script setup>
  47. import duihuanmaDialog from "./components/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 loginComp from "@/components/loginComp/index.vue"
  58. import {
  59. onLoad,
  60. onShow
  61. } from '@dcloudio/uni-app';
  62. import {
  63. reactive,
  64. ref
  65. } from "vue";
  66. let appleCode =ref(null)
  67. let currentPlatform = ref(null);
  68. let authInfo = ref(null);
  69. let loginRef = ref(null);
  70. let currentTabIndex = ref(3)
  71. let myInfoData = reactive({
  72. userImg: '',
  73. userName: '',
  74. credit: '',
  75. vipFlag: '',
  76. nickName: '',
  77. icon: '',
  78. });
  79. let pageFrom = ref(null)
  80. onShow(() => {
  81. currentTabIndex.value = 3
  82. if(pageFrom.value ==='myInfo'){
  83. getMyInfo();
  84. }
  85. })
  86. /***************** 测试 ******************/
  87. const testRef = ref(null)
  88. function handleTest() {
  89. testRef.value.showPopup(7)
  90. }
  91. /***************** 测试 ******************/
  92. // 获取用户数据
  93. function getMyInfo() {
  94. myInfo({}).then(res => {
  95. myInfoData.userName = res.data.userName;
  96. myInfoData.nickName = res.data.nickName;
  97. pageFrom.value = ''
  98. appleCode.value = res.data.appleCode.toString()
  99. if (res.data.nickName) {
  100. myInfoData.nickName = res.data.nickName;
  101. } else {
  102. myInfoData.nickName = '鹅状元';
  103. }
  104. if (res.data.icon) {
  105. myInfoData.icon = res.data.icon;
  106. } else {
  107. getUserImg(res.data.growthType)
  108. }
  109. })
  110. }
  111. // 获取用户头像
  112. function getUserImg(data) {
  113. switch (data) {
  114. case 0:
  115. myInfoData.icon = 'static/images/my/head-img0.png'
  116. break;
  117. case 1:
  118. myInfoData.icon = 'static/images/my/head-img1.png'
  119. break;
  120. case 2:
  121. myInfoData.icon = 'static/images/my/head-img2.png'
  122. break;
  123. case 3:
  124. myInfoData.icon = 'static/images/my/head-img3.png'
  125. break;
  126. default:
  127. myInfoData.icon = 'static/images/my/head-unlogin-img.png'
  128. break;
  129. }
  130. }
  131. function yingyongshezhi() {
  132. pageFrom.value = 'myInfo'
  133. uni.navigateTo({
  134. url: '/pages/chanpinMy/myInfo'
  135. })
  136. }
  137. function ddBtn(){
  138. uni.navigateTo({
  139. url: '/pages/chanpinMy/order'
  140. })
  141. }
  142. function duihuamaDuihuan() {
  143. // 兑换码兑换策略
  144. if (currentPlatform.value == 'ios') {
  145. // ios
  146. if (authInfo.value.youke) {
  147. // 非登录
  148. } else {
  149. // 已登录
  150. duihuanmaDialogRef.value.handleShow();
  151. }
  152. } else {
  153. // android
  154. if (authInfo.value.youke) {
  155. // 非登录 -> 去登录
  156. } else {
  157. // 已登录
  158. duihuanmaDialogRef.value.handleShow();
  159. }
  160. }
  161. }
  162. function duihuanmaBtn() {
  163. let req = {
  164. code: data
  165. }
  166. duihuanmaCode(req).then(res => {
  167. if (res.code == 0) {
  168. toast('兑换成功')
  169. const localList = cacheManager.get('auth').levelIdList || []
  170. const mergeList = [...new Set([...localList, ...res.data.levelIdList])]
  171. cacheManager.updateObject('auth', {
  172. levelIdList: mergeList
  173. })
  174. uni.redirectTo({
  175. url: '/pages/my/index'
  176. })
  177. } else {
  178. toast('兑换失败请重试或联系管理员')
  179. return false
  180. }
  181. }).catch(err => {
  182. })
  183. }
  184. onLoad((options) => {
  185. uni.hideTabBar()
  186. getAuthData();
  187. getMyInfo();
  188. isIOSorAndroid()
  189. })
  190. function isIOSorAndroid() {
  191. const systemInfo = uni.getSystemInfoSync();
  192. if (systemInfo.platform == 'ios') {
  193. currentPlatform.value = 'ios'
  194. } else {
  195. currentPlatform.value = 'android'
  196. }
  197. }
  198. function getAuthData() {
  199. authInfo.value = cacheManager.get('auth');
  200. }
  201. function test() {
  202. loginRef.value.showPopup()
  203. }
  204. </script>