search-result.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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="toFeedback" @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. toFeedback() {
  114. uni.navigateTo({
  115. url: '/pages-sell/pages/feedback'
  116. });
  117. },
  118. onSearch(val) {
  119. console.log('Search:', val);
  120. },
  121. addToCart(data) {
  122. // data now contains { product, quality, quantity } from the popup
  123. console.log('Added to cart:', data);
  124. uni.showToast({
  125. title: '已加入购物车',
  126. icon: 'success'
  127. });
  128. }
  129. }
  130. }
  131. </script>
  132. <style lang="scss" scoped>
  133. .search-result-page {
  134. min-height: 100vh;
  135. background-color: #F6F6F6;
  136. font-family: 'Source Han Sans SC', sans-serif;
  137. position: relative;
  138. }
  139. /* 顶部大背景图 */
  140. .top-bg-image {
  141. position: fixed;
  142. top: 0;
  143. left: 0;
  144. width: 100%;
  145. z-index: 0;
  146. display: block;
  147. }
  148. .search-bar-wrapper {
  149. position: relative;
  150. z-index: 2;
  151. display: flex;
  152. align-items: center;
  153. padding: 0 30rpx;
  154. height: 88rpx;
  155. width: 100%;
  156. }
  157. .banner-section {
  158. position: relative;
  159. width: 100%;
  160. z-index: 1;
  161. padding: 10rpx 30rpx;
  162. .top-banner {
  163. width: 100%;
  164. display: block;
  165. }
  166. }
  167. .content-area {
  168. position: relative;
  169. z-index: 2;
  170. padding: 30rpx 30rpx;
  171. border-radius: 30rpx 30rpx 0 0;
  172. min-height: 500rpx;
  173. .section-block {
  174. margin-bottom: 30rpx;
  175. background-color: #fff;
  176. padding: 30rpx 24rpx;
  177. border-radius: 20rpx;
  178. .section-title {
  179. font-size: 32rpx;
  180. font-weight: bold;
  181. color: #333;
  182. margin-bottom: 20rpx;
  183. display: block;
  184. }
  185. }
  186. }
  187. .filter-bar {
  188. display: flex;
  189. justify-content: space-between;
  190. align-items: center;
  191. margin-bottom: 20rpx;
  192. .filter-item {
  193. display: flex;
  194. align-items: center;
  195. font-size: 28rpx;
  196. color: #666;
  197. &.active {
  198. color: #333;
  199. font-weight: bold;
  200. .triangle-icon {
  201. border-top-color: #333;
  202. }
  203. }
  204. text {
  205. margin-right: 6rpx;
  206. }
  207. .triangle-icon {
  208. width: 0;
  209. height: 0;
  210. border-left: 8rpx solid transparent;
  211. border-right: 8rpx solid transparent;
  212. border-top: 10rpx solid #666;
  213. }
  214. .sort-icons {
  215. display: flex;
  216. flex-direction: column;
  217. margin-left: 4rpx;
  218. .icon-sort {
  219. width: 12rpx;
  220. height: 8rpx;
  221. margin: 2rpx 0;
  222. }
  223. }
  224. .icon-filter {
  225. width: 24rpx;
  226. height: 24rpx;
  227. margin-left: 4rpx;
  228. }
  229. }
  230. }
  231. .book-list {
  232. padding-bottom: 40rpx;
  233. background: #fff;
  234. border-radius: 20rpx;
  235. padding: 0 24rpx;
  236. }
  237. </style>