topic.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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="scrollTop > 0 ? '#333333' : '#ffffff'" :back-icon-color="scrollTop > 0 ? '#333333' : '#ffffff'" :background="scrollTop > 0 ? '#ffffff' : 'transparent'"></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" @update-item="updateBookItem($event, index)"></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. scrollTop: 0
  47. }
  48. },
  49. onLoad(options) {
  50. if (options.cateId || options.id) {
  51. this.cateId = options.cateId || options.id;
  52. this.loadData();
  53. }
  54. },
  55. onPageScroll(e) {
  56. this.scrollTop = e.scrollTop;
  57. },
  58. methods: {
  59. loadData() {
  60. uni.showLoading({ title: '加载中' });
  61. this.$u.api.getBookListByCateIdAjax({
  62. cateId: this.cateId,
  63. pageNum: this.pageNum,
  64. pageSize: this.pageSize
  65. }).then(res => {
  66. uni.hideLoading();
  67. if (res.code == 200) {
  68. const data = res.data;
  69. this.showName = data.showName || '图书专题';
  70. this.imageUrl = data.imgUrl || '/pages-sell/static/topic/top-bg-2.png';
  71. this.total = data.bookPageList.total;
  72. this.bookList = data.bookPageList.rows.map(item => {
  73. return {
  74. title: item.bookName,
  75. author: item.author || '', // API doesn't return author currently
  76. price: item.bookPrice,
  77. originalPrice: item.bookOriginalPrice,
  78. cover: item.bookImg,
  79. desc: item.bookShortReview,
  80. availableStock: item.availableStock,
  81. hasArrivalNotice: item.hasArrivalNotice,
  82. id: item.bookId || item.id,
  83. isbn: item.bookIsbn
  84. }
  85. });
  86. // Scroll to top when data changes
  87. uni.pageScrollTo({
  88. scrollTop: 0,
  89. duration: 300
  90. });
  91. }
  92. }).catch(() => {
  93. uni.hideLoading();
  94. });
  95. },
  96. changeBatch() {
  97. const maxPages = Math.ceil(this.total / this.pageSize);
  98. if (this.pageNum < maxPages) {
  99. this.pageNum++;
  100. } else {
  101. this.pageNum = 1;
  102. }
  103. this.loadData();
  104. },
  105. updateBookItem(updatedItem, index) {
  106. this.$set(this.bookList, index, { ...this.bookList[index], ...updatedItem });
  107. },
  108. handleAddToCart(data) {
  109. console.log('Add to cart:', data);
  110. // Implement actual add to cart logic if needed, or keep toast
  111. this.$u.api.addShopCartAjax({
  112. bookId: data.id,
  113. num: 1
  114. }).then(async res => {
  115. if (res.code == 200) {
  116. await this.$updateCartBadge();
  117. uni.showToast({
  118. title: '已加入购物车',
  119. icon: 'success',
  120. duration: 3000
  121. });
  122. }
  123. });
  124. }
  125. },
  126. onShareAppMessage(res) {
  127. if (res.from === "button" && res.target && res.target.dataset && res.target.dataset.shareType === "reduce") {
  128. let reduceCode = uni.getStorageSync("reduceCodeShare");
  129. if (this.$u && this.$u.api && this.$u.api.goToReduceShareAjax) {
  130. this.$u.api.goToReduceShareAjax({ reduceCode: reduceCode });
  131. } else {
  132. uni.$u && uni.$u.http && uni.$u.http.get('/token/shop/order/goToShare', { reduceCode: reduceCode });
  133. }
  134. return {
  135. title: "快来帮我减钱买书吧!",
  136. path: "/pages/home/index?reduceCode=" + reduceCode,
  137. imageUrl: "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
  138. desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
  139. };
  140. }
  141. return {
  142. title: this.showName || '图书专题',
  143. path: `/pages-sell/pages/topic?cateId=${this.cateId}`,
  144. imageUrl: this.imageUrl || ''
  145. };
  146. }
  147. }
  148. </script>
  149. <style lang="scss" scoped>
  150. .feature-page {
  151. min-height: 100vh;
  152. background-color: #F8F8F8;
  153. position: relative;
  154. }
  155. .header-bg {
  156. position: fixed;
  157. top: 0;
  158. left: 0;
  159. width: 100%;
  160. z-index: 0;
  161. }
  162. .header-content {
  163. position: relative;
  164. z-index: 1;
  165. padding: 0 40rpx;
  166. display: flex;
  167. flex-direction: column;
  168. align-items: center;
  169. justify-content: center;
  170. min-height: 200rpx;
  171. .title-area {
  172. width: 100%;
  173. .main-title {
  174. font-family: YouSheBiaoTiHei;
  175. font-weight: 400;
  176. font-size: 60rpx;
  177. color: #FFFFFF;
  178. text-shadow: 2px 2px 4px #0C256D;
  179. text-align: center;
  180. }
  181. }
  182. }
  183. .list-container {
  184. position: relative;
  185. z-index: 1;
  186. background-color: #fff;
  187. border-radius: 40rpx 40rpx 0 0;
  188. padding: 10rpx 40rpx 40rpx;
  189. min-height: calc(100vh - 360rpx);
  190. }
  191. .refresh-fab {
  192. position: fixed;
  193. right: 30rpx;
  194. bottom: 30%;
  195. width: 108rpx;
  196. height: 108rpx;
  197. border-radius: 50%;
  198. z-index: 100;
  199. display: flex;
  200. align-items: center;
  201. justify-content: center;
  202. overflow: hidden;
  203. .refresh-bg {
  204. position: absolute;
  205. top: 0;
  206. left: 0;
  207. width: 100%;
  208. height: 100%;
  209. background-color: #000000;
  210. opacity: 0.2;
  211. /* Adjusted for visibility, user said 0.1 but that might be too faint for white text bg */
  212. z-index: 1;
  213. }
  214. .refresh-content {
  215. position: relative;
  216. z-index: 2;
  217. display: flex;
  218. flex-direction: column;
  219. align-items: center;
  220. justify-content: center;
  221. .refresh-text {
  222. font-size: 20rpx;
  223. color: #FFFFFF;
  224. margin-top: 4rpx;
  225. }
  226. }
  227. }
  228. </style>