my.vue 5.1 KB

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