recommend.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <view class="recommend-page">
  3. <!-- Header Background Image -->
  4. <!-- User specified 363rpx x 251rpx. Assuming top-right positioning or similar based on typical designs -->
  5. <image class="header-bg" src="/pages-sell/static/recommend/top-bg.png" mode="aspectFit"></image>
  6. <!-- Custom Navbar -->
  7. <Navbar title="推荐图书专题" :background="scrollTop > 0 ? '#ffffff' : 'transparent'"></Navbar>
  8. <!-- Header Content -->
  9. <view class="header-content">
  10. <image class="header-image" :src="imageUrl" mode="widthFix"></image>
  11. <view class="header-desc">
  12. <view class="title-row">
  13. <text class="title-text">{{ showName }}</text>
  14. <button class="share-btn" open-type="share">
  15. <image class="share-icon" src="/pages-sell/static/recommend/icon-share.png" mode="aspectFit"></image>
  16. </button>
  17. </view>
  18. <text class="desc-text">{{ remark }}</text>
  19. </view>
  20. </view>
  21. <!-- List Content -->
  22. <view class="list-container">
  23. <recommend-item v-for="(item, index) in bookList" :key="index" :item="item" :show-desc="cateType != 1" @update-item="updateBookItem($event, index)"></recommend-item>
  24. <u-loadmore :status="loadStatus" margin-top="30" margin-bottom="30"></u-loadmore>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. import RecommendItem from '../components/recommend-item/index.vue'
  30. import Navbar from '@/components/navbar/navbar.vue';
  31. export default {
  32. components: {
  33. RecommendItem,
  34. Navbar
  35. },
  36. data() {
  37. return {
  38. cateId: '',
  39. pageNum: 1,
  40. pageSize: 10,
  41. loadStatus: 'loadmore',
  42. imageUrl: "",
  43. showName: "",
  44. remark: "",
  45. bookList: [],
  46. cateType: '',
  47. scrollTop: 0
  48. }
  49. },
  50. onLoad(options) {
  51. if(options.cateId || options.id) {
  52. this.cateId = options.cateId || options.id;
  53. this.loadData();
  54. }
  55. },
  56. onPageScroll(e) {
  57. this.scrollTop = e.scrollTop;
  58. },
  59. onReachBottom() {
  60. if(this.loadStatus == 'loadmore') {
  61. this.loadData();
  62. }
  63. },
  64. onShareAppMessage(res) {
  65. if (res.from === "button" && res.target && res.target.dataset && res.target.dataset.shareType === "reduce") {
  66. let reduceCode = uni.getStorageSync("reduceCodeShare");
  67. if (this.$u && this.$u.api && this.$u.api.goToReduceShareAjax) {
  68. this.$u.api.goToReduceShareAjax({ reduceCode: reduceCode });
  69. } else {
  70. uni.$u && uni.$u.http && uni.$u.http.get('/token/shop/order/goToShare', { reduceCode: reduceCode });
  71. }
  72. return {
  73. title: "快来帮我减钱买书吧!",
  74. path: "/pages/home/index?reduceCode=" + reduceCode,
  75. imageUrl: "https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/share.jpg",
  76. desc: "书嗨,专注于书籍交易的平台,提供新书和二手书的买卖服务",
  77. };
  78. }
  79. return {
  80. title: this.showName || '推荐图书专题',
  81. path: `/pages-sell/pages/recommend?cateId=${this.cateId}`,
  82. imageUrl: this.imageUrl || ''
  83. };
  84. },
  85. onShareTimeline() {
  86. return {
  87. title: this.showName || '推荐图书专题',
  88. query: `cateId=${this.cateId}`,
  89. imageUrl: this.imageUrl || ''
  90. };
  91. },
  92. methods: {
  93. loadData() {
  94. this.loadStatus = 'loading';
  95. this.$u.api.getBookListByCateIdAjax({
  96. cateId: this.cateId,
  97. pageNum: this.pageNum,
  98. pageSize: this.pageSize
  99. }).then(res => {
  100. if(res.code == 200) {
  101. const data = res.data;
  102. this.cateType = data.cateType;
  103. // Update header info (only needed on first page, but safe to update every time or check pageNum)
  104. if(this.pageNum == 1) {
  105. this.imageUrl = data.imgUrl;
  106. this.showName = data.showName;
  107. this.remark = data.remark;
  108. this.bookList = [];
  109. }
  110. const list = data.bookPageList.rows.map(item => {
  111. return {
  112. title: item.bookName,
  113. author: item.author || '', // API doesn't return author currently
  114. price: item.bookPrice,
  115. originalPrice: item.bookOriginalPrice,
  116. cover: item.bookImg,
  117. desc: item.bookShortReview,
  118. availableStock: item.availableStock,
  119. hasArrivalNotice: item.hasArrivalNotice,
  120. // Pass other props if needed by item component
  121. id: item.bookId || item.id, // Assuming there might be an ID
  122. isbn: item.bookIsbn
  123. }
  124. });
  125. this.bookList = [...this.bookList, ...list];
  126. if(this.bookList.length >= data.bookPageList.total) {
  127. this.loadStatus = 'nomore';
  128. } else {
  129. this.loadStatus = 'loadmore';
  130. this.pageNum++;
  131. }
  132. } else {
  133. this.loadStatus = 'nomore';
  134. }
  135. }).catch(() => {
  136. this.loadStatus = 'nomore';
  137. });
  138. },
  139. updateBookItem(updatedItem, index) {
  140. this.$set(this.bookList, index, { ...this.bookList[index], ...updatedItem });
  141. },
  142. goBack() {
  143. uni.navigateBack();
  144. }
  145. }
  146. }
  147. </script>
  148. <style lang="scss" scoped>
  149. .recommend-page {
  150. min-height: 100vh;
  151. background: linear-gradient(180deg, #EBF9F1 0%, #FFFFFF 400rpx);
  152. /* Light green gradient to match theme */
  153. position: relative;
  154. }
  155. .header-bg {
  156. position: fixed;
  157. top: 0;
  158. right: 0;
  159. width: 100%;
  160. height: 624rpx;
  161. z-index: 0;
  162. }
  163. .header-content {
  164. position: relative;
  165. z-index: 1;
  166. padding: 30rpx 40rpx;
  167. display: flex;
  168. align-items: flex-start;
  169. font-family: Source Han Sans SC;
  170. .header-image {
  171. width: 226rpx;
  172. height: 300rpx;
  173. border-radius: 4rpx;
  174. box-shadow: 0 8rpx 16rpx rgba(0,0,0,0.1);
  175. flex-shrink: 0;
  176. }
  177. .header-desc {
  178. flex: 1;
  179. margin-left: 30rpx;
  180. display: flex;
  181. flex-direction: column;
  182. .title-row {
  183. display: flex;
  184. justify-content: space-between;
  185. align-items: flex-start;
  186. margin-bottom: 20rpx;
  187. .title-text {
  188. font-size: 40rpx;
  189. font-weight: bold;
  190. color: #333;
  191. line-height: 1.2;
  192. }
  193. .share-btn {
  194. max-width: 60rpx;
  195. background-color: transparent;
  196. padding: 0;
  197. margin: 0;
  198. line-height: normal;
  199. display: flex;
  200. align-items: center;
  201. justify-content: center;
  202. border: none;
  203. height: 50rpx;
  204. &::after {
  205. border: none;
  206. }
  207. .share-icon {
  208. width: 34rpx;
  209. height: 34rpx;
  210. flex-shrink: 0;
  211. margin-left: 20rpx;
  212. margin-top: 10rpx;
  213. }
  214. }
  215. }
  216. .desc-text {
  217. font-size: 26rpx;
  218. color: #666;
  219. line-height: 1.6;
  220. text-align: justify;
  221. display: -webkit-box;
  222. -webkit-box-orient: vertical;
  223. -webkit-line-clamp: 6;
  224. overflow: hidden;
  225. }
  226. }
  227. }
  228. .list-container {
  229. position: relative;
  230. z-index: 1;
  231. background-color: #fff;
  232. border-radius: 40rpx 40rpx 0 0;
  233. padding: 10rpx 40rpx;
  234. min-height: calc(100vh - 200rpx);
  235. }
  236. </style>