question_category.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <!-- +---------------------------------------------------------------------- -->
  2. <!-- | CRMEB [ CRMEB赋能开发者,助力企业发展 ] -->
  3. <!-- +---------------------------------------------------------------------- -->
  4. <!-- | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved. -->
  5. <!-- +---------------------------------------------------------------------- -->
  6. <!-- | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权 -->
  7. <!-- +---------------------------------------------------------------------- -->
  8. <!-- | Author: CRMEB Team <admin@crmeb.com> -->
  9. <!-- +---------------------------------------------------------------------- -->
  10. {extend name="public/container"}
  11. {block name="title"}{$type==1 ? '练习列表' : '考试列表'}{/block}
  12. {block name="head"}<style></style>{/block}
  13. {block name="content"}
  14. <div v-cloak id="app">
  15. <div class="question-category-page">
  16. <div class="header">
  17. <div>
  18. <div class="search">
  19. <div>
  20. {if $homeLogo}
  21. <img src="{$homeLogo}">
  22. {else}
  23. <img src="{__WAP_PATH}zsff/images/crmeb.png">
  24. {/if}
  25. </div>
  26. <input v-model="search" placeholder="输入试卷名称">
  27. <a href="javascript:" @click="onSearch">搜索</a>
  28. </div>
  29. <div id="sup" class="swiper-container" @click="onSup">
  30. <div class="swiper-wrapper">
  31. <div v-for="(item, index) in navSup" :key="item.id" :class="{ on: index === indexSup }" class="swiper-slide">{{ item.title }}</div>
  32. </div>
  33. </div>
  34. </div>
  35. <div id="sub" class="swiper-container" @click="onSub">
  36. <div class="swiper-wrapper">
  37. <div v-for="(item, index) in navSub" :key="item.id" :class="{ on: index === indexSub }" class="swiper-slide">{{ item.title }}</div>
  38. </div>
  39. </div>
  40. </div>
  41. <div>
  42. <ul v-if="type == 1" class="problem">
  43. <li v-for="item in question" :key="item.id">
  44. <div>{{ item.title }}</div>
  45. <div>
  46. <div>共{{ item.item_number }}题</div>
  47. <div>{{ item.answer + item.fake_sales}}人已答题</div>
  48. <a :href="'{:url('topic/problem_index')}?id=' + item.id">练习</a>
  49. </div>
  50. </li>
  51. </ul>
  52. <ul v-else class="question">
  53. <li v-for="item in question" :key="item.id">
  54. <div>
  55. <img :src="item.image">
  56. </div>
  57. <div>
  58. <div>{{ item.title }}</div>
  59. <div v-if="item.pay_type">¥<span>{{ item.money }}</span></div>
  60. <div v-else class="free">免费</div>
  61. <div>
  62. {{ item.answer + item.fake_sales}}人已答题
  63. <a :href="'{:url('special/question_index')}?id=' + item.id">答题</a>
  64. </div>
  65. </div>
  66. </li>
  67. </ul>
  68. </div>
  69. </div>
  70. <quick-menu></quick-menu>
  71. </div>
  72. <script>
  73. require([
  74. 'vue',
  75. 'swiper',
  76. 'helper',
  77. 'store',
  78. 'quick'
  79. ], function (Vue, Swiper, $h, $http) {
  80. var vm = new Vue({
  81. el: '#app',
  82. data: {
  83. swiperOptions: {
  84. slidesPerView: 'auto',
  85. freeMode: true,
  86. observer: true
  87. },
  88. navSup: [],
  89. navSub: [],
  90. indexSup: 0,
  91. indexSub: 0,
  92. type: 1,
  93. page: 1,
  94. limit: 15,
  95. loading: false,
  96. finished: false,
  97. question: [],
  98. current: {},
  99. search: ''
  100. },
  101. watch: {
  102. loading: function (loading) {
  103. loading ? $h.loadFFF() : $h.loadClear();
  104. }
  105. },
  106. created: function () {
  107. this.type = $h.getParmas('type');
  108. this.getCategory();
  109. },
  110. mounted: function () {
  111. this.$nextTick(function () {
  112. this.swiperSup = new Swiper('#sup', this.swiperOptions);
  113. this.swiperSub = new Swiper('#sub', this.swiperOptions);
  114. $h.EventUtil.listenTouchDirection(document, function () {
  115. vm.getQuestion();
  116. });
  117. });
  118. },
  119. methods: {
  120. onSup: function () {
  121. if (this.loading) {
  122. return;
  123. }
  124. var swiperWidth = this.swiperSup.width,
  125. swiperScrollWidth = this.swiperSup.$wrapperEl[0].scrollWidth,
  126. swiperSlideLeft = this.swiperSup.clickedSlide.offsetLeft,
  127. swiperSlideWidth = this.swiperSup.clickedSlide.offsetWidth;
  128. this.swiperSup.setTransition(300);
  129. if (swiperSlideLeft < (swiperWidth - parseInt(swiperSlideWidth)) / 2) {
  130. this.swiperSup.setTranslate(0);
  131. } else if (swiperSlideLeft > parseInt(swiperScrollWidth) - (swiperWidth + parseInt(swiperSlideWidth)) / 2) {
  132. this.swiperSup.setTranslate(swiperWidth - parseInt(swiperScrollWidth));
  133. } else {
  134. this.swiperSup.setTranslate((swiperWidth - parseInt(swiperSlideWidth)) / 2 - swiperSlideLeft);
  135. }
  136. this.indexSup = this.swiperSup.clickedIndex;
  137. this.navSub = this.navSup[this.indexSup].children;
  138. this.indexSub = 0;
  139. this.question = [];
  140. this.loading = false;
  141. this.finished = false;
  142. this.page = 1;
  143. this.search = '';
  144. this.current = this.navSub[0];
  145. this.getQuestion();
  146. },
  147. onSub: function () {
  148. if (this.loading) {
  149. return;
  150. }
  151. var swiperWidth = this.swiperSub.width,
  152. swiperScrollWidth = this.swiperSub.$wrapperEl[0].scrollWidth,
  153. swiperSlideLeft = this.swiperSub.clickedSlide.offsetLeft,
  154. swiperSlideWidth = this.swiperSub.clickedSlide.offsetWidth;
  155. this.swiperSub.setTransition(300);
  156. if (swiperSlideLeft < (swiperWidth - parseInt(swiperSlideWidth)) / 2) {
  157. this.swiperSub.setTranslate(0);
  158. } else if (swiperSlideLeft > parseInt(swiperScrollWidth) - (swiperWidth + parseInt(swiperSlideWidth)) / 2) {
  159. this.swiperSub.setTranslate(swiperWidth - parseInt(swiperScrollWidth));
  160. } else {
  161. this.swiperSub.setTranslate((swiperWidth - parseInt(swiperSlideWidth)) / 2 - swiperSlideLeft);
  162. }
  163. this.indexSub = this.swiperSub.clickedIndex;
  164. this.question = [];
  165. this.loading = false;
  166. this.finished = false;
  167. this.page = 1;
  168. this.search = '';
  169. this.current = this.navSub[this.indexSub];
  170. this.getQuestion();
  171. },
  172. getCategory: function () {
  173. this.loading = true;
  174. $http.baseGet($h.U({
  175. c: 'topic',
  176. a: 'testPaperCate',
  177. q: {
  178. type: this.type
  179. }
  180. }), function (res) {
  181. $h.loadClear();
  182. var navSup = res.data.data;
  183. for (var i = navSup.length; i--;) {
  184. navSup[i].children.unshift({
  185. pid: navSup[i].id,
  186. id: 0,
  187. title: '全部'
  188. });
  189. }
  190. vm.navSup = navSup;
  191. vm.loading = false;
  192. if (vm.navSup.length) {
  193. vm.navSub = vm.navSup[0].children;
  194. vm.current = vm.navSub[0];
  195. vm.getQuestion();
  196. }
  197. });
  198. },
  199. getQuestion: function () {
  200. if (this.loading || this.finished) {
  201. return;
  202. }
  203. this.loading = true;
  204. $http.basePost($h.U({
  205. c: 'topic',
  206. a: 'practiceList?type=' + this.type,
  207. }), {
  208. page: this.page++,
  209. limit: this.limit,
  210. pid: this.current.pid,
  211. tid: this.current.id,
  212. search: this.search
  213. }, function (res) {
  214. vm.question = vm.question.concat(res.data.data);
  215. vm.loading = false;
  216. vm.finished = vm.limit > res.data.data.length;
  217. });
  218. },
  219. onSearch: function () {
  220. if (!this.search) {
  221. return $h.pushMsg('请输入搜索内容');
  222. }
  223. this.indexSup = 0;
  224. this.indexSub = 0;
  225. this.current = vm.navSub[0];
  226. this.question = [];
  227. this.loading = false;
  228. this.finished = false;
  229. this.page = 1;
  230. this.getQuestion();
  231. }
  232. }
  233. });
  234. });
  235. </script>
  236. {/block}