topic.vue 6.2 KB

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