search-result.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  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"
  5. :background="navbarBackground"></Navbar>
  6. <!-- Custom Header -->
  7. <view class="search-bar-wrapper">
  8. <u-search style="width: 100%;" v-model="keyword" placeholder="书名/作者/ISBN" :show-action="true"
  9. action-text="反馈" :action-style="{ color: '#fff' }" bg-color="#fff" shape="round" :clearabled="true"
  10. search-icon="/pages-sell/static/search-icon.png" @custom="toFeedback" @search="onSearch"></u-search>
  11. </view>
  12. <!-- Banner -->
  13. <view class="banner-section">
  14. <image src="/pages-sell/static/top-banner.png" class="top-banner" mode="widthFix"></image>
  15. </view>
  16. <!-- Content Area -->
  17. <view class="content-area">
  18. <!-- Everyone is watching -->
  19. <view class="section-block" v-if="hotBook && hotBook.isbn">
  20. <text class="section-title">大家都在看</text>
  21. <HotRecommendItem :item="hotBook" @add-cart="addToCart"></HotRecommendItem>
  22. </view>
  23. <!-- Filter Bar -->
  24. <view class="filter-bar">
  25. <view class="filter-item" :class="{ active: sort === 1 }" @click="handleSort(1)">
  26. <text>综合</text>
  27. <view class="sort-icons">
  28. <u-icon name="arrow-down-fill" :color="sort === 1 ? '#38C148' : '#cccccc'" size="14"></u-icon>
  29. </view>
  30. </view>
  31. <view class="filter-item" :class="{ active: sort === 4 || sort === 5 }" @click="handleSort('sales')">
  32. <text>销量</text>
  33. <view class="sort-icons">
  34. <u-icon name="arrow-up-fill" :color="sort === 4 ? '#38C148' : '#cccccc'" size="14"></u-icon>
  35. <u-icon name="arrow-down-fill" :color="sort === 5 ? '#38C148' : '#cccccc'" size="14"></u-icon>
  36. </view>
  37. </view>
  38. <view class="filter-item" :class="{ active: sort === 2 || sort === 3 }" @click="handleSort('price')">
  39. <text>价格</text>
  40. <view class="sort-icons">
  41. <u-icon name="arrow-up-fill" :color="sort === 2 ? '#38C148' : '#cccccc'" size="14"></u-icon>
  42. <u-icon name="arrow-down-fill" :color="sort === 3 ? '#38C148' : '#cccccc'" size="14"></u-icon>
  43. </view>
  44. </view>
  45. <view class="filter-item" @click="showFilter = true">
  46. <text>筛选</text>
  47. <image src="/pages-sell/static/search-result/icon-filter.png" class="icon-filter"></image>
  48. </view>
  49. </view>
  50. <!-- Book List -->
  51. <view class="book-list">
  52. <RecommendItem v-for="(item, index) in bookList" :key="index" :item="item" @add-cart="addToCart"
  53. :show-desc="false">
  54. </RecommendItem>
  55. <u-loadmore :status="loadStatus" margin-top="30" margin-bottom="30"></u-loadmore>
  56. </view>
  57. </view>
  58. <!-- Filter Popup -->
  59. <u-popup v-model="showFilter" mode="bottom">
  60. <view class="filter-popup">
  61. <view class="filter-content">
  62. <view class="filter-title">价格区间</view>
  63. <view class="price-inputs">
  64. <u-input v-model="tempMinPrice" type="number" placeholder="最低价" border="surround"></u-input>
  65. <view class="divider">-</view>
  66. <u-input v-model="tempMaxPrice" type="number" placeholder="最高价" border="surround"></u-input>
  67. </view>
  68. </view>
  69. <view class="filter-footer">
  70. <view class="btn reset" @click="resetFilter">重置</view>
  71. <view class="btn confirm" @click="confirmFilter">确定</view>
  72. </view>
  73. </view>
  74. </u-popup>
  75. <!-- Red Packet Float -->
  76. <!-- <view class="red-packet-float" @click="openPacket">
  77. <view class="time-badge">
  78. <text>剩</text>
  79. <u-count-down :timestamp="timestamp" separator="colon" color="#DF1407" bg-color="transparent"
  80. font-size="18" separator-size="18" separator-color="#DF1407"></u-count-down>
  81. </view>
  82. <image src="/pages-sell/static/search/icon-red-packet.png" class="packet-img" mode="aspectFit"></image>
  83. </view> -->
  84. <!-- Surprise Packet Dialog -->
  85. <PacketDialog ref="packetDialog"></PacketDialog>
  86. </view>
  87. </template>
  88. <script>
  89. import RecommendItem from '../components/recommend-item/index.vue';
  90. import HotRecommendItem from '../components/hot-recommend-item/index.vue';
  91. import Navbar from '@/components/navbar/navbar.vue';
  92. import PacketDialog from '@/pages-sell/components/packet-dialog/index.vue';
  93. export default {
  94. components: {
  95. RecommendItem,
  96. HotRecommendItem,
  97. Navbar,
  98. PacketDialog
  99. },
  100. data() {
  101. return {
  102. keyword: '',
  103. pageNum: 1,
  104. pageSize: 10,
  105. hotBook: {},
  106. bookList: [],
  107. loadStatus: 'loadmore',
  108. navbarBackground: 'transparent',
  109. navbarTitleColor: '#ffffff',
  110. navbarIconColor: '#ffffff',
  111. sort: 1, // 1-综合 2-价格升序 3-价格降序 4-销量升序 5-销量降序
  112. showFilter: false,
  113. tempMinPrice: '',
  114. tempMaxPrice: '',
  115. minPrice: '',
  116. maxPrice: '',
  117. timestamp: 86400, // 24 hours countdown
  118. }
  119. },
  120. onPullDownRefresh() {
  121. this.pageNum = 1;
  122. this.loadStatus = 'loading';
  123. this.loadData();
  124. },
  125. onReachBottom() {
  126. if (this.loadStatus === 'nomore') return;
  127. this.pageNum++;
  128. this.loadStatus = 'loading';
  129. this.loadData();
  130. },
  131. onPageScroll(e) {
  132. if (e.scrollTop > 50) {
  133. this.navbarBackground = '#ffffff';
  134. this.navbarTitleColor = '#000000';
  135. this.navbarIconColor = '#000000';
  136. } else {
  137. this.navbarBackground = 'transparent';
  138. this.navbarTitleColor = '#ffffff';
  139. this.navbarIconColor = '#ffffff';
  140. }
  141. },
  142. onLoad(options) {
  143. this.keyword = options.keyword ? decodeURIComponent(options.keyword) : '';
  144. this.loadData();
  145. },
  146. methods: {
  147. loadData() {
  148. const params = {
  149. keyword: this.keyword,
  150. pageNum: this.pageNum,
  151. pageSize: this.pageSize,
  152. sort: this.sort
  153. };
  154. if (this.minPrice) params.minPrice = this.minPrice;
  155. if (this.maxPrice) params.maxPrice = this.maxPrice;
  156. this.$u.api.getSearchKeywordAjax(params).then(res => {
  157. uni.stopPullDownRefresh();
  158. const rows = res.data.rows || [];
  159. if (this.pageNum === 1) {
  160. this.bookList = rows;
  161. } else {
  162. this.bookList = [...this.bookList, ...rows];
  163. }
  164. if (rows.length < this.pageSize) {
  165. this.loadStatus = 'nomore';
  166. } else {
  167. this.loadStatus = 'loadmore';
  168. }
  169. if(res.data.couponName){
  170. this.openPacket({
  171. couponName: res.data.couponName,
  172. faceMoney: res.data.faceMoney,
  173. thresholdMoney: res.data.thresholdMoney,
  174. });
  175. }
  176. }).catch(() => {
  177. uni.stopPullDownRefresh();
  178. this.loadStatus = 'loadmore';
  179. });
  180. if (this.pageNum === 1) {
  181. this.$u.api.getSearchRecommendAjax().then(res => {
  182. if (res.code == 200) {
  183. res.data.discountDesc = res.data.productPrice ? (res.data.productPrice / res.data.price) + '折' : '';
  184. res.data.discountPrice = res.data.productPrice ? res.data.price - res.data.productPrice : '';
  185. this.hotBook = res.data;
  186. }
  187. });
  188. }
  189. },
  190. handleSort(type) {
  191. if (type === 1) {
  192. if (this.sort === 1) return;
  193. this.sort = 1;
  194. } else if (type === 'price') {
  195. if (this.sort === 2) {
  196. this.sort = 3;
  197. } else {
  198. this.sort = 2;
  199. }
  200. } else if (type === 'sales') {
  201. if (this.sort === 5) {
  202. this.sort = 4;
  203. } else {
  204. this.sort = 5;
  205. }
  206. }
  207. this.pageNum = 1;
  208. this.loadStatus = 'loading';
  209. this.loadData();
  210. },
  211. resetFilter() {
  212. this.tempMinPrice = '';
  213. this.tempMaxPrice = '';
  214. },
  215. confirmFilter() {
  216. this.minPrice = this.tempMinPrice;
  217. this.maxPrice = this.tempMaxPrice;
  218. this.showFilter = false;
  219. this.pageNum = 1;
  220. this.loadStatus = 'loading';
  221. this.loadData();
  222. },
  223. goBack() {
  224. uni.navigateBack();
  225. },
  226. toFeedback() {
  227. uni.navigateTo({
  228. url: '/pages-sell/pages/feedback'
  229. });
  230. },
  231. onSearch(val) {
  232. console.log('Search:', val);
  233. this.keyword = val;
  234. this.pageNum = 1;
  235. this.loadData();
  236. },
  237. addToCart(data) {
  238. // data now contains { product, quality, quantity } from the popup
  239. console.log('Added to cart:', data);
  240. uni.showToast({
  241. title: '已加入购物车',
  242. icon: 'success'
  243. });
  244. },
  245. openPacket(data) {
  246. this.$refs.packetDialog.open(data);
  247. },
  248. closePacket() {
  249. this.$refs.packetDialog.close();
  250. }
  251. }
  252. }
  253. </script>
  254. <style lang="scss" scoped>
  255. .search-result-page {
  256. min-height: 100vh;
  257. background-color: #F6F6F6;
  258. font-family: 'Source Han Sans SC', sans-serif;
  259. position: relative;
  260. }
  261. /* 顶部大背景图 */
  262. .top-bg-image {
  263. position: fixed;
  264. top: 0;
  265. left: 0;
  266. width: 100%;
  267. z-index: 0;
  268. display: block;
  269. }
  270. .search-bar-wrapper {
  271. position: relative;
  272. z-index: 2;
  273. display: flex;
  274. align-items: center;
  275. padding: 0 30rpx;
  276. height: 88rpx;
  277. width: 100%;
  278. }
  279. .banner-section {
  280. position: relative;
  281. width: 100%;
  282. z-index: 1;
  283. padding: 10rpx 30rpx;
  284. .top-banner {
  285. width: 100%;
  286. display: block;
  287. }
  288. }
  289. .content-area {
  290. position: relative;
  291. z-index: 2;
  292. padding: 30rpx 30rpx;
  293. border-radius: 30rpx 30rpx 0 0;
  294. min-height: 500rpx;
  295. .section-block {
  296. margin-bottom: 30rpx;
  297. background-color: #fff;
  298. padding: 30rpx 24rpx;
  299. border-radius: 20rpx;
  300. .section-title {
  301. font-size: 32rpx;
  302. font-weight: bold;
  303. color: #333;
  304. margin-bottom: 20rpx;
  305. display: block;
  306. }
  307. }
  308. }
  309. .filter-bar {
  310. display: flex;
  311. justify-content: space-between;
  312. align-items: center;
  313. margin-bottom: 20rpx;
  314. .filter-item {
  315. display: flex;
  316. align-items: center;
  317. font-size: 28rpx;
  318. color: #666;
  319. &.active {
  320. color: #333;
  321. font-weight: bold;
  322. .triangle-icon {
  323. border-top-color: #333;
  324. }
  325. }
  326. text {
  327. margin-right: 6rpx;
  328. }
  329. .triangle-icon {
  330. width: 0;
  331. height: 0;
  332. border-left: 8rpx solid transparent;
  333. border-right: 8rpx solid transparent;
  334. border-top: 10rpx solid #666;
  335. }
  336. .sort-icons {
  337. display: flex;
  338. flex-direction: column;
  339. margin-left: 4rpx;
  340. justify-content: center;
  341. gap: 4rpx;
  342. u-icon {
  343. margin: -2rpx 0;
  344. }
  345. }
  346. .icon-filter {
  347. width: 24rpx;
  348. height: 24rpx;
  349. margin-left: 4rpx;
  350. }
  351. }
  352. }
  353. .book-list {
  354. background: #fff;
  355. border-radius: 20rpx;
  356. padding: 0 24rpx;
  357. padding-bottom: 40rpx;
  358. }
  359. .filter-popup {
  360. background-color: #fff;
  361. height: 100%;
  362. display: flex;
  363. flex-direction: column;
  364. .filter-content {
  365. flex: 1;
  366. padding: 30rpx;
  367. .filter-title {
  368. font-size: 30rpx;
  369. font-weight: bold;
  370. color: #333;
  371. margin-bottom: 30rpx;
  372. }
  373. .price-inputs {
  374. display: flex;
  375. align-items: center;
  376. justify-content: space-between;
  377. u-input {
  378. flex: 1;
  379. }
  380. .divider {
  381. margin: 0 20rpx;
  382. color: #999;
  383. }
  384. }
  385. }
  386. .filter-footer {
  387. display: flex;
  388. height: 100rpx;
  389. .btn {
  390. flex: 1;
  391. display: flex;
  392. align-items: center;
  393. justify-content: center;
  394. font-size: 32rpx;
  395. &.reset {
  396. background-color: #fff;
  397. color: #666;
  398. border-top: 1rpx solid #eee;
  399. }
  400. &.confirm {
  401. background-color: #38C148;
  402. color: #fff;
  403. }
  404. }
  405. }
  406. }
  407. .red-packet-float {
  408. position: fixed;
  409. bottom: 200rpx;
  410. right: 40rpx;
  411. z-index: 100;
  412. display: flex;
  413. flex-direction: column;
  414. align-items: center;
  415. .time-badge {
  416. background: #FFE173;
  417. color: #DF1407;
  418. font-size: 18rpx;
  419. padding: 4rpx 10rpx;
  420. border-radius: 10rpx;
  421. position: absolute;
  422. top: -40rpx;
  423. right: -20rpx;
  424. white-space: nowrap;
  425. z-index: 2;
  426. display: flex;
  427. align-items: center;
  428. text {
  429. margin-right: 4rpx;
  430. }
  431. }
  432. .packet-img {
  433. width: 100rpx;
  434. height: 120rpx;
  435. }
  436. }
  437. </style>