index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <view>
  3. <!--#ifdef APP-PLUS-->
  4. <view class="lz-status_bar">
  5. <view class="lz-top_view"></view>
  6. </view>
  7. <!--#endif-->
  8. <!-- #ifndef MP-WEIXIN -->
  9. <view class="kaoshi-head">
  10. <view class="kaoshi-head-top">
  11. <view class="kaoshi-head-left" @tap="$navigateBack">
  12. <view class="iconfont icon-zuojiantou"></view>
  13. </view>
  14. <view class="kaoshi-head-m">{{name}}</view>
  15. </view>
  16. </view>
  17. <!--#endif-->
  18. <view class="kaoshi-tiku">
  19. <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback"
  20. :down="downOption" :up="upOption">
  21. <block v-for="(item, index) in list" :key="index">
  22. <view class="kaoshi-tiku-content" @tap="goto_detail(item)">
  23. <view class="pub-flex-1">
  24. <view class="kaoshi-tiku-content-flex">
  25. <view class="kaoshi-tiku-content-top">
  26. <view>{{item.name}}
  27. <view v-if="item.is_vip == 1 && !subjectVip" class="vip">
  28. <image src="../../../static/img/vip.png" mode=""></image>
  29. <view>VIP</view>
  30. </view></view>
  31. </view>
  32. <view class="kaoshi-tiku-bilv">{{item.scale.toFixed(0)}}
  33. <view class="kaoshi-remind-title">%</view>
  34. </view>
  35. </view>
  36. <view class="kaoshi-tiku-content-flex">
  37. <view class="kaoshi-tiku-content-bottom">
  38. <view class="iconfont icon-dui2"></view>
  39. <view class="pub-gray">已答题{{item.test_num}}/{{item.total_num}}</view>
  40. </view>
  41. <view class="pub-gray">正确率</view>
  42. </view>
  43. </view>
  44. <view class="iconfont icon-arrow"></view>
  45. </view>
  46. </block>
  47. </mescroll-body>
  48. </view>
  49. <authVip v-if="showAuthVip" @hideAuthVip="showAuthVip = false"></authVip>
  50. </view>
  51. </template>
  52. <script>
  53. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  54. import {
  55. mapState
  56. } from "vuex";
  57. import Error from '@/core/untils/error/index';
  58. import authVip from '@/components/authVip.vue'
  59. export default {
  60. mixins: [MescrollMixin], // 使用mixin
  61. data() {
  62. return {
  63. showAuthVip: false, //是否显示认证vip
  64. mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
  65. // 下拉刷新的配置(可选, 绝大部分情况无需配置)
  66. downOption: {
  67. use: true, // 是否启用下拉刷新; 默认true
  68. auto: false, // 是否在初始化完毕之后自动执行下拉刷新的回调; 默认true
  69. native: false // 启用系统自带的下拉组件,默认false;仅mescroll-body生效,mescroll-uni无效(native: true, 则需在pages.json中配置"enablePullDownRefresh":true)
  70. },
  71. // 上拉加载的配置(可选, 绝大部分情况无需配置)
  72. upOption: {
  73. page: {
  74. num: 0,
  75. size: 10 // 每页数据的数量,默认10
  76. },
  77. noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  78. empty: {
  79. tip: '暂无相关数据'
  80. }
  81. },
  82. // 列表数据
  83. list: [],
  84. pages_params: {
  85. // dotype: '' 'zhangjie 章节', 'moni模拟', 'yicuo易错', 'cuoti错题', 'vip答题'
  86. },
  87. type: '',
  88. name: '',
  89. id: '',
  90. //通过step确定当前页面层次,用于后退时逐层退出
  91. step: 0,
  92. arr: [],
  93. };
  94. },
  95. onLoad(opts) {
  96. this.pages_params = opts
  97. if (opts && opts.from_type) {
  98. this.type = opts.from_type
  99. this.name = opts.name
  100. this.id = opts.id
  101. }
  102. this.arr[0] = 0;
  103. },
  104. onShow() {
  105. if (this.type != '') {
  106. // this.getList()
  107. this.arr[this.step] = (this.id)
  108. }
  109. },
  110. mounted() {},
  111. computed: {
  112. ...mapState(["subject", "userinfo", "subjectVip"]),
  113. },
  114. components: {
  115. authVip
  116. },
  117. onBackPress() {
  118. //逐层退出
  119. if (this.step == 0) {
  120. this.id = this.pages_params.id
  121. this.mescroll.resetUpScroll(false)
  122. } else {
  123. this.step -= 1;
  124. this.id = this.arr[this.step]
  125. this.mescroll.resetUpScroll(false)
  126. return true;
  127. }
  128. },
  129. methods: {
  130. /*上拉加载的回调*/
  131. async upCallback(page) {
  132. let pageNum = page.num; // 页码, 默认从1开始
  133. let pageSize = page.size; // 页长, 默认每页10条
  134. let needLogin = false
  135. if (this.userinfo.token) {
  136. needLogin = true
  137. }
  138. let res = await this.$myHttp.post({
  139. url: this.type == '1' ? this.$myHttp.urlMap.unitList : this.$myHttp.urlMap.zhentiList,
  140. data: {
  141. subject_id: this.subject.id,
  142. unit_id: this.id,
  143. page: pageNum,
  144. limit: pageSize
  145. },
  146. needLogin: needLogin
  147. })
  148. if (res.code == 1) {
  149. // 接口返回的当前页数据列表 (数组)
  150. let curPageData = res.data.data;
  151. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  152. let curPageLen = curPageData.length;
  153. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  154. // let totalPage = data.xxx;
  155. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  156. let totalSize = res.data.total;
  157. this.mescroll.endBySize(curPageLen, totalSize);
  158. if (page.num == 1) this.list = []; //如果是第一页需手动置空列表
  159. this.list = this.list.concat(curPageData); //追加新数据
  160. } else {
  161. this.mescroll.endErr()
  162. }
  163. // 此处仍可以继续写其他接口请求...
  164. // 调用其他方法...
  165. },
  166. // async getList() {
  167. // let needLogin = false
  168. // if (this.userinfo.token) {
  169. // needLogin = true
  170. // }
  171. // let data = {
  172. // subject_id: this.subject.id,
  173. // unit_id:this.id,
  174. // page:1,
  175. // limit:0
  176. // }
  177. // let res = await this.$myHttp.post({
  178. // url: this.type == '1' ? this.$myHttp.urlMap.unitList : this.$myHttp.urlMap.zhentiList,
  179. // data: data,
  180. // needLogin: needLogin
  181. // });
  182. // if (res.code === 1) {
  183. // this.list = res.data.data;
  184. // }
  185. // },
  186. goto_detail(item) {
  187. if (!this.subjectVip && item.is_vip) {
  188. if (this.$myUserLogin.getToken()) {
  189. this.showAuthVip = true
  190. return
  191. } else {
  192. Error.errorNotLoggedIn();
  193. return
  194. }
  195. }
  196. if (this.$myUserLogin.getToken()) {
  197. if (item.is_last == 0) {
  198. //非终极栏目,点击进入下级栏目
  199. this.step += 1;
  200. this.arr[this.step] = (item.id)
  201. this.id = item.id
  202. this.name = item.name
  203. this.mescroll.resetUpScroll(false)
  204. } else if (item.is_last == 1) {
  205. //终极栏目,点击进入答题页
  206. this.$openrul('/pages/questionBank/questionBankAnswer/index?id=' + item.id + '&from_type=' + this
  207. .type + '&name=' + item.name)
  208. }
  209. } else {
  210. Error.errorNotLoggedIn();
  211. }
  212. }
  213. }
  214. };
  215. </script>
  216. <style>
  217. page {
  218. background: #f6f7f9;
  219. }
  220. /*题库列表*/
  221. .kaoshi-tiku {
  222. background: #fff;
  223. }
  224. .kaoshi-tiku-content {
  225. width: 92%;
  226. margin: 0 auto;
  227. display: flex;
  228. flex-direction: row;
  229. align-items: center;
  230. font-size: 16px;
  231. padding: 14px 0;
  232. border-bottom: solid 1px #f5f5f5;
  233. }
  234. .kaoshi-tiku-content-flex {
  235. width: 100%;
  236. display: flex;
  237. justify-content: space-between;
  238. align-items: center;
  239. }
  240. .kaoshi-tiku-content .icon-arrow {
  241. padding-left: 13px;
  242. color: #b3b3b3;
  243. }
  244. .kaoshi-tiku-content .kaoshi-tiku-content-flex:first-child {
  245. padding-bottom: 6px;
  246. }
  247. .kaoshi-tiku-content .kaoshi-tiku-content-flex:last-child {
  248. font-size: 14px;
  249. }
  250. .kaoshi-tiku-content-top {
  251. display: flex;
  252. align-items: center;
  253. }
  254. .kaoshi-tiku-content-top img {
  255. width: 20px;
  256. height: 22px;
  257. margin-right: 10px;
  258. }
  259. .kaoshi-tiku-content-bottom {
  260. display: flex;
  261. align-items: center;
  262. }
  263. .kaoshi-tiku-content-flex .icon-dui2 {
  264. margin: 2px 2px 0 0;
  265. color: #3c7bfc;
  266. }
  267. .kaoshi-tiku-bilv {
  268. font-size: 22px;
  269. color: #000;
  270. display: flex;
  271. align-items: baseline;
  272. }
  273. .kaoshi-remind-title {
  274. font-size: 13px;
  275. color: #000;
  276. }
  277. </style>