search.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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="true" :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. this.searchParams = {
  70. searchContent: this.searchKeyword.trim()
  71. };
  72. // 重新加载数据
  73. this.$refs.pageScroll?.loadData(true, this.searchParams);
  74. },
  75. // 清空搜索
  76. handleClear() {
  77. this.searchKeyword = '';
  78. this.searchParams = {};
  79. this.bookList = [];
  80. },
  81. // 更新列表数据
  82. handleUpdateList(data) {
  83. this.bookList = data;
  84. },
  85. // 格式化日期
  86. formatDate(dateStr) {
  87. if (!dateStr) return '';
  88. const date = new Date(dateStr);
  89. return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
  90. }
  91. }
  92. };
  93. </script>
  94. <style lang="scss" scoped>
  95. .book-search {
  96. min-height: 100vh;
  97. background-color: #f5f5f5;
  98. }
  99. .search-container {
  100. position: fixed;
  101. top: 0;
  102. left: 0;
  103. right: 0;
  104. z-index: 999;
  105. background-color: #fff;
  106. padding: 20rpx 30rpx;
  107. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.04);
  108. }
  109. .content-wrapper {
  110. margin-top: 130rpx; /* 为固定搜索框留出空间 */
  111. }
  112. .book-list {
  113. padding: 0 30rpx;
  114. }
  115. .book-item {
  116. display: flex;
  117. background-color: #fff;
  118. padding: 30rpx;
  119. margin-bottom: 20rpx;
  120. border-radius: 16rpx;
  121. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.08);
  122. .book-cover {
  123. margin-right: 24rpx;
  124. flex-shrink: 0;
  125. }
  126. .book-info {
  127. flex: 1;
  128. .book-title {
  129. font-size: 32rpx;
  130. font-weight: 600;
  131. color: #333;
  132. margin-bottom: 12rpx;
  133. line-height: 1.4;
  134. display: -webkit-box;
  135. -webkit-box-orient: vertical;
  136. -webkit-line-clamp: 2;
  137. overflow: hidden;
  138. }
  139. .book-isbn,
  140. .book-author,
  141. .book-publish,
  142. .book-date {
  143. font-size: 26rpx;
  144. color: #666;
  145. margin-bottom: 8rpx;
  146. line-height: 1.3;
  147. }
  148. .book-isbn {
  149. color: #999;
  150. font-family: 'Courier New', monospace;
  151. }
  152. }
  153. .book-stock {
  154. display: flex;
  155. flex-direction: column;
  156. align-items: center;
  157. justify-content: center;
  158. min-width: 80rpx;
  159. .stock-num {
  160. font-size: 36rpx;
  161. font-weight: 600;
  162. color: #52c41a;
  163. margin-bottom: 8rpx;
  164. }
  165. .stock-label {
  166. font-size: 24rpx;
  167. color: #999;
  168. }
  169. }
  170. }
  171. .empty-container {
  172. display: flex;
  173. flex-direction: column;
  174. align-items: center;
  175. padding-top: 25vh;
  176. .empty-image {
  177. width: 200rpx;
  178. height: 200rpx;
  179. margin-bottom: 30rpx;
  180. }
  181. .empty-title {
  182. font-size: 32rpx;
  183. color: #333;
  184. margin-bottom: 16rpx;
  185. }
  186. .empty-text {
  187. font-size: 28rpx;
  188. color: #999;
  189. }
  190. }
  191. </style>