searchList.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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">
  12. <view class="iconfont icon-zuojiantou" @tap="$navigateBack"></view>
  13. </view>
  14. <view class="kaoshi-head-m">题目搜索</view>
  15. <view class="kaoshi-head-right"></view>
  16. </view>
  17. </view>
  18. <!--#endif-->
  19. <view class="search-box">
  20. <uni-search-bar class="uni-mt-10" radius="100" placeholder="请输入关键字搜索题目" @confirm="search" v-model="keyword"
  21. clearButton="none" cancelButton="none" style="width: 86%;" />
  22. <view class="search-submit" @tap="search">搜索</view>
  23. </view>
  24. <view class="search-wuc" v-if="issearch">
  25. <wuc-tab :tab-list="order_sort" :tabCur="current_index" @change="tabChange"
  26. tab-class="text-black bg-white list_top" select-class="text-blue text-xl"></wuc-tab>
  27. </view>
  28. <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption"
  29. :up="upOption">
  30. <view v-for="(item,index) in list" :key="index" @tap="gotoDetail(item.id)">
  31. <view class="searchbox">
  32. <view class="classify">{{item.type_text}}</view>
  33. <uc-parse :node="item.question_name"></uc-parse>
  34. </view>
  35. </view>
  36. </mescroll-body>
  37. </view>
  38. </template>
  39. <script>
  40. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  41. import {
  42. mapState
  43. } from 'vuex'
  44. import WucTab from '@/components/wuc-tab/wuc-tab.vue';
  45. import Error from '@/core/untils/error/index';
  46. export default {
  47. mixins: [MescrollMixin], // 使用mixin
  48. data() {
  49. return {
  50. keyword: '',
  51. mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
  52. // 下拉刷新的配置(可选, 绝大部分情况无需配置)
  53. downOption: {
  54. use: true, // 是否启用下拉刷新; 默认true
  55. auto: false, // 是否在初始化完毕之后自动执行下拉刷新的回调; 默认true
  56. native: false // 启用系统自带的下拉组件,默认false;仅mescroll-body生效,mescroll-uni无效(native: true, 则需在pages.json中配置"enablePullDownRefresh":true)
  57. },
  58. // 上拉加载的配置(可选, 绝大部分情况无需配置)
  59. upOption: {
  60. auto: false, // 是否在初始化完毕之后自动执行下拉刷新的回调; 默认true
  61. page: {
  62. num: 0,
  63. size: 10 // 每页数据的数量,默认10
  64. },
  65. noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  66. empty: {
  67. tip: '暂无相关数据'
  68. }
  69. },
  70. // 列表数据
  71. list: [],
  72. order_sort: [{
  73. name: '全部',
  74. goods_type: '0'
  75. },
  76. {
  77. name: '单选',
  78. goods_type: '1'
  79. },
  80. {
  81. name: '多选',
  82. goods_type: '2'
  83. },
  84. {
  85. name: '判断',
  86. goods_type: '3'
  87. },
  88. {
  89. name: '填空',
  90. goods_type: '4'
  91. },
  92. {
  93. name: '简答题',
  94. goods_type: '5'
  95. }
  96. ],
  97. current_id: '0',
  98. current_index: 0,
  99. issearch: false,
  100. }
  101. },
  102. computed: {
  103. ...mapState(['subject', 'userinfo'])
  104. },
  105. methods: {
  106. gotoDetail(id) {
  107. if (this.userinfo.token == undefined) {
  108. Error.errorNotLoggedIn();
  109. return
  110. }
  111. uni.navigateTo({
  112. url: '/pages/questionSearch/questionDetail?id=' + id
  113. })
  114. },
  115. search() {
  116. if (this.keyword == '') return
  117. this.issearch = true
  118. this.mescroll.resetUpScroll()
  119. },
  120. /*上拉加载的回调*/
  121. async upCallback(page) {
  122. let pageNum = page.num; // 页码, 默认从1开始
  123. let pageSize = page.size; // 页长, 默认每页10条
  124. let res = await this.$myHttp.post({
  125. url: this.$myHttp.urlMap.questionsSearchResult,
  126. data: {
  127. subject_id: this.subject.id,
  128. keyword: this.keyword,
  129. page: pageNum,
  130. limit: pageSize,
  131. type: this.current_id
  132. },
  133. needLogin: false
  134. })
  135. if (res.code == 1) {
  136. // 接口返回的当前页数据列表 (数组)
  137. let curPageData = res.data.data;
  138. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  139. let curPageLen = curPageData.length;
  140. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  141. // let totalPage = data.xxx;
  142. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  143. let totalSize = res.data.total;
  144. this.mescroll.endBySize(curPageLen, totalSize);
  145. if (page.num == 1) this.list = []; //如果是第一页需手动置空列表
  146. this.list = this.list.concat(curPageData); //追加新数据
  147. } else {
  148. this.mescroll.endErr()
  149. }
  150. // 此处仍可以继续写其他接口请求...
  151. // 调用其他方法...
  152. },
  153. tabChange(index) {
  154. this.current_index = index;
  155. this.current_id = this.order_sort[index].goods_type;
  156. if (this.keyword == '') {
  157. return
  158. }
  159. this.mescroll.resetUpScroll(false)
  160. }
  161. }
  162. }
  163. </script>
  164. <style>
  165. page {
  166. background-color: #f6f6f6;
  167. }
  168. .search-box {
  169. display: flex;
  170. flex: 1;
  171. justify-content: space-between;
  172. background-color: #fff;
  173. }
  174. .search-submit {
  175. width: 16%;
  176. height: 32px;
  177. background: #3c7bfc;
  178. text-align: center;
  179. margin-right: 10px;
  180. line-height: 32px;
  181. margin-top: 11px;
  182. border-radius: 16px;
  183. color: #fff;
  184. font-size: 14px;
  185. }
  186. .searchbox {
  187. margin: 10px 15px;
  188. padding: 10px;
  189. background-color: #fff;
  190. border-radius: 8px;
  191. }
  192. .classify {
  193. font-size: 16px;
  194. margin: 5px 0 10px -10px;
  195. padding-left: 11px;
  196. line-height: 16px;
  197. border-left: 5px solid #3c7bfc;
  198. }
  199. </style>