my.vue 5.3 KB

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