search.vue 4.9 KB

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