index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. if (data.current == 0) {
  95. data.shuxue.page = 0
  96. } else if (data.current == 1){
  97. data.yingyu.page = 0
  98. }
  99. getMore(data.current);
  100. }
  101. }
  102. function getMore(code) {
  103. const opt = {
  104. page: 1,
  105. size: 10, // 固定查询10条
  106. cardId: data.current+1// 前台索引加1为学科cardId
  107. }
  108. if (code == 0) {
  109. // 数学
  110. if (data.shuxue.state == 'no-more') return;
  111. data.shuxue.state = 'loading';
  112. data.shuxue.page++;
  113. opt.page = data.shuxue.page;
  114. } else if (code == 1) {
  115. // 英语
  116. if (data.yingyu.state == 'no-more') return;
  117. data.yingyu.state = 'loading';
  118. data.yingyu.page++;
  119. opt.page = data.yingyu.page;
  120. }
  121. getWrongData(opt).then(res => {
  122. if (code == 0) {
  123. data.shuxue.list.push(res.data);
  124. } else if (code == 1) {
  125. data.yingyu.list.push(res.data);
  126. }
  127. if (res.data.total * res.data.size >= res.data.length) {
  128. if (code == 0) {
  129. // 数学
  130. data.shuxue.state = 'no-more';
  131. } else if (code == 1) {
  132. // 英语
  133. data.yingyu.state = 'no-more';
  134. }
  135. } else {
  136. if (code == 0) {
  137. // 数学
  138. data.shuxue.state = 'more';
  139. } else if (code == 1) {
  140. // 英语
  141. data.yingyu.state = 'more';
  142. }
  143. }
  144. }).catch(err => {
  145. if (code == 0) {
  146. // 数学
  147. data.shuxue.state = 'more';
  148. } else if (code == 1) {
  149. // 英语
  150. data.yingyu.state = 'more';
  151. }
  152. })
  153. }
  154. function getCuotiData(item) {
  155. getWrongInfo({
  156. cardId: data.current+1,
  157. cdate: item.cdate
  158. }).then(res => {
  159. data.wrongList = res.data;
  160. wrongRef.value.showPopup();
  161. })
  162. }
  163. onLoad(() => {
  164. getMore(data.current);
  165. })
  166. </script>
  167. <style>
  168. </style>