search-result.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <view class="search-result-page">
  3. <image class="top-bg-image" src="/pages-sell/static/top-bg.png" mode="widthFix"></image>
  4. <Navbar title="书嗨" :titleSize="36" :title-color="navbarTitleColor" :back-icon-color="navbarIconColor" :background="navbarBackground"></Navbar>
  5. <!-- Custom Header -->
  6. <view class="search-bar-wrapper">
  7. <u-search style="width: 100%;" v-model="keyword" placeholder="书名/作者/ISBN" :show-action="true" action-text="取消"
  8. :action-style="{ color: '#fff' }" bg-color="#fff" shape="round" :clearabled="true"
  9. search-icon="/pages-sell/static/search-icon.png" @custom="goBack" @search="onSearch"></u-search>
  10. </view>
  11. <!-- Banner -->
  12. <view class="banner-section">
  13. <image src="/pages-sell/static/top-banner.png" class="top-banner" mode="widthFix"></image>
  14. </view>
  15. <!-- Content Area -->
  16. <view class="content-area">
  17. <!-- Everyone is watching -->
  18. <view class="section-block">
  19. <text class="section-title">大家都在看</text>
  20. <HotRecommendItem :item="hotBook" @add-cart="addToCart"></HotRecommendItem>
  21. </view>
  22. <!-- Filter Bar -->
  23. <view class="filter-bar">
  24. <view class="filter-item active">
  25. <text>综合</text>
  26. <view class="triangle-icon"></view>
  27. </view>
  28. <view class="filter-item">
  29. <text>销量</text>
  30. </view>
  31. <view class="filter-item">
  32. <text>价格</text>
  33. <view class="sort-icons">
  34. <image src="/pages-sell/static/search-result/icon-top.png" class="icon-sort"></image>
  35. <image src="/pages-sell/static/search-result/icon-bottom.png" class="icon-sort"></image>
  36. </view>
  37. </view>
  38. <view class="filter-item">
  39. <text>筛选</text>
  40. <image src="/pages-sell/static/search-result/icon-filter.png" class="icon-filter"></image>
  41. </view>
  42. </view>
  43. <!-- Book List -->
  44. <view class="book-list">
  45. <RecommendItem v-for="(item, index) in bookList" :key="index" :item="item" @add-cart="addToCart" :show-desc="false">
  46. </RecommendItem>
  47. </view>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. import RecommendItem from '../components/recommend-item/index.vue';
  53. import HotRecommendItem from '../components/hot-recommend-item/index.vue';
  54. import Navbar from '@/components/navbar/navbar.vue';
  55. export default {
  56. components: {
  57. RecommendItem,
  58. HotRecommendItem,
  59. Navbar,
  60. },
  61. data() {
  62. return {
  63. keyword: '',
  64. pageNum: 1,
  65. pageSize: 10,
  66. hotBook: {
  67. id: 1,
  68. title: '山河岁月',
  69. cover: '/static/img/1.png', // Assuming a placeholder or from static
  70. price: '6.80',
  71. discount: '5.3折',
  72. discountDesc: '省9.8元'
  73. },
  74. bookList: [],
  75. navbarBackground: 'transparent',
  76. navbarTitleColor: '#ffffff',
  77. navbarIconColor: '#ffffff'
  78. }
  79. },
  80. onPageScroll(e) {
  81. if (e.scrollTop > 50) {
  82. this.navbarBackground = '#ffffff';
  83. this.navbarTitleColor = '#000000';
  84. this.navbarIconColor = '#000000';
  85. } else {
  86. this.navbarBackground = 'transparent';
  87. this.navbarTitleColor = '#ffffff';
  88. this.navbarIconColor = '#ffffff';
  89. }
  90. },
  91. onLoad(options) {
  92. this.keyword = options.keyword ? decodeURIComponent(options.keyword) : '';
  93. this.loadData();
  94. },
  95. methods: {
  96. loadData() {
  97. this.$u.api.getSearchKeywordAjax({
  98. keyword: this.keyword,
  99. pageNum: this.pageNum,
  100. pageSize: this.pageSize
  101. }).then(res => {
  102. const rows = res.data.rows || [];
  103. if (this.pageNum === 1) {
  104. this.bookList = rows;
  105. } else {
  106. this.bookList = [...this.bookList, ...rows];
  107. }
  108. })
  109. },
  110. goBack() {
  111. uni.navigateBack();
  112. },
  113. onSearch(val) {
  114. console.log('Search:', val);
  115. },
  116. addToCart(data) {
  117. // data now contains { product, quality, quantity } from the popup
  118. console.log('Added to cart:', data);
  119. uni.showToast({
  120. title: '已加入购物车',
  121. icon: 'success'
  122. });
  123. }
  124. }
  125. }
  126. </script>
  127. <style lang="scss" scoped>
  128. .search-result-page {
  129. min-height: 100vh;
  130. background-color: #F6F6F6;
  131. font-family: 'Source Han Sans SC', sans-serif;
  132. position: relative;
  133. }
  134. /* 顶部大背景图 */
  135. .top-bg-image {
  136. position: fixed;
  137. top: 0;
  138. left: 0;
  139. width: 100%;
  140. z-index: 0;
  141. display: block;
  142. }
  143. .search-bar-wrapper {
  144. position: relative;
  145. z-index: 2;
  146. display: flex;
  147. align-items: center;
  148. padding: 0 30rpx;
  149. height: 88rpx;
  150. width: 100%;
  151. }
  152. .banner-section {
  153. position: relative;
  154. width: 100%;
  155. z-index: 1;
  156. padding: 10rpx 30rpx;
  157. .top-banner {
  158. width: 100%;
  159. display: block;
  160. }
  161. }
  162. .content-area {
  163. position: relative;
  164. z-index: 2;
  165. padding: 30rpx 30rpx;
  166. border-radius: 30rpx 30rpx 0 0;
  167. min-height: 500rpx;
  168. .section-block {
  169. margin-bottom: 30rpx;
  170. background-color: #fff;
  171. padding: 30rpx 24rpx;
  172. border-radius: 20rpx;
  173. .section-title {
  174. font-size: 32rpx;
  175. font-weight: bold;
  176. color: #333;
  177. margin-bottom: 20rpx;
  178. display: block;
  179. }
  180. }
  181. }
  182. .filter-bar {
  183. display: flex;
  184. justify-content: space-between;
  185. align-items: center;
  186. margin-bottom: 20rpx;
  187. .filter-item {
  188. display: flex;
  189. align-items: center;
  190. font-size: 28rpx;
  191. color: #666;
  192. &.active {
  193. color: #333;
  194. font-weight: bold;
  195. .triangle-icon {
  196. border-top-color: #333;
  197. }
  198. }
  199. text {
  200. margin-right: 6rpx;
  201. }
  202. .triangle-icon {
  203. width: 0;
  204. height: 0;
  205. border-left: 8rpx solid transparent;
  206. border-right: 8rpx solid transparent;
  207. border-top: 10rpx solid #666;
  208. }
  209. .sort-icons {
  210. display: flex;
  211. flex-direction: column;
  212. margin-left: 4rpx;
  213. .icon-sort {
  214. width: 12rpx;
  215. height: 8rpx;
  216. margin: 2rpx 0;
  217. }
  218. }
  219. .icon-filter {
  220. width: 24rpx;
  221. height: 24rpx;
  222. margin-left: 4rpx;
  223. }
  224. }
  225. }
  226. .book-list {
  227. padding-bottom: 40rpx;
  228. background: #fff;
  229. border-radius: 20rpx;
  230. padding: 0 24rpx;
  231. }
  232. </style>