search.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <view class="book-search">
  3. <!-- 搜索框 - 固定在顶部 -->
  4. <view class="search-container fixed-top">
  5. <u-search v-model="searchKeyword" placeholder="输入ISBN/书名" :show-action="true" action-text="搜索"
  6. :clearabled="true" @search="handleSearch" @clear="handleClear" @custom="handleSearch"></u-search>
  7. </view>
  8. <!-- 书籍列表 -->
  9. <view class="content-wrapper">
  10. <page-scroll ref="pageScroll" url="/token/activation/infoList" :immediate="false" :slot-empty="true"
  11. :params="searchParams" @updateList="handleUpdateList">
  12. <view class="book-list">
  13. <view class="book-item" v-for="(item, index) in bookList" :key="index">
  14. <!-- 书籍封面 -->
  15. <view class="book-cover">
  16. <u-image :src="item.cover || defaultCover" width="120rpx" height="160rpx" border-radius="8rpx"
  17. :fade="true"></u-image>
  18. </view>
  19. <!-- 书籍信息 -->
  20. <view class="book-info">
  21. <view class="book-title">{{ item.bookName }}</view>
  22. <view class="book-isbn">ISBN: {{ item.isbn }}</view>
  23. <view class="book-author">作者: {{ item.author }}</view>
  24. <view class="book-publish">出版社: {{ item.publish }}</view>
  25. <view class="book-date">出版时间: {{ formatDate(item.pubDate) }}</view>
  26. </view>
  27. <!-- 库存信息 -->
  28. <view class="book-stock">
  29. <view class="stock-num">{{ item.stockNum }}</view>
  30. <view class="stock-label">库存</view>
  31. </view>
  32. </view>
  33. </view>
  34. <!-- 空状态提示 -->
  35. <template v-slot:empty>
  36. <view class="empty-container">
  37. <image src="https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/no-data.png" class="empty-image"
  38. mode="aspectFit" />
  39. <view class="empty-title">暂无搜索结果</view>
  40. <view class="empty-text">请尝试其他关键词</view>
  41. </view>
  42. </template>
  43. </page-scroll>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. import pageScroll from '@/components/pageScroll/index.vue'
  49. export default {
  50. components: {
  51. pageScroll
  52. },
  53. data() {
  54. return {
  55. searchKeyword: '',
  56. bookList: [],
  57. searchParams: {},
  58. defaultCover: 'https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/book-default.png'
  59. };
  60. },
  61. // #ifdef MP-ALIPAY
  62. onPullDownRefresh() {
  63. this.$refs.pageScroll?.loadData(true, this.searchParams)
  64. },
  65. // #endif
  66. methods: {
  67. // 处理搜索
  68. handleSearch() {
  69. if (!this.searchKeyword.trim()) {
  70. uni.showToast({
  71. title: '请输入搜索关键词',
  72. icon: 'none'
  73. });
  74. return;
  75. }
  76. this.searchParams = {
  77. searchContent: this.searchKeyword.trim()
  78. };
  79. // 重新加载数据
  80. this.$refs.pageScroll?.loadData(true, this.searchParams);
  81. },
  82. // 清空搜索
  83. handleClear() {
  84. this.searchKeyword = '';
  85. this.searchParams = {};
  86. this.bookList = [];
  87. },
  88. // 更新列表数据
  89. handleUpdateList(data) {
  90. this.bookList = data;
  91. },
  92. // 格式化日期
  93. formatDate(dateStr) {
  94. if (!dateStr) return '';
  95. const date = new Date(dateStr);
  96. return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
  97. }
  98. }
  99. };
  100. </script>
  101. <style lang="scss" scoped>
  102. .book-search {
  103. min-height: 100vh;
  104. background-color: #f5f5f5;
  105. }
  106. .search-container {
  107. position: fixed;
  108. top: 0;
  109. left: 0;
  110. right: 0;
  111. z-index: 999;
  112. background-color: #fff;
  113. padding: 20rpx 30rpx;
  114. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
  115. }
  116. .content-wrapper {
  117. margin-top: 120rpx; /* 为固定搜索框留出空间 */
  118. }
  119. .book-list {
  120. padding: 0 30rpx;
  121. }
  122. .book-item {
  123. display: flex;
  124. background-color: #fff;
  125. padding: 30rpx;
  126. margin-bottom: 20rpx;
  127. border-radius: 16rpx;
  128. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
  129. .book-cover {
  130. margin-right: 24rpx;
  131. flex-shrink: 0;
  132. }
  133. .book-info {
  134. flex: 1;
  135. .book-title {
  136. font-size: 32rpx;
  137. font-weight: 600;
  138. color: #333;
  139. margin-bottom: 12rpx;
  140. line-height: 1.4;
  141. display: -webkit-box;
  142. -webkit-box-orient: vertical;
  143. -webkit-line-clamp: 2;
  144. overflow: hidden;
  145. }
  146. .book-isbn,
  147. .book-author,
  148. .book-publish,
  149. .book-date {
  150. font-size: 26rpx;
  151. color: #666;
  152. margin-bottom: 8rpx;
  153. line-height: 1.3;
  154. }
  155. .book-isbn {
  156. color: #999;
  157. font-family: 'Courier New', monospace;
  158. }
  159. }
  160. .book-stock {
  161. display: flex;
  162. flex-direction: column;
  163. align-items: center;
  164. justify-content: center;
  165. min-width: 80rpx;
  166. .stock-num {
  167. font-size: 36rpx;
  168. font-weight: 600;
  169. color: #52c41a;
  170. margin-bottom: 8rpx;
  171. }
  172. .stock-label {
  173. font-size: 24rpx;
  174. color: #999;
  175. }
  176. }
  177. }
  178. .empty-container {
  179. display: flex;
  180. flex-direction: column;
  181. align-items: center;
  182. padding-top: 25vh;
  183. .empty-image {
  184. width: 200rpx;
  185. height: 200rpx;
  186. margin-bottom: 30rpx;
  187. }
  188. .empty-title {
  189. font-size: 32rpx;
  190. color: #333;
  191. margin-bottom: 16rpx;
  192. }
  193. .empty-text {
  194. font-size: 28rpx;
  195. color: #999;
  196. }
  197. }
  198. </style>