search-result.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  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" @update-item="updateHotBook"></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. @update-item="updateBookItem($event, index)" :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) * 10).toFixed(2) + '折' : '';
  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. duration: 3000
  244. });
  245. },
  246. updateBookItem(updatedItem, index) {
  247. this.$set(this.bookList, index, { ...this.bookList[index], ...updatedItem });
  248. },
  249. updateHotBook(updatedItem) {
  250. this.hotBook = { ...this.hotBook, ...updatedItem };
  251. },
  252. openPacket(data) {
  253. this.$refs.packetDialog.open(data);
  254. },
  255. closePacket() {
  256. this.$refs.packetDialog.close();
  257. }
  258. },
  259. onShareAppMessage(res) {
  260. if (res.from === "button" && res.target && res.target.dataset && res.target.dataset.shareType === "reduce") {
  261. let reduceCode = uni.getStorageSync("reduceCodeShare");
  262. if (this.$u && this.$u.api && this.$u.api.goToReduceShareAjax) {
  263. this.$u.api.goToReduceShareAjax({ reduceCode: reduceCode });
  264. } else {
  265. uni.$u && uni.$u.http && uni.$u.http.get('/token/shop/order/goToShare', { reduceCode: reduceCode });
  266. }
  267. return {
  268. title: "快来帮我减钱买书吧!",
  269. path: "/pages/home/index?reduceCode=" + reduceCode,
  270. imageUrl: "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
  271. desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
  272. };
  273. }
  274. return {
  275. title: "书嗨",
  276. path: "/pages-sell/pages/search-result?keyword=" + (this.keyword || ""),
  277. };
  278. }
  279. }
  280. </script>
  281. <style lang="scss" scoped>
  282. .search-result-page {
  283. min-height: 100vh;
  284. background-color: #F6F6F6;
  285. font-family: 'Source Han Sans SC', sans-serif;
  286. position: relative;
  287. }
  288. /* 顶部大背景图 */
  289. .top-bg-image {
  290. position: fixed;
  291. top: 0;
  292. left: 0;
  293. width: 100%;
  294. z-index: 0;
  295. display: block;
  296. }
  297. .search-bar-wrapper {
  298. position: relative;
  299. z-index: 2;
  300. display: flex;
  301. align-items: center;
  302. padding: 0 30rpx;
  303. height: 88rpx;
  304. width: 100%;
  305. }
  306. .banner-section {
  307. position: relative;
  308. width: 100%;
  309. z-index: 1;
  310. padding: 10rpx 30rpx;
  311. .top-banner {
  312. width: 100%;
  313. display: block;
  314. }
  315. }
  316. .content-area {
  317. position: relative;
  318. z-index: 2;
  319. padding: 30rpx 30rpx;
  320. border-radius: 30rpx 30rpx 0 0;
  321. min-height: 500rpx;
  322. .section-block {
  323. margin-bottom: 30rpx;
  324. background-color: #fff;
  325. padding: 30rpx 24rpx;
  326. border-radius: 20rpx;
  327. .section-title {
  328. font-size: 32rpx;
  329. font-weight: bold;
  330. color: #333;
  331. margin-bottom: 20rpx;
  332. display: block;
  333. }
  334. }
  335. }
  336. .filter-bar {
  337. display: flex;
  338. justify-content: space-between;
  339. align-items: center;
  340. margin-bottom: 20rpx;
  341. .filter-item {
  342. display: flex;
  343. align-items: center;
  344. font-size: 28rpx;
  345. color: #666;
  346. &.active {
  347. color: #333;
  348. font-weight: bold;
  349. .triangle-icon {
  350. border-top-color: #333;
  351. }
  352. }
  353. text {
  354. margin-right: 6rpx;
  355. }
  356. .triangle-icon {
  357. width: 0;
  358. height: 0;
  359. border-left: 8rpx solid transparent;
  360. border-right: 8rpx solid transparent;
  361. border-top: 10rpx solid #666;
  362. }
  363. .sort-icons {
  364. display: flex;
  365. flex-direction: column;
  366. margin-left: 4rpx;
  367. justify-content: center;
  368. gap: 4rpx;
  369. u-icon {
  370. margin: -2rpx 0;
  371. }
  372. }
  373. .icon-filter {
  374. width: 24rpx;
  375. height: 24rpx;
  376. margin-left: 4rpx;
  377. }
  378. }
  379. }
  380. .book-list {
  381. background: #fff;
  382. border-radius: 20rpx;
  383. padding: 0 24rpx;
  384. padding-bottom: 40rpx;
  385. }
  386. .filter-popup {
  387. background-color: #fff;
  388. height: 100%;
  389. display: flex;
  390. flex-direction: column;
  391. .filter-content {
  392. flex: 1;
  393. padding: 30rpx;
  394. .filter-title {
  395. font-size: 30rpx;
  396. font-weight: bold;
  397. color: #333;
  398. margin-bottom: 30rpx;
  399. }
  400. .price-inputs {
  401. display: flex;
  402. align-items: center;
  403. justify-content: space-between;
  404. u-input {
  405. flex: 1;
  406. }
  407. .divider {
  408. margin: 0 20rpx;
  409. color: #999;
  410. }
  411. }
  412. }
  413. .filter-footer {
  414. display: flex;
  415. height: 100rpx;
  416. .btn {
  417. flex: 1;
  418. display: flex;
  419. align-items: center;
  420. justify-content: center;
  421. font-size: 32rpx;
  422. &.reset {
  423. background-color: #fff;
  424. color: #666;
  425. border-top: 1rpx solid #eee;
  426. }
  427. &.confirm {
  428. background-color: #38C148;
  429. color: #fff;
  430. }
  431. }
  432. }
  433. }
  434. .red-packet-float {
  435. position: fixed;
  436. bottom: 200rpx;
  437. right: 40rpx;
  438. z-index: 100;
  439. display: flex;
  440. flex-direction: column;
  441. align-items: center;
  442. .time-badge {
  443. background: #FFE173;
  444. color: #DF1407;
  445. font-size: 18rpx;
  446. padding: 4rpx 10rpx;
  447. border-radius: 10rpx;
  448. position: absolute;
  449. top: -40rpx;
  450. right: -20rpx;
  451. white-space: nowrap;
  452. z-index: 2;
  453. display: flex;
  454. align-items: center;
  455. text {
  456. margin-right: 4rpx;
  457. }
  458. }
  459. .packet-img {
  460. width: 100rpx;
  461. height: 120rpx;
  462. }
  463. }
  464. </style>