index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <view class="ezy-shop-page">
  3. <!-- 返回区域 -->
  4. <view class="icon-title-navBar-box">
  5. <view class="nav-bar-icon" @click="handleBack"></view>
  6. <text class="nav-bar-title">商城</text>
  7. </view>
  8. <view class="ezy-page-body">
  9. <!-- 头部区域 -->
  10. <view class="ezy-xueke-tab-box">
  11. <!-- 动画按钮 -->
  12. <ezyActiveVue class="ezy-btn-active tab-item" v-for="item in data.list" :key="item.key"
  13. :class="{active: item.key == data.chanpinActiveSelect}" @aclick="handleSelectChanpin(item)">
  14. {{ item.label }}
  15. </ezyActiveVue>
  16. </view>
  17. <!-- 数学列表 -->
  18. <shuxueListVue v-if="data.chanpinActiveSelect == 'shuxue'" :list="data.shuxueList"></shuxueListVue>
  19. <!-- 英语列表 -->
  20. <yingyuListVue v-if="data.chanpinActiveSelect == 'yingyu'" :list="data.yingyuList"></yingyuListVue>
  21. <!-- 语文列表 -->
  22. <yuwenListVue v-if="data.chanpinActiveSelect == 'yuwen'" :list="data.yuwenList"></yuwenListVue>
  23. </view>
  24. </view>
  25. </template>
  26. <script setup>
  27. import {
  28. reactive,
  29. ref
  30. } from "vue";
  31. import shuxueListVue from "./components/shuxueList.vue";
  32. import yingyuListVue from "./components/yingyuList.vue";
  33. import yuwenListVue from "./components/yuwenList.vue";
  34. import {
  35. onLoad,
  36. onShow
  37. } from "@dcloudio/uni-app"
  38. import * as shopHttp from "@/api/shop.js"
  39. import ezyActiveVue from "@/components/ezyActive/ezyActive.vue";
  40. import {
  41. getChanpinTongyongIndex
  42. } from "@/api/chanpinShuxue";
  43. import {
  44. getFullTimer
  45. } from "@/utils/common";
  46. let currentTabIndex = ref(0)
  47. const data = reactive({
  48. list: [{
  49. key: 'shuxue',
  50. label: '数学'
  51. },
  52. {
  53. key: 'yingyu',
  54. label: '英语'
  55. },
  56. {
  57. key: 'yuwen',
  58. label: '语文'
  59. }
  60. ],
  61. chanpinActiveSelect: 'shuxue',
  62. shuxueList: [],
  63. yingyuList: [],
  64. yuwenList: [],
  65. })
  66. function getFormatData(data) {
  67. const shuxue = data.shuxue || {};
  68. const yingyu = data.yingyu || {};
  69. const yuwen = data.yuwen || {};
  70. return {
  71. shuxue: Object.entries(shuxue).map(([chanpin, value]) => {
  72. return {
  73. chanpin,
  74. value
  75. };
  76. }),
  77. yingyu: Object.entries(yingyu).map(([chanpin, value]) => {
  78. return {
  79. chanpin,
  80. value
  81. };
  82. }),
  83. yuwen: Object.entries(yuwen).map(([chanpin, value]) => {
  84. return {
  85. chanpin,
  86. value
  87. };
  88. }),
  89. }
  90. }
  91. function getPageData() {
  92. shopHttp.getAppShopIndex().then(res => {
  93. const result = getFormatData(res.data);
  94. data.shuxueList = result.shuxue;
  95. data.yingyuList = result.yingyu;
  96. data.yuwenList = result.yuwen;
  97. })
  98. }
  99. function handleSelectChanpin(item) {
  100. data.chanpinActiveSelect = item.key
  101. }
  102. onShow(() => {
  103. currentTabIndex.value = 0;
  104. data.chanpinActiveSelect = 'shuxue';
  105. if (getFullTimer() !== `2026-01-28`) {
  106. //每日刷新
  107. getPageData();
  108. } else {
  109. getPageData()
  110. }
  111. })
  112. onLoad(() => {
  113. })
  114. function handleBack() {
  115. uni.navigateBack()
  116. }
  117. </script>