topic.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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="#ffffff" back-icon-color="#ffffff"></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. }
  47. },
  48. onLoad(options) {
  49. if (options.cateId || options.id) {
  50. this.cateId = options.cateId || options.id;
  51. this.loadData();
  52. }
  53. },
  54. methods: {
  55. loadData() {
  56. uni.showLoading({ title: '加载中' });
  57. this.$u.api.getBookListByCateIdAjax({
  58. cateId: this.cateId,
  59. pageNum: this.pageNum,
  60. pageSize: this.pageSize
  61. }).then(res => {
  62. uni.hideLoading();
  63. if (res.code == 200) {
  64. const data = res.data;
  65. this.showName = data.showName || '图书专题';
  66. this.imageUrl = data.imgUrl || '/pages-sell/static/topic/top-bg-2.png';
  67. this.total = data.bookPageList.total;
  68. this.bookList = data.bookPageList.rows.map(item => {
  69. return {
  70. title: item.bookName,
  71. author: item.author || '', // API doesn't return author currently
  72. price: item.bookPrice,
  73. originalPrice: item.bookOriginalPrice,
  74. cover: item.bookImg,
  75. desc: item.bookShortReview,
  76. id: item.bookId || item.id,
  77. isbn: item.bookIsbn
  78. }
  79. });
  80. // Scroll to top when data changes
  81. uni.pageScrollTo({
  82. scrollTop: 0,
  83. duration: 300
  84. });
  85. }
  86. }).catch(() => {
  87. uni.hideLoading();
  88. });
  89. },
  90. changeBatch() {
  91. const maxPages = Math.ceil(this.total / this.pageSize);
  92. if (this.pageNum < maxPages) {
  93. this.pageNum++;
  94. } else {
  95. this.pageNum = 1;
  96. }
  97. this.loadData();
  98. },
  99. handleAddToCart(data) {
  100. console.log('Add to cart:', data);
  101. // Implement actual add to cart logic if needed, or keep toast
  102. this.$u.api.addShopCartAjax({
  103. bookId: data.id,
  104. num: 1
  105. }).then(res => {
  106. if (res.code == 200) {
  107. uni.showToast({
  108. title: '已加入购物车',
  109. icon: 'success',
  110. duration: 3000
  111. });
  112. this.$updateCartBadge();
  113. }
  114. });
  115. }
  116. }
  117. }
  118. </script>
  119. <style lang="scss" scoped>
  120. .feature-page {
  121. min-height: 100vh;
  122. background-color: #F8F8F8;
  123. position: relative;
  124. }
  125. .header-bg {
  126. position: fixed;
  127. top: 0;
  128. left: 0;
  129. width: 100%;
  130. z-index: 0;
  131. }
  132. .header-content {
  133. position: relative;
  134. z-index: 1;
  135. padding: 0 40rpx;
  136. display: flex;
  137. flex-direction: column;
  138. align-items: center;
  139. justify-content: center;
  140. min-height: 200rpx;
  141. .title-area {
  142. width: 100%;
  143. .main-title {
  144. font-family: YouSheBiaoTiHei;
  145. font-weight: 400;
  146. font-size: 60rpx;
  147. color: #FFFFFF;
  148. text-shadow: 2px 2px 4px #0C256D;
  149. text-align: center;
  150. }
  151. }
  152. }
  153. .list-container {
  154. position: relative;
  155. z-index: 1;
  156. background-color: #fff;
  157. border-radius: 40rpx 40rpx 0 0;
  158. padding: 10rpx 40rpx 40rpx;
  159. min-height: calc(100vh - 360rpx);
  160. }
  161. .refresh-fab {
  162. position: fixed;
  163. right: 30rpx;
  164. bottom: 30%;
  165. width: 108rpx;
  166. height: 108rpx;
  167. border-radius: 50%;
  168. z-index: 100;
  169. display: flex;
  170. align-items: center;
  171. justify-content: center;
  172. overflow: hidden;
  173. .refresh-bg {
  174. position: absolute;
  175. top: 0;
  176. left: 0;
  177. width: 100%;
  178. height: 100%;
  179. background-color: #000000;
  180. opacity: 0.2;
  181. /* Adjusted for visibility, user said 0.1 but that might be too faint for white text bg */
  182. z-index: 1;
  183. }
  184. .refresh-content {
  185. position: relative;
  186. z-index: 2;
  187. display: flex;
  188. flex-direction: column;
  189. align-items: center;
  190. justify-content: center;
  191. .refresh-text {
  192. font-size: 20rpx;
  193. color: #FFFFFF;
  194. margin-top: 4rpx;
  195. }
  196. }
  197. }
  198. </style>