topic.vue 4.5 KB

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