index.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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" :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. function handleBack() {
  119. uni.redirectTo({
  120. url: '/pages/my/index'
  121. })
  122. }
  123. function handleBackFromCuoti() {
  124. wrongRef.value.closePopup();
  125. }
  126. function onChangeTab(e) {
  127. if (data.current !== e.currentIndex) {
  128. data.current = e.currentIndex;
  129. if (data.current == 0) {
  130. data.shuxue.page = 0
  131. } else if (data.current == 1) {
  132. data.yingyu.page = 0
  133. }
  134. refreshData(data.current);
  135. }
  136. }
  137. function refreshData(code) {
  138. const opt = {
  139. page: 1,
  140. size: 10, // 固定查询10条
  141. cardId: data.current + 1 // 前台索引加1为学科cardId
  142. }
  143. if (code == 0) {
  144. data.shuxue.list = [];
  145. // 数学
  146. data.shuxue.state = 'loading';
  147. data.shuxue.page++;
  148. opt.page = data.shuxue.page;
  149. } else if (code == 1) {
  150. data.yingyu.list = [];
  151. // 英语
  152. data.yingyu.state = 'loading';
  153. data.yingyu.page++;
  154. opt.page = data.yingyu.page;
  155. }
  156. getWrongData(opt).then(res => {
  157. if (code == 0) {
  158. data.shuxue.list = data.shuxue.list.concat(res.data.data);
  159. data.shuxue.loading = false;
  160. } else if (code == 1) {
  161. data.yingyu.list = data.yingyu.list.concat(res.data.data);
  162. data.yingyu.loading = false;
  163. }
  164. if (code == 0) {
  165. if (res.data.total >= data.shuxue.list.length) {
  166. // 数学
  167. data.shuxue.state = 'no-more';
  168. data.shuxue.loading = false;
  169. } else {
  170. // 数学
  171. data.shuxue.state = 'more';
  172. data.shuxue.loading = false;
  173. }
  174. } else if (code == 1) {
  175. if (res.data.total >= data.yingyu.list.length) {
  176. // 英语
  177. data.yingyu.state = 'no-more';
  178. data.yingyu.loading = false;
  179. } else {
  180. // 英语
  181. data.yingyu.state = 'more';
  182. data.yingyu.loading = false;
  183. }
  184. }
  185. }).catch(err => {
  186. if (code == 0) {
  187. // 数学
  188. data.shuxue.state = 'more';
  189. data.shuxue.loading = false;
  190. } else if (code == 1) {
  191. // 英语
  192. data.yingyu.state = 'more';
  193. data.yingyu.loading = false;
  194. }
  195. })
  196. }
  197. function getMore(code) {
  198. const opt = {
  199. page: 1,
  200. size: 10, // 固定查询10条
  201. cardId: data.current + 1 // 前台索引加1为学科cardId
  202. }
  203. if (code == 0) {
  204. if (data.shuxue.state == 'no-more') return;
  205. // 数学
  206. data.shuxue.state = 'loading';
  207. data.shuxue.page++;
  208. opt.page = data.shuxue.page;
  209. } else if (code == 1) {
  210. // 英语
  211. if (data.yingyu.state == 'no-more') return;
  212. data.yingyu.state = 'loading';
  213. data.yingyu.page++;
  214. opt.page = data.yingyu.page;
  215. }
  216. getWrongData(opt).then(res => {
  217. if (code == 0) {
  218. data.shuxue.list = data.shuxue.list.concat(res.data.data);
  219. data.shuxue.loading = false;
  220. } else if (code == 1) {
  221. data.yingyu.list = data.yingyu.list.concat(res.data.data);
  222. data.yingyu.loading = false;
  223. }
  224. if (code == 0) {
  225. if (res.data.total >= data.shuxue.list.length) {
  226. // 数学
  227. data.shuxue.state = 'no-more';
  228. data.shuxue.state_text = '没有更多啦';
  229. data.shuxue.loading = false;
  230. } else {
  231. // 数学
  232. data.shuxue.state = 'more';
  233. data.shuxue.state_text = '加载更多';
  234. data.shuxue.loading = false;
  235. }
  236. } else if (code == 1) {
  237. if (res.data.total >= data.yingyu.list.length) {
  238. // 英语
  239. data.yingyu.state = 'no-more';
  240. data.yingyu.state_text = '没有更多啦';
  241. data.yingyu.loading = false;
  242. } else {
  243. // 英语
  244. data.yingyu.state = 'more';
  245. data.yingyu.state_text = '加载更多';
  246. data.yingyu.loading = false;
  247. }
  248. }
  249. }).catch(err => {
  250. if (code == 0) {
  251. // 数学
  252. data.shuxue.state = 'more';
  253. data.shuxue.state_text = '加载更多';
  254. data.shuxue.loading = false;
  255. } else if (code == 1) {
  256. // 英语
  257. data.yingyu.state = 'more';
  258. data.yingyu.state_text = '加载更多';
  259. data.yingyu.loading = false;
  260. }
  261. })
  262. }
  263. function formatListToUse(list) {
  264. list.forEach((item, index) => {
  265. item.mta_show = false;
  266. if (item.type == 3) {
  267. item.result = JSON.parse(item.result);
  268. item.placeholders = item.result.map((item, cindex) => `[bank${cindex+1}]`)
  269. item.reply = item.reply ? JSON.parse(item.reply) : item.result.map(() => '');
  270. }
  271. })
  272. }
  273. function getCuotiData(item) {
  274. getWrongInfo({
  275. cardId: data.current + 1,
  276. cdate: item.cdate
  277. }).then(res => {
  278. formatListToUse(res.data)
  279. data.wrongList = res.data;
  280. wrongRef.value.showPopup();
  281. })
  282. }
  283. function onRefresh() {
  284. if (data.current == 0) {
  285. data.shuxue.page = 0;
  286. data.shuxue.list = [];
  287. data.shuxue.loading = true;
  288. } else if (data.current == 1) {
  289. data.yingyu.page = 0;
  290. data.yingyu.list = [];
  291. data.yingyu.loading = true;
  292. }
  293. refreshData(data.current);
  294. }
  295. onLoad(() => {
  296. getMore(data.current);
  297. })
  298. </script>
  299. <style>
  300. </style>