my.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. <bindPhone ref="bindPhoneRef" :skipBtnFlag='false' @success="bingPhoneSuccess"></bindPhone>
  45. <!-- 底部 -->
  46. <custom-tab-bar :show="true" :current-index="currentTabIndex" />
  47. </view>
  48. </template>
  49. <script setup>
  50. import duihuanmaDialog from "./components/duihuanma/duihuanmaDialog.vue"
  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 bindPhone from "@/components/bindPhone/bindPhone.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 bindPhoneRef = ref(null);
  79. let currentTabIndex = ref(3)
  80. let myInfoData = reactive({
  81. userImg: '',
  82. userName: '',
  83. credit: '',
  84. vipFlag: '',
  85. nickName: '',
  86. icon: '',
  87. });
  88. let pageFrom = ref(null)
  89. onShow(() => {
  90. currentTabIndex.value = 3
  91. if (pageFrom.value === 'myInfo') {
  92. getMyInfo();
  93. }
  94. })
  95. /***************** 测试 ******************/
  96. const testRef = ref(null)
  97. function handleTest() {
  98. testRef.value.showPopup(7)
  99. }
  100. /***************** 测试 ******************/
  101. function bingPhoneSuccess(flag, tel) {
  102. toast("绑定成功")
  103. cacheManager.updateObject('auth', {
  104. userName: tel,
  105. })
  106. }
  107. // 获取用户数据
  108. function getMyInfo() {
  109. myInfo({}).then(res => {
  110. myInfoData.userName = res.data.userName;
  111. myInfoData.nickName = res.data.nickName;
  112. pageFrom.value = ''
  113. appleCode.value = res.data.appleCode.toString()
  114. if (res.data.nickName) {
  115. myInfoData.nickName = res.data.nickName;
  116. } else {
  117. myInfoData.nickName = '鹅状元';
  118. }
  119. if (res.data.icon) {
  120. myInfoData.icon = res.data.icon;
  121. } else {
  122. getUserImg(res.data.growthType)
  123. }
  124. })
  125. }
  126. // 获取用户头像
  127. function getUserImg(data) {
  128. switch (data) {
  129. case 0:
  130. myInfoData.icon = 'static/images/my/head-img0.png'
  131. break;
  132. case 1:
  133. myInfoData.icon = 'static/images/my/head-img1.png'
  134. break;
  135. case 2:
  136. myInfoData.icon = 'static/images/my/head-img2.png'
  137. break;
  138. case 3:
  139. myInfoData.icon = 'static/images/my/head-img3.png'
  140. break;
  141. default:
  142. myInfoData.icon = 'static/images/my/head-unlogin-img.png'
  143. break;
  144. }
  145. }
  146. function yingyongshezhi() {
  147. pageFrom.value = 'myInfo'
  148. uni.navigateTo({
  149. url: '/pages/chanpinMy/myInfo'
  150. })
  151. }
  152. function ddBtn() {
  153. uni.navigateTo({
  154. url: '/pages/chanpinMy/order'
  155. })
  156. }
  157. function bangPhone() {
  158. bindPhoneRef.value.showDl();
  159. }
  160. function duihuamaDuihuan() {
  161. // 兑换码兑换策略
  162. if (getUserIsYouke()) {
  163. // 非登录 -- 登录
  164. loginRef.value.showDl()
  165. } else {
  166. // 已登录
  167. uni.navigateTo({
  168. url: '/pages/chanpinMy/duihuanma'
  169. })
  170. }
  171. }
  172. function handleSuccess(authInfo) {
  173. // 登录成功更改用户名
  174. myInfoData.userName = authInfo.userName;
  175. // 前往兑换码
  176. uni.navigateTo({
  177. url: '/pages/chanpinMy/duihuanma'
  178. })
  179. }
  180. onLoad((options) => {
  181. uni.hideTabBar()
  182. getAuthData();
  183. getMyInfo();
  184. isIOSorAndroid()
  185. })
  186. function isIOSorAndroid() {
  187. const systemInfo = uni.getSystemInfoSync();
  188. if (systemInfo.platform == 'ios') {
  189. currentPlatform.value = 'ios'
  190. } else {
  191. currentPlatform.value = 'android'
  192. }
  193. }
  194. function getAuthData() {
  195. authInfo.value = cacheManager.get('auth');
  196. }
  197. // 商城
  198. function shangcheng() {
  199. uni.navigateTo({
  200. url: '/pages/chanpinShop/index'
  201. })
  202. }
  203. </script>