index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <view class="ezy-cuoti-page">
  3. <view class="icon-title-navBar-box">
  4. <view @click="handleBack" class="nav-bar-icon"></view>
  5. <text class="nav-bar-title">我的错题</text>
  6. </view>
  7. <view class="cuoti-border-box">
  8. <uni-segmented-control :current="data.current" :values="data.items" active-color="#3A7FE9"
  9. @clickItem="onChangeTab" class="cuo-tab-box" />
  10. <view class="cuoti-content-box">
  11. <view v-if="data.current === 0">
  12. <scroll-view style="height: 300px;" scroll-y="true" refresher-enabled="true"
  13. :refresher-triggered="data.shuxue.loading" :refresher-threshold="50"
  14. refresher-background="lightgreen" @refresherrefresh="onRefresh">
  15. <!--数学-->
  16. <uni-list>
  17. <uni-list-item v-for="item in data.shuxue.list">
  18. <template v-slot:body>
  19. <view class="slot-box">
  20. <!-- 时间 -->
  21. <text class="slot-text">日期{{ item.cdate }}</text>
  22. <!-- 数量 -->
  23. <text class="slot-text">错题数:{{ item.count }}题</text>
  24. <button @click="getCuotiData(item)">查看错题</button>
  25. </view>
  26. </template>
  27. </uni-list-item>
  28. <uni-load-more :status="data.shuxue.state" @click="getMore(0)"
  29. :contentText="data.shuxue.contentText"></uni-load-more>
  30. </uni-list>
  31. </scroll-view>
  32. </view>
  33. <view v-if="data.current === 1">
  34. <scroll-view style="height: 300px;" scroll-y="true" refresher-enabled="true"
  35. :refresher-triggered="data.yingyu.loading" :refresher-threshold="50"
  36. refresher-background="lightgreen" @refresherrefresh="onRefresh">
  37. <!--英语-->
  38. <uni-list>
  39. <uni-list-item v-for="item in data.yingyu.list">
  40. <template v-slot:body>
  41. <view class="slot-box">
  42. <!-- 时间 -->
  43. <text class="slot-text">日期{{ item.cdate }}</text>
  44. <!-- 数量 -->
  45. <text class="slot-text">错题数:{{ item.count }}题</text>
  46. <button @click="getCuotiData(item)">查看错题</button>
  47. </view>
  48. </template>
  49. </uni-list-item>
  50. <uni-load-more :status="data.yingyu.state" @click="getMore(1)"
  51. :contentText="data.yingyu.contentText"></uni-load-more>
  52. </uni-list>
  53. </scroll-view>
  54. </view>
  55. </view>
  56. </view>
  57. <cuoti ref="wrongRef" :list="data.wrongList" @back="handleBackFromCuoti"></cuoti>
  58. </view>
  59. </template>
  60. <script setup>
  61. import {
  62. reactive,
  63. ref
  64. } from "vue";
  65. import {
  66. getWrongData
  67. } from "@/api/wrong";
  68. import {
  69. onLoad
  70. } from "@dcloudio/uni-app";
  71. import cuoti from "@/components/chengji/chengji.vue";
  72. import {
  73. getWrongInfo
  74. } from "@/api/wrong";
  75. const wrongRef = ref(null);
  76. const data = reactive({
  77. items: ['数学', '英语'],
  78. current: 0,
  79. shuxue: {
  80. page: 0,
  81. list: [],
  82. loading: false,
  83. state: 'more',
  84. state_text: '加载更多'
  85. },
  86. yingyu: {
  87. page: 0,
  88. list: [],
  89. loading: false,
  90. state: 'more',
  91. state_text: '加载更多'
  92. },
  93. wrongList: [],
  94. })
  95. function handleBack() {
  96. uni.redirectTo({
  97. url: '/pages/my/index'
  98. })
  99. }
  100. function handleBackFromCuoti() {
  101. wrongRef.value.closePopup();
  102. }
  103. function onChangeTab(e) {
  104. if (data.current !== e.currentIndex) {
  105. data.current = e.currentIndex;
  106. if (data.current == 0) {
  107. data.shuxue.page = 0
  108. } else if (data.current == 1) {
  109. data.yingyu.page = 0
  110. }
  111. refreshData(data.current);
  112. }
  113. }
  114. function refreshData(code) {
  115. const opt = {
  116. page: 1,
  117. size: 10, // 固定查询10条
  118. cardId: data.current + 1 // 前台索引加1为学科cardId
  119. }
  120. if (code == 0) {
  121. data.shuxue.list = [];
  122. // 数学
  123. data.shuxue.state = 'loading';
  124. data.shuxue.page++;
  125. opt.page = data.shuxue.page;
  126. } else if (code == 1) {
  127. data.yingyu.list = [];
  128. // 英语
  129. data.yingyu.state = 'loading';
  130. data.yingyu.page++;
  131. opt.page = data.yingyu.page;
  132. }
  133. getWrongData(opt).then(res => {
  134. if (code == 0) {
  135. data.shuxue.list = data.shuxue.list.concat(res.data.data);
  136. data.shuxue.loading = false;
  137. } else if (code == 1) {
  138. data.yingyu.list = data.yingyu.list.concat(res.data.data);
  139. data.yingyu.loading = false;
  140. }
  141. if (code == 0) {
  142. if (res.data.total >= data.shuxue.list.length) {
  143. // 数学
  144. data.shuxue.state = 'no-more';
  145. data.shuxue.state_text = '没有更多啦';
  146. data.shuxue.loading = false;
  147. } else {
  148. // 数学
  149. data.shuxue.state = 'more';
  150. data.shuxue.state_text = '加载更多';
  151. data.shuxue.loading = false;
  152. }
  153. } else if (code == 1) {
  154. if (res.data.total >= data.yingyu.list.length) {
  155. // 英语
  156. data.yingyu.state = 'no-more';
  157. data.yingyu.state_text = '没有更多啦';
  158. data.yingyu.loading = false;
  159. } else {
  160. // 英语
  161. data.yingyu.state = 'more';
  162. data.yingyu.state_text = '加载更多';
  163. data.yingyu.loading = false;
  164. }
  165. }
  166. }).catch(err => {
  167. if (code == 0) {
  168. // 数学
  169. data.shuxue.state = 'more';
  170. data.shuxue.state_text = '加载更多';
  171. data.shuxue.loading = false;
  172. } else if (code == 1) {
  173. // 英语
  174. data.yingyu.state = 'more';
  175. data.yingyu.state_text = '加载更多';
  176. data.yingyu.loading = false;
  177. }
  178. })
  179. }
  180. function getMore(code) {
  181. const opt = {
  182. page: 1,
  183. size: 10, // 固定查询10条
  184. cardId: data.current + 1 // 前台索引加1为学科cardId
  185. }
  186. if (code == 0) {
  187. if (data.shuxue.state == 'no-more') return;
  188. // 数学
  189. data.shuxue.state = 'loading';
  190. data.shuxue.page++;
  191. opt.page = data.shuxue.page;
  192. } else if (code == 1) {
  193. // 英语
  194. if (data.yingyu.state == 'no-more') return;
  195. data.yingyu.state = 'loading';
  196. data.yingyu.page++;
  197. opt.page = data.yingyu.page;
  198. }
  199. getWrongData(opt).then(res => {
  200. if (code == 0) {
  201. data.shuxue.list = data.shuxue.list.concat(res.data.data);
  202. data.shuxue.loading = false;
  203. } else if (code == 1) {
  204. data.yingyu.list = data.yingyu.list.concat(res.data.data);
  205. data.yingyu.loading = false;
  206. }
  207. if (code == 0) {
  208. if (res.data.total >= data.shuxue.list.length) {
  209. // 数学
  210. data.shuxue.state = 'no-more';
  211. data.shuxue.state_text = '没有更多啦';
  212. data.shuxue.loading = false;
  213. } else {
  214. // 数学
  215. data.shuxue.state = 'more';
  216. data.shuxue.state_text = '加载更多';
  217. data.shuxue.loading = false;
  218. }
  219. } else if (code == 1) {
  220. if (res.data.total >= data.yingyu.list.length) {
  221. // 英语
  222. data.yingyu.state = 'no-more';
  223. data.yingyu.state_text = '没有更多啦';
  224. data.yingyu.loading = false;
  225. } else {
  226. // 英语
  227. data.yingyu.state = 'more';
  228. data.yingyu.state_text = '加载更多';
  229. data.yingyu.loading = false;
  230. }
  231. }
  232. }).catch(err => {
  233. if (code == 0) {
  234. // 数学
  235. data.shuxue.state = 'more';
  236. data.shuxue.state_text = '加载更多';
  237. data.shuxue.loading = false;
  238. } else if (code == 1) {
  239. // 英语
  240. data.yingyu.state = 'more';
  241. data.yingyu.state_text = '加载更多';
  242. data.yingyu.loading = false;
  243. }
  244. })
  245. }
  246. function formatListToUse(list) {
  247. list.forEach((item, index) => {
  248. item.mta_show = false;
  249. if (item.type == 3) {
  250. item.result = JSON.parse(item.result);
  251. item.placeholders = item.result.map((item, cindex) => `[bank${cindex}]`)
  252. item.reply = item.reply ? JSON.parse(item.reply) : item.result.map(() => '');
  253. }
  254. })
  255. }
  256. function getCuotiData(item) {
  257. getWrongInfo({
  258. cardId: data.current + 1,
  259. cdate: item.cdate
  260. }).then(res => {
  261. formatListToUse(res.data)
  262. data.wrongList = res.data;
  263. wrongRef.value.showPopup();
  264. })
  265. }
  266. function onRefresh() {
  267. if (data.current == 0) {
  268. data.shuxue.page = 0;
  269. data.shuxue.list = [];
  270. data.shuxue.loading = true;
  271. } else if (data.current == 1) {
  272. data.yingyu.page = 0;
  273. data.yingyu.list = [];
  274. data.yingyu.loading = true;
  275. }
  276. refreshData(data.current);
  277. }
  278. onLoad(() => {
  279. getMore(data.current);
  280. })
  281. </script>
  282. <style>
  283. </style>