index.vue 8.7 KB

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