my.vue 4.6 KB

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