recommend.vue 7.0 KB

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