index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <view>
  3. <view class="ezy-navBar-box">
  4. <view @click="handleBack" class="nav-bar-icon"></view>
  5. <text class="nav-bar-title">我的错题</text>
  6. </view>
  7. <view class="uni-padding-wrap uni-common-mt">
  8. <uni-segmented-control :current="data.current" :values="data.items" style-type="button"
  9. active-color="#007aff" @clickItem="onChangeTab" />
  10. </view>
  11. <view class="content">
  12. <view v-if="data.current === 0">
  13. <!--数学-->
  14. <uni-list>
  15. <uni-list-item v-for="item in data.shuxue.list">
  16. <template v-slot:body>
  17. <view class="slot-box">
  18. {{ item }}
  19. <text class="slot-text">{{ item.title }}</text>
  20. <text class="slot-text">{{ item.date }}</text>
  21. <text class="slot-text">错题数:{{ item.count }}题</text>
  22. <button @click="getCuotiData(item)">查看错题</button>
  23. </view>
  24. </template>
  25. </uni-list-item>
  26. <uni-load-more :status="data.shuxue.state" @click="getMore(0)"></uni-load-more>
  27. </uni-list>
  28. </view>
  29. <view v-if="data.current === 1">
  30. <!--英语-->
  31. <uni-list>
  32. <uni-list-item v-for="item in data.yingyu.list">
  33. <template v-slot:body>
  34. <view class="slot-box">
  35. {{ item }}
  36. <text class="slot-text">title</text>
  37. <text class="slot-text">date</text>
  38. <text class="slot-text">wrong</text>
  39. <button>查看错题</button>
  40. </view>
  41. </template>
  42. </uni-list-item>
  43. <uni-load-more :status="data.yingyu.state" @click="getMore(1)"></uni-load-more>
  44. </uni-list>
  45. </view>
  46. </view>
  47. <cuoti ref="wrongRef" :list="data.wrongList" @back="handleBackFromCuoti"></cuoti>
  48. </view>
  49. </template>
  50. <script setup>
  51. import {
  52. reactive,
  53. ref
  54. } from "vue";
  55. import {
  56. getWrongData
  57. } from "@/api/wrong";
  58. import {
  59. onLoad
  60. } from "@dcloudio/uni-app";
  61. import cuoti from "@/components/chengji/chengji.vue";
  62. import {
  63. getWrongInfo
  64. } from "@/api/wrong";
  65. const wrongRef = ref(null);
  66. const data = reactive({
  67. items: ['数学', '英语'],
  68. current: 0,
  69. shuxue: {
  70. page: 0,
  71. list: [],
  72. loading: false,
  73. state: 'more',
  74. },
  75. yingyu: {
  76. page: 0,
  77. list: [],
  78. loading: false,
  79. state: 'more',
  80. },
  81. wrongList: [],
  82. })
  83. function handleBack() {
  84. uni.redirectTo({
  85. url: '/pages/my/index'
  86. })
  87. }
  88. function handleBackFromCuoti() {
  89. wrongRef.value.closePopup();
  90. }
  91. function onChangeTab(e) {
  92. if (data.current !== e.currentIndex) {
  93. data.current = e.currentIndex
  94. }
  95. }
  96. function getMore(code) {
  97. const opt = {
  98. page: 1,
  99. size: 10, // 固定查询10条
  100. }
  101. if (code == 0) {
  102. if (data.shuxue.state == 'no-more') return;
  103. data.shuxue.state = 'loading';
  104. // 数学
  105. data.shuxue.page++;
  106. opt.page = data.shuxue.page;
  107. } else if (code == 1) {
  108. if (data.yingyu.state == 'no-more') return;
  109. data.yingyu.state = 'loading';
  110. // 英语
  111. data.yingyu.page++;
  112. opt.page = data.yingyu.page;
  113. }
  114. getWrongData(opt).then(res => {
  115. if (code == 0) {
  116. data.shuxue.list.push(res.data);
  117. } else if (code == 1) {
  118. data.yingyu.list.push(res.data);
  119. }
  120. if (res.data.total * res.data.size >= res.data.length) {
  121. if (code == 0) {
  122. data.shuxue.state = 'no-more';
  123. } else if (code == 1) {
  124. data.yingyu.state = 'no-more';
  125. }
  126. } else {
  127. if (code == 0) {
  128. data.shuxue.state = 'more';
  129. } else if (code == 1) {
  130. data.yingyu.state = 'more';
  131. }
  132. }
  133. }).catch(err => {
  134. if (code == 0) {
  135. data.shuxue.state = 'more';
  136. } else if (code == 1) {
  137. data.yingyu.state = 'more';
  138. }
  139. })
  140. }
  141. function getCuotiData(data) {
  142. getWrongInfo({
  143. id: data.id
  144. }).then(res => {
  145. data.wrongList = res.data;
  146. wrongRef.value.showPopup();
  147. })
  148. }
  149. onLoad(() => {
  150. getMore(data.current);
  151. })
  152. </script>
  153. <style>
  154. </style>