topic.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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(async res => {
  106. if (res.code == 200) {
  107. await this.$updateCartBadge();
  108. uni.showToast({
  109. title: '已加入购物车',
  110. icon: 'success',
  111. duration: 3000
  112. });
  113. }
  114. });
  115. }
  116. },
  117. onShareAppMessage(res) {
  118. if (res.from === "button" && res.target && res.target.dataset && res.target.dataset.shareType === "reduce") {
  119. let reduceCode = uni.getStorageSync("reduceCodeShare");
  120. if (this.$u && this.$u.api && this.$u.api.goToReduceShareAjax) {
  121. this.$u.api.goToReduceShareAjax({ reduceCode: reduceCode });
  122. } else {
  123. uni.$u && uni.$u.http && uni.$u.http.get('/token/shop/order/goToShare', { reduceCode: reduceCode });
  124. }
  125. return {
  126. title: "快来帮我减钱买书吧!",
  127. path: "/pages/home/index?reduceCode=" + reduceCode,
  128. imageUrl: "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
  129. desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
  130. };
  131. }
  132. return {
  133. title: this.showName || '图书专题',
  134. path: `/pages-sell/pages/topic?cateId=${this.cateId}`,
  135. imageUrl: this.imageUrl || ''
  136. };
  137. }
  138. }
  139. </script>
  140. <style lang="scss" scoped>
  141. .feature-page {
  142. min-height: 100vh;
  143. background-color: #F8F8F8;
  144. position: relative;
  145. }
  146. .header-bg {
  147. position: fixed;
  148. top: 0;
  149. left: 0;
  150. width: 100%;
  151. z-index: 0;
  152. }
  153. .header-content {
  154. position: relative;
  155. z-index: 1;
  156. padding: 0 40rpx;
  157. display: flex;
  158. flex-direction: column;
  159. align-items: center;
  160. justify-content: center;
  161. min-height: 200rpx;
  162. .title-area {
  163. width: 100%;
  164. .main-title {
  165. font-family: YouSheBiaoTiHei;
  166. font-weight: 400;
  167. font-size: 60rpx;
  168. color: #FFFFFF;
  169. text-shadow: 2px 2px 4px #0C256D;
  170. text-align: center;
  171. }
  172. }
  173. }
  174. .list-container {
  175. position: relative;
  176. z-index: 1;
  177. background-color: #fff;
  178. border-radius: 40rpx 40rpx 0 0;
  179. padding: 10rpx 40rpx 40rpx;
  180. min-height: calc(100vh - 360rpx);
  181. }
  182. .refresh-fab {
  183. position: fixed;
  184. right: 30rpx;
  185. bottom: 30%;
  186. width: 108rpx;
  187. height: 108rpx;
  188. border-radius: 50%;
  189. z-index: 100;
  190. display: flex;
  191. align-items: center;
  192. justify-content: center;
  193. overflow: hidden;
  194. .refresh-bg {
  195. position: absolute;
  196. top: 0;
  197. left: 0;
  198. width: 100%;
  199. height: 100%;
  200. background-color: #000000;
  201. opacity: 0.2;
  202. /* Adjusted for visibility, user said 0.1 but that might be too faint for white text bg */
  203. z-index: 1;
  204. }
  205. .refresh-content {
  206. position: relative;
  207. z-index: 2;
  208. display: flex;
  209. flex-direction: column;
  210. align-items: center;
  211. justify-content: center;
  212. .refresh-text {
  213. font-size: 20rpx;
  214. color: #FFFFFF;
  215. margin-top: 4rpx;
  216. }
  217. }
  218. }
  219. </style>