topic.vue 4.7 KB

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