topic.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. });
  111. this.$updateCartBadge();
  112. }
  113. });
  114. }
  115. }
  116. }
  117. </script>
  118. <style lang="scss" scoped>
  119. .feature-page {
  120. min-height: 100vh;
  121. background-color: #F8F8F8;
  122. position: relative;
  123. }
  124. .header-bg {
  125. position: fixed;
  126. top: 0;
  127. left: 0;
  128. width: 100%;
  129. z-index: 0;
  130. }
  131. .header-content {
  132. position: relative;
  133. z-index: 1;
  134. padding: 0 40rpx;
  135. display: flex;
  136. flex-direction: column;
  137. align-items: center;
  138. justify-content: center;
  139. min-height: 200rpx;
  140. .title-area {
  141. width: 100%;
  142. .main-title {
  143. font-family: YouSheBiaoTiHei;
  144. font-weight: 400;
  145. font-size: 60rpx;
  146. color: #FFFFFF;
  147. text-shadow: 2px 2px 4px #0C256D;
  148. text-align: center;
  149. }
  150. }
  151. }
  152. .list-container {
  153. position: relative;
  154. z-index: 1;
  155. background-color: #fff;
  156. border-radius: 40rpx 40rpx 0 0;
  157. padding: 10rpx 40rpx 40rpx;
  158. min-height: calc(100vh - 360rpx);
  159. }
  160. .refresh-fab {
  161. position: fixed;
  162. right: 30rpx;
  163. bottom: 30%;
  164. width: 108rpx;
  165. height: 108rpx;
  166. border-radius: 50%;
  167. z-index: 100;
  168. display: flex;
  169. align-items: center;
  170. justify-content: center;
  171. overflow: hidden;
  172. .refresh-bg {
  173. position: absolute;
  174. top: 0;
  175. left: 0;
  176. width: 100%;
  177. height: 100%;
  178. background-color: #000000;
  179. opacity: 0.2;
  180. /* Adjusted for visibility, user said 0.1 but that might be too faint for white text bg */
  181. z-index: 1;
  182. }
  183. .refresh-content {
  184. position: relative;
  185. z-index: 2;
  186. display: flex;
  187. flex-direction: column;
  188. align-items: center;
  189. justify-content: center;
  190. .refresh-text {
  191. font-size: 20rpx;
  192. color: #FFFFFF;
  193. margin-top: 4rpx;
  194. }
  195. }
  196. }
  197. </style>