index.vue 8.2 KB

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