index.vue 8.4 KB

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