recommend.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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="推荐图书专题"></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"></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. }
  47. },
  48. onLoad(options) {
  49. if(options.cateId || options.id) {
  50. this.cateId = options.cateId || options.id;
  51. this.loadData();
  52. }
  53. },
  54. onReachBottom() {
  55. if(this.loadStatus == 'loadmore') {
  56. this.loadData();
  57. }
  58. },
  59. onShareAppMessage() {
  60. return {
  61. title: this.showName || '推荐图书专题',
  62. path: `/pages-sell/pages/recommend?cateId=${this.cateId}`,
  63. imageUrl: this.imageUrl || ''
  64. };
  65. },
  66. onShareTimeline() {
  67. return {
  68. title: this.showName || '推荐图书专题',
  69. query: `cateId=${this.cateId}`,
  70. imageUrl: this.imageUrl || ''
  71. };
  72. },
  73. methods: {
  74. loadData() {
  75. this.loadStatus = 'loading';
  76. this.$u.api.getBookListByCateIdAjax({
  77. cateId: this.cateId,
  78. pageNum: this.pageNum,
  79. pageSize: this.pageSize
  80. }).then(res => {
  81. if(res.code == 200) {
  82. const data = res.data;
  83. // Update header info (only needed on first page, but safe to update every time or check pageNum)
  84. if(this.pageNum == 1) {
  85. this.imageUrl = data.imgUrl;
  86. this.showName = data.showName;
  87. this.remark = data.remark;
  88. this.bookList = [];
  89. }
  90. const list = data.bookPageList.rows.map(item => {
  91. return {
  92. title: item.bookName,
  93. author: item.author || '', // API doesn't return author currently
  94. price: item.bookPrice,
  95. originalPrice: item.bookOriginalPrice,
  96. cover: item.bookImg,
  97. desc: item.bookShortReview,
  98. // Pass other props if needed by item component
  99. id: item.bookId || item.id, // Assuming there might be an ID
  100. isbn: item.bookIsbn
  101. }
  102. });
  103. this.bookList = [...this.bookList, ...list];
  104. if(this.bookList.length >= data.bookPageList.total) {
  105. this.loadStatus = 'nomore';
  106. } else {
  107. this.loadStatus = 'loadmore';
  108. this.pageNum++;
  109. }
  110. } else {
  111. this.loadStatus = 'nomore';
  112. }
  113. }).catch(() => {
  114. this.loadStatus = 'nomore';
  115. });
  116. },
  117. goBack() {
  118. uni.navigateBack();
  119. }
  120. }
  121. }
  122. </script>
  123. <style lang="scss" scoped>
  124. .recommend-page {
  125. min-height: 100vh;
  126. background: linear-gradient(180deg, #EBF9F1 0%, #FFFFFF 400rpx);
  127. /* Light green gradient to match theme */
  128. position: relative;
  129. }
  130. .header-bg {
  131. position: fixed;
  132. top: 0;
  133. right: 0;
  134. width: 100%;
  135. height: 624rpx;
  136. z-index: 0;
  137. }
  138. .header-content {
  139. position: relative;
  140. z-index: 1;
  141. padding: 30rpx 40rpx;
  142. display: flex;
  143. align-items: flex-start;
  144. font-family: Source Han Sans SC;
  145. .header-image {
  146. width: 226rpx;
  147. height: 300rpx;
  148. border-radius: 4rpx;
  149. box-shadow: 0 8rpx 16rpx rgba(0,0,0,0.1);
  150. flex-shrink: 0;
  151. }
  152. .header-desc {
  153. flex: 1;
  154. margin-left: 30rpx;
  155. display: flex;
  156. flex-direction: column;
  157. .title-row {
  158. display: flex;
  159. justify-content: space-between;
  160. align-items: flex-start;
  161. margin-bottom: 20rpx;
  162. .title-text {
  163. font-size: 40rpx;
  164. font-weight: bold;
  165. color: #333;
  166. line-height: 1.2;
  167. }
  168. .share-btn {
  169. max-width: 60rpx;
  170. background-color: transparent;
  171. padding: 0;
  172. margin: 0;
  173. line-height: normal;
  174. display: flex;
  175. align-items: center;
  176. justify-content: center;
  177. border: none;
  178. height: 50rpx;
  179. &::after {
  180. border: none;
  181. }
  182. .share-icon {
  183. width: 34rpx;
  184. height: 34rpx;
  185. flex-shrink: 0;
  186. margin-left: 20rpx;
  187. margin-top: 10rpx;
  188. }
  189. }
  190. }
  191. .desc-text {
  192. font-size: 26rpx;
  193. color: #666;
  194. line-height: 1.6;
  195. text-align: justify;
  196. display: -webkit-box;
  197. -webkit-box-orient: vertical;
  198. -webkit-line-clamp: 6;
  199. overflow: hidden;
  200. }
  201. }
  202. }
  203. .list-container {
  204. position: relative;
  205. z-index: 1;
  206. background-color: #fff;
  207. border-radius: 40rpx 40rpx 0 0;
  208. padding: 10rpx 40rpx;
  209. min-height: calc(100vh - 200rpx);
  210. }
  211. </style>