index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <view>
  3. <HMfilterDropdown :filterData="filterData" :defaultSelected="filterDropdownValue" @confirm="confirmCate"></HMfilterDropdown>
  4. <view class="paper-contains">
  5. <!-- 试卷列表 -->
  6. <view class="paper-card" v-for="(item, index) in list" :key="index">
  7. <navigator :url="'paper?id='+item.id" hover-class="none">
  8. <tui-card :title="{text: item.cates.name, size: 30, color: '#7A7A7A'}" :tag="{text: item.mode_text, size: 24}" :header="{title: item.title}">
  9. <template v-slot:body>
  10. <view class="tui-default">
  11. {{item.title}}
  12. </view>
  13. </template>
  14. <template v-slot:footer>
  15. <view class="tui-default">
  16. <view>考试限时:{{item.limit_time|format_second}}</view>
  17. <view class="text-red" v-if="item.end_time > 0">截止时间:{{item.end_time|format_date}}</view>
  18. </view>
  19. </template>
  20. </tui-card>
  21. </navigator>
  22. </view>
  23. <!-- 加载状态条 -->
  24. <view class="cu-load bg-grey" :class="loadFlag" v-show="!has_more"></view>
  25. </view>
  26. <tabbar></tabbar>
  27. </view>
  28. </template>
  29. <script>
  30. import HMfilterDropdown from '@/components/HM-filterDropdown/HM-filterDropdown.vue';
  31. import TuiCard from '@/components/tui-card/tui-card.vue';
  32. export default {
  33. components: {
  34. 'HMfilterDropdown': HMfilterDropdown,
  35. 'tui-card': TuiCard,
  36. },
  37. data() {
  38. return {
  39. cate_id: null,
  40. sort: null,
  41. list: [],
  42. has_more: false,
  43. current_page: 1,
  44. loadFlag: 'loading',
  45. filterData: [],
  46. filterDropdownValue: [],
  47. }
  48. },
  49. onLoad(e) {
  50. if (e.cate_id) {
  51. this.cate_id = e.cate_id
  52. }
  53. this.ajax()
  54. },
  55. async onReachBottom() {
  56. console.log("onReachBottom")
  57. if (this.has_more) {
  58. this.current_page++
  59. this.getPaper()
  60. }
  61. },
  62. methods: {
  63. async ajax() {
  64. await this.getCate('init')
  65. await this.getPaper()
  66. },
  67. // 获取试卷
  68. async getPaper() {
  69. this.loadFlag = 'loading'
  70. let params = {
  71. page: this.current_page
  72. }
  73. if (this.cate_id) {
  74. params['cate_id'] = this.cate_id
  75. }
  76. if (this.sort) {
  77. params['sort'] = this.sort
  78. }
  79. await this.http('paper/index', params).then(res => {
  80. if (res && res.data) {
  81. this.list = this.list.concat(res.data.list.data)
  82. console.log('list', this.list)
  83. this.has_more = res.data.list.has_more
  84. this.current_page = res.data.list.current_page
  85. this.loadFlag = 'over'
  86. }
  87. })
  88. },
  89. // 获取题库
  90. async getCate(type = '') {
  91. await this.http('cate/filter', {kind: 'QUESTION'}).then(res => {
  92. this.filterData = res.data
  93. if (type == 'init') {
  94. let defaultCate = this.utils.getData('default_cate-QUESTION')
  95. console.log('defaultCate', defaultCate)
  96. if (defaultCate) {
  97. this.cate_id = defaultCate.value
  98. let defaultCateList = []
  99. for (var i = 0; i < defaultCate.result.length; i++) {
  100. if (i == 0) {
  101. // 0=全部题库,需要+1
  102. defaultCateList.push(defaultCate.result[i].index + 1)
  103. } else {
  104. defaultCateList.push(defaultCate.result[i].index)
  105. }
  106. }
  107. console.log('defaultCateList', defaultCateList)
  108. this.filterDropdownValue = [
  109. defaultCateList,
  110. [0]
  111. ]
  112. }
  113. }
  114. })
  115. },
  116. // 选择题库
  117. confirmCate(event) {
  118. console.log('confirm cate', event, event.value[0].length)
  119. let cate_id = 0
  120. for (let i = 0; i < event.value[0].length; i++) {
  121. cate_id = event.value[0].pop()
  122. console.log('for cate_id', cate_id)
  123. if (cate_id) {
  124. break
  125. }
  126. }
  127. if (!cate_id && event.value[0][0]) {
  128. cate_id = event.value[0][0]
  129. }
  130. console.log('cate_id', cate_id)
  131. let sort = ''
  132. if (event?.value[1]) {
  133. sort = event?.value[1][0]
  134. }
  135. if (cate_id != this.cate_id || sort !== this.sort) {
  136. console.log('confirmCate', [cate_id, this.cate_id, sort, this.sort])
  137. this.cate_id = cate_id
  138. this.sort = sort
  139. this.list = []
  140. this.getPaper()
  141. }
  142. },
  143. }
  144. }
  145. </script>
  146. <style>
  147. .paper-contains {
  148. margin-top: 50px;
  149. padding-bottom: 100px;
  150. }
  151. .paper-card {
  152. margin: 20rpx 0;
  153. }
  154. .tui-title {
  155. width: 100%;
  156. padding: 70rpx 30rpx 30rpx 30rpx;
  157. box-sizing: border-box;
  158. font-size: 30rpx;
  159. line-height: 30rpx;
  160. color: #666;
  161. }
  162. .tui-default {
  163. padding: 20rpx 30rpx;
  164. }
  165. .tui-article {
  166. position: relative;
  167. }
  168. .tui-article-img {
  169. width: 100%;
  170. height: 300rpx;
  171. display: block;
  172. }
  173. .tui-article-title {
  174. position: absolute;
  175. left: 0;
  176. bottom: 0;
  177. color: #fff;
  178. font-size: 32rpx;
  179. font-weight: 500;
  180. box-sizing: border-box;
  181. padding: 20rpx 30rpx;
  182. background: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.6));
  183. }
  184. .tui-cell-title {
  185. font-size: 32rpx;
  186. font-weight: 500;
  187. padding: 0 10rpx;
  188. word-break: break-all;
  189. word-wrap: break-word;
  190. }
  191. .tui-cell-img {
  192. height: 160rpx;
  193. width: 160rpx;
  194. }
  195. .tui-flex {
  196. display: flex;
  197. align-items: center;
  198. justify-content: space-between;
  199. }
  200. .tui-mr {
  201. margin-right: 20rpx;
  202. }
  203. .tui-flex-pic {
  204. display: flex;
  205. display: -webkit-flex;
  206. justify-content: space-between;
  207. flex-direction: row;
  208. flex-wrap: wrap;
  209. box-sizing: border-box;
  210. background: #fff;
  211. padding: 0 120rpx;
  212. }
  213. .tui-flex-pic image {
  214. width: 32%;
  215. margin-bottom: 2%;
  216. }
  217. .tui-content {
  218. padding: 0rpx 30rpx 20rpx 120rpx;
  219. box-sizing: border-box;
  220. font-size: 34rpx;
  221. font-weight: 400;
  222. color: #333;
  223. }
  224. .tui-color-gray {
  225. color: #ccc;
  226. }
  227. .tui-pleft {
  228. padding-left: 120rpx;
  229. }
  230. </style>