图书馆小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

241 lines
5.5 KiB

2 weeks ago
  1. <template>
  2. <view style="background-color: #fff; padding-bottom:5px;">
  3. <view class="my-search-container">
  4. <view class="my-search-wrapper">
  5. <picker
  6. mode="selector"
  7. :range="rangeText"
  8. :value="selectIndex"
  9. @change="onPickerChange"
  10. class="picker-select"
  11. >
  12. <view class="picker-display">
  13. {{ selectValueText || '请选择分类' }}
  14. <uni-icons type="arrowdown" size="14" color="#999" style="margin-left: 4px;" />
  15. </view>
  16. </picker>
  17. <uni-search-bar
  18. class="my-search-bar"
  19. @confirm="onSearch"
  20. @focus="onFocus"
  21. @blur="onBlur"
  22. @clear="onClear"
  23. @cancel="onCancel"
  24. @input="onInput"
  25. cancelButton="none"
  26. bgColor="#f7f7f7"
  27. v-model="value"
  28. placeholder="请输入搜索内容"
  29. >
  30. <uni-icons slot="clearIcon" type="clear" color="#999999" />
  31. </uni-search-bar>
  32. </view>
  33. <view class="search-btn-container" @click="onSearch">
  34. <button class="search-btn" type="primary" >搜索</button>
  35. </view>
  36. <!-- 有数据才显示 -->
  37. <view class="filter-container">
  38. <view class="total-reslut" v-if="listData.length > 0">
  39. 搜索到 {{ total }} 条记录 {{ totalPage }} 当前第 {{ page }}
  40. </view>
  41. <view>筛选</view>
  42. </view>
  43. </view>
  44. <!-- 有数据才显示列表 -->
  45. <view style="padding-top: 154px;" v-if="listData.length > 0">
  46. <scroll-view
  47. scroll-y
  48. style="height: calc(100vh - 80px);"
  49. @scrolltolower="onScrollLower"
  50. >
  51. <book-list-item
  52. class="hot-list-item"
  53. v-for="(item, index) in listData"
  54. :key="index"
  55. :data="item"
  56. :ranking="index + 1"
  57. @click="onItemClick(item)"
  58. ></book-list-item>
  59. <view class="load-more" v-if="total > listData.length">
  60. 上拉加载更多...
  61. </view>
  62. <view class="load-more" v-if="total <= listData.length && listData.length > 0">
  63. 没有更多数据了
  64. </view>
  65. </scroll-view>
  66. </view>
  67. </view>
  68. </template>
  69. <script>
  70. import BookListItem from "@/components/book-list-item/book-list-item.vue";
  71. export default {
  72. components: {
  73. BookListItem
  74. },
  75. data() {
  76. return {
  77. selectValue: '',
  78. selectValueText: '',
  79. selectIndex: 0,
  80. value:'',
  81. range: [
  82. { value: 0, text: "任意词" },
  83. { value: 1, text: "题名" },
  84. { value: 2, text: "著者" },
  85. { value: 3, text: "ISBN" },
  86. { value: 4, text: "主题" },
  87. { value: 5, text: "出版社" },
  88. { value: 6, text: "分类号" }
  89. ],
  90. rangeText: [],
  91. listData:[],
  92. size: 10,
  93. page: 1,
  94. total: 0,
  95. totalPage: 0
  96. };
  97. },
  98. onLoad() {
  99. this.rangeText = this.range.map(item => item.text);
  100. this.selectValue = this.range[0].value;
  101. this.selectValueText = this.range[0].text;
  102. },
  103. methods: {
  104. onPickerChange(e) {
  105. const index = e.detail.value;
  106. this.selectIndex = index;
  107. this.selectValue = this.range[index].value;
  108. this.selectValueText = this.range[index].text;
  109. },
  110. async getBookList() {
  111. uni.showLoading({ title: '搜索中...' });
  112. await new Promise(resolve => setTimeout(resolve, 500));
  113. const mockList = [];
  114. for (let i = 0; i < this.size; i++) {
  115. const idx = (this.page - 1) * this.size + i + 1;
  116. mockList.push({
  117. id: idx,
  118. title: `穆尔西医生带你走出孤独`,
  119. desc: `关键词:${this.value}|检索类型:${this.selectValueText}`,
  120. nickname: `穆尔西`,
  121. imgCover:'http://wxtest.twgbz.cn/spider/bookcover/978-7-5546-1700-7',
  122. publish: "中国青年出版社",
  123. });
  124. }
  125. this.total = 37;
  126. this.totalPage = 4;
  127. if (this.page === 1) {
  128. this.listData = mockList;
  129. } else {
  130. this.listData = [...this.listData, ...mockList];
  131. }
  132. uni.hideLoading();
  133. },
  134. onScrollLower() {
  135. if (this.listData.length >= this.total) return;
  136. this.page++;
  137. this.getBookList();
  138. },
  139. onSearch() {
  140. this.page = 1;
  141. this.getBookList();
  142. uni.showToast({ title: '搜索:' + this.value, icon: 'none' });
  143. },
  144. onItemClick(item) {
  145. // uni.showToast({ title: '点击了:' + item.title, icon: 'none' });
  146. uni.navigateTo({
  147. url: "/subpkg/pages/book-detail/book-detail?isbn=" + item.isbn
  148. })
  149. },
  150. onFocus() {},
  151. onBlur() {},
  152. onClear() {
  153. this.value = '';
  154. this.listData = []; // 清空列表
  155. this.total = 0;
  156. },
  157. onCancel() {},
  158. onInput(val) { this.value = val; }
  159. }
  160. }
  161. </script>
  162. <style lang="scss" scoped>
  163. .my-search-container {
  164. display: flex;
  165. flex-direction: column;
  166. padding: 15px 20px;
  167. background: #fff;
  168. position: fixed;
  169. top: 0;
  170. left: 0;
  171. right: 0;
  172. z-index: 99;
  173. height: 124px;
  174. .my-search-wrapper{
  175. display: flex;
  176. align-items: center;
  177. width: 100%;
  178. padding: 5px 0;
  179. background-color: #f7f7f7;
  180. border-radius: 36px;
  181. overflow: hidden;
  182. }
  183. .picker-select {
  184. width: 60px;
  185. border-right: 1px solid #c9c9c9;
  186. }
  187. .picker-display {
  188. display: flex;
  189. align-items: center;
  190. justify-content: center;
  191. padding: 6px 0;
  192. font-size: 14px;
  193. color: #333;
  194. }
  195. .my-search-bar {
  196. flex: 1;
  197. ::v-deep .uni-searchbar {
  198. padding: 0 !important;
  199. background: transparent !important;
  200. }
  201. }
  202. .search-btn-container{
  203. width: 100%;
  204. margin-top: 10px;
  205. .search-btn{
  206. background-color: #01a4fe;
  207. font-size: 15px;
  208. border-radius: 20px;
  209. }
  210. }
  211. }
  212. .filter-container {
  213. display: flex;
  214. justify-content: flex-end;
  215. padding-top: 10px;
  216. font-size: 13px;
  217. color: #666;
  218. }
  219. .load-more {
  220. text-align: center;
  221. padding: 10px;
  222. font-size: 13px;
  223. color: #999;
  224. }
  225. .total-reslut{
  226. flex: 1;
  227. line-height: 20px;
  228. font-size: 13px;
  229. color: #01a4fe;
  230. font-weight: 400;
  231. }
  232. </style>