index.vue 7.9 KB

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