topic.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <template>
  2. <view class="feature-page">
  3. <!-- Header Background -->
  4. <image class="header-bg" :src="imageUrl" mode="widthFix"></image>
  5. <!-- Custom Navbar -->
  6. <Navbar title="图书专题" :titleSize="32" :title-color="scrollTop > 0 ? '#333333' : '#ffffff'" :back-icon-color="scrollTop > 0 ? '#333333' : '#ffffff'" :background="scrollTop > 0 ? '#ffffff' : 'transparent'"></Navbar>
  7. <!-- Header Content -->
  8. <view class="header-content">
  9. <view class="title-area">
  10. <text class="main-title">{{ showName }}</text>
  11. </view>
  12. </view>
  13. <!-- List Content -->
  14. <view class="list-container">
  15. <RecommendItem v-for="(item, index) in bookList" :key="index" :item="item" :show-desc="false"
  16. @add-cart="handleAddToCart"></RecommendItem>
  17. <!-- Change Batch Button -->
  18. <view class="refresh-fab" @click="changeBatch" v-if="total > pageSize">
  19. <view class="refresh-bg"></view>
  20. <view class="refresh-content">
  21. <image src="/pages-sell/static/topic/icon-refresh.png" class="refresh-icon" mode="widthFix"
  22. style="width: 32rpx"></image>
  23. <text class="refresh-text">换一批</text>
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import RecommendItem from '../components/recommend-item/index.vue'
  31. import Navbar from '@/components/navbar/navbar.vue'
  32. export default {
  33. components: {
  34. RecommendItem,
  35. Navbar
  36. },
  37. data() {
  38. return {
  39. cateId: '',
  40. pageNum: 1,
  41. pageSize: 5,
  42. total: 0,
  43. bookList: [],
  44. showName: '',
  45. imageUrl: '/pages-sell/static/topic/top-bg-2.png',
  46. scrollTop: 0
  47. }
  48. },
  49. onLoad(options) {
  50. if (options.cateId || options.id) {
  51. this.cateId = options.cateId || options.id;
  52. this.loadData();
  53. }
  54. },
  55. onPageScroll(e) {
  56. this.scrollTop = e.scrollTop;
  57. },
  58. methods: {
  59. loadData() {
  60. uni.showLoading({ title: '加载中' });
  61. this.$u.api.getBookListByCateIdAjax({
  62. cateId: this.cateId,
  63. pageNum: this.pageNum,
  64. pageSize: this.pageSize
  65. }).then(res => {
  66. uni.hideLoading();
  67. if (res.code == 200) {
  68. const data = res.data;
  69. this.showName = data.showName || '图书专题';
  70. this.imageUrl = data.imgUrl || '/pages-sell/static/topic/top-bg-2.png';
  71. this.total = data.bookPageList.total;
  72. this.bookList = data.bookPageList.rows.map(item => {
  73. return {
  74. title: item.bookName,
  75. author: item.author || '', // API doesn't return author currently
  76. price: item.bookPrice,
  77. originalPrice: item.bookOriginalPrice,
  78. cover: item.bookImg,
  79. desc: item.bookShortReview,
  80. id: item.bookId || item.id,
  81. isbn: item.bookIsbn
  82. }
  83. });
  84. // Scroll to top when data changes
  85. uni.pageScrollTo({
  86. scrollTop: 0,
  87. duration: 300
  88. });
  89. }
  90. }).catch(() => {
  91. uni.hideLoading();
  92. });
  93. },
  94. changeBatch() {
  95. const maxPages = Math.ceil(this.total / this.pageSize);
  96. if (this.pageNum < maxPages) {
  97. this.pageNum++;
  98. } else {
  99. this.pageNum = 1;
  100. }
  101. this.loadData();
  102. },
  103. handleAddToCart(data) {
  104. console.log('Add to cart:', data);
  105. // Implement actual add to cart logic if needed, or keep toast
  106. this.$u.api.addShopCartAjax({
  107. bookId: data.id,
  108. num: 1
  109. }).then(async res => {
  110. if (res.code == 200) {
  111. await this.$updateCartBadge();
  112. uni.showToast({
  113. title: '已加入购物车',
  114. icon: 'success',
  115. duration: 3000
  116. });
  117. }
  118. });
  119. }
  120. },
  121. onShareAppMessage(res) {
  122. if (res.from === "button" && res.target && res.target.dataset && res.target.dataset.shareType === "reduce") {
  123. let reduceCode = uni.getStorageSync("reduceCodeShare");
  124. if (this.$u && this.$u.api && this.$u.api.goToReduceShareAjax) {
  125. this.$u.api.goToReduceShareAjax({ reduceCode: reduceCode });
  126. } else {
  127. uni.$u && uni.$u.http && uni.$u.http.get('/token/shop/order/goToShare', { reduceCode: reduceCode });
  128. }
  129. return {
  130. title: "快来帮我减钱买书吧!",
  131. path: "/pages/home/index?reduceCode=" + reduceCode,
  132. imageUrl: "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
  133. desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
  134. };
  135. }
  136. return {
  137. title: this.showName || '图书专题',
  138. path: `/pages-sell/pages/topic?cateId=${this.cateId}`,
  139. imageUrl: this.imageUrl || ''
  140. };
  141. }
  142. }
  143. </script>
  144. <style lang="scss" scoped>
  145. .feature-page {
  146. min-height: 100vh;
  147. background-color: #F8F8F8;
  148. position: relative;
  149. }
  150. .header-bg {
  151. position: fixed;
  152. top: 0;
  153. left: 0;
  154. width: 100%;
  155. z-index: 0;
  156. }
  157. .header-content {
  158. position: relative;
  159. z-index: 1;
  160. padding: 0 40rpx;
  161. display: flex;
  162. flex-direction: column;
  163. align-items: center;
  164. justify-content: center;
  165. min-height: 200rpx;
  166. .title-area {
  167. width: 100%;
  168. .main-title {
  169. font-family: YouSheBiaoTiHei;
  170. font-weight: 400;
  171. font-size: 60rpx;
  172. color: #FFFFFF;
  173. text-shadow: 2px 2px 4px #0C256D;
  174. text-align: center;
  175. }
  176. }
  177. }
  178. .list-container {
  179. position: relative;
  180. z-index: 1;
  181. background-color: #fff;
  182. border-radius: 40rpx 40rpx 0 0;
  183. padding: 10rpx 40rpx 40rpx;
  184. min-height: calc(100vh - 360rpx);
  185. }
  186. .refresh-fab {
  187. position: fixed;
  188. right: 30rpx;
  189. bottom: 30%;
  190. width: 108rpx;
  191. height: 108rpx;
  192. border-radius: 50%;
  193. z-index: 100;
  194. display: flex;
  195. align-items: center;
  196. justify-content: center;
  197. overflow: hidden;
  198. .refresh-bg {
  199. position: absolute;
  200. top: 0;
  201. left: 0;
  202. width: 100%;
  203. height: 100%;
  204. background-color: #000000;
  205. opacity: 0.2;
  206. /* Adjusted for visibility, user said 0.1 but that might be too faint for white text bg */
  207. z-index: 1;
  208. }
  209. .refresh-content {
  210. position: relative;
  211. z-index: 2;
  212. display: flex;
  213. flex-direction: column;
  214. align-items: center;
  215. justify-content: center;
  216. .refresh-text {
  217. font-size: 20rpx;
  218. color: #FFFFFF;
  219. margin-top: 4rpx;
  220. }
  221. }
  222. }
  223. </style>