index.vue 2.9 KB

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