my.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <view class="ezy-my-page">
  3. <view class="icon-title-navBar-box my-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. <tipMiddleDialog ref="goLoRef" @confirm-btn="btntxt" :content="tishiTxt" qrBtnName="去登录"></tipMiddleDialog>
  46. <!-- 底部 -->
  47. <custom-tab-bar :show="true" :current-index="currentTabIndex" />
  48. </view>
  49. </template>
  50. <script setup>
  51. import cacheManager from '@/utils/cacheManager';
  52. import {
  53. myInfo,
  54. zhuxiao,
  55. duihuanmaCode,
  56. myCardList,
  57. commonCardList
  58. } from '@/api/my.js'
  59. import CustomTabBar from '@/components/custom-tabbar/index.vue';
  60. import goLogin from "@/components/goLogin/goLogin.vue"
  61. import tipMiddleDialog from '@/components/dialog/tipMiddleDialog.vue';
  62. import {
  63. onLoad,
  64. onShow
  65. } from '@dcloudio/uni-app';
  66. import {
  67. reactive,
  68. ref
  69. } from "vue";
  70. import {
  71. getUserIsYouke,
  72. toast
  73. } from "../../utils/common";
  74. let appleCode = ref(null)
  75. let currentPlatform = ref(null);
  76. let authInfo = ref(null);
  77. let loginRef = ref(null);
  78. let currentTabIndex = ref(3)
  79. let isShowBindPhone = ref(false);
  80. let myInfoData = reactive({
  81. userImg: '',
  82. userName: '',
  83. credit: '',
  84. vipFlag: '',
  85. nickName: '',
  86. icon: '',
  87. });
  88. let pageFrom = ref(null)
  89. const goLoRef = ref(null)
  90. let tishiTxt = ref('您现在是游客身份,请先登录再进行兑换操作!')
  91. onShow(() => {
  92. console.log('pageFrom.value', pageFrom.value);
  93. currentTabIndex.value = 3
  94. if (pageFrom.value === 'myInfo') {
  95. getMyInfo();
  96. }
  97. if (getUserIsYouke()) {
  98. isShowBindPhone.value = true
  99. } else {
  100. isShowBindPhone.value = false
  101. }
  102. })
  103. function btntxt() {
  104. loginRef.value.showDl()
  105. }
  106. /***************** 测试 ******************/
  107. const testRef = ref(null)
  108. function handleTest() {
  109. testRef.value.showPopup(7)
  110. }
  111. /***************** 测试 ******************/
  112. function bangPhone() {
  113. pageFrom.value = 'myInfo'
  114. uni.navigateTo({
  115. url: '/pages/bindPhone/bindPhone?from=my'
  116. })
  117. }
  118. // 获取用户数据
  119. function getMyInfo() {
  120. return myInfo({}).then(res => {
  121. console.log('res', res);
  122. myInfoData.userName = res.data.userName;
  123. myInfoData.nickName = res.data.nickName;
  124. pageFrom.value = ''
  125. appleCode.value = res.data.appleCode.toString()
  126. myInfoData.nickName = res.data.nickName;
  127. if (res.data.icon) {
  128. myInfoData.icon = res.data.icon;
  129. } else {
  130. getUserImg()
  131. }
  132. })
  133. }
  134. // 获取用户头像
  135. function getUserImg() {
  136. myInfoData.icon = 'static/images/my/head-img1.png'
  137. }
  138. function yingyongshezhi() {
  139. pageFrom.value = 'myInfo'
  140. uni.navigateTo({
  141. url: '/pages/chanpinMy/myInfo'
  142. })
  143. }
  144. function ddBtn() {
  145. uni.navigateTo({
  146. url: '/pages/chanpinMy/order'
  147. })
  148. }
  149. function duihuamaDuihuan() {
  150. // 兑换码兑换策略
  151. if (getUserIsYouke()) {
  152. // 非登录 -- 登录
  153. goLoRef.value.handleShow();
  154. } else {
  155. // 已登录
  156. uni.navigateTo({
  157. url: '/pages/chanpinMy/duihuanma'
  158. })
  159. }
  160. }
  161. function handleSuccess(authInfo) {
  162. // 登录成功更改用户名
  163. // myInfoData.userName = authInfo.userName;
  164. getMyInfo().then(() => {
  165. // 前往兑换码
  166. uni.navigateTo({
  167. url: '/pages/chanpinMy/duihuanma'
  168. })
  169. });
  170. }
  171. onLoad((options) => {
  172. uni.hideTabBar()
  173. getAuthData();
  174. getMyInfo();
  175. isIOSorAndroid()
  176. })
  177. function isIOSorAndroid() {
  178. const systemInfo = uni.getSystemInfoSync();
  179. if (systemInfo.platform == 'ios') {
  180. currentPlatform.value = 'ios'
  181. } else {
  182. currentPlatform.value = 'android'
  183. }
  184. }
  185. function getAuthData() {
  186. authInfo.value = cacheManager.get('auth');
  187. }
  188. // 商城
  189. function shangcheng() {
  190. uni.navigateTo({
  191. url: '/pages/chanpinShop/index'
  192. })
  193. }
  194. </script>