search.vue 5.8 KB

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