recommend.vue 6.5 KB

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