detail.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. <template>
  2. <view class="detail-page">
  3. <!-- Top Background -->
  4. <view class="header-bg"></view>
  5. <!-- Custom Navbar -->
  6. <Navbar :title="product.bookName || '详情'" :titleSize="32" title-color="#fff" back-icon-color="#fff"
  7. background="transparent">
  8. </Navbar>
  9. <!-- Notification Bar -->
  10. <view class="notification-bar">
  11. <u-avatar size="40" src="https://img.yzcdn.cn/vant/cat.jpeg"></u-avatar>
  12. <text class="notif-text">微 ** 用户 购买了 《苏菲的世界》</text>
  13. </view>
  14. <view class="content-scroll">
  15. <!-- Book Cover Area -->
  16. <view class="cover-area">
  17. <image class="book-cover" :src="product.cover" mode="aspectFill"></image>
  18. <view class="share-btn" @click="openSharePopup">
  19. <image src="/pages-sell/static/goods/icon-share.png" class="share-icon"></image>
  20. <text>分享</text>
  21. </view>
  22. </view>
  23. <!-- Product Info Card -->
  24. <InfoCard :product="product"></InfoCard>
  25. <!-- Banner -->
  26. <view class="banner-area">
  27. <image src="/pages-sell/static/top-banner.png" class="banner-img" mode="widthFix"></image>
  28. </view>
  29. <!-- Service Info -->
  30. <ServiceCard @click="showServicePopup" :bookInfo="product"></ServiceCard>
  31. <!-- Customer Service Float -->
  32. <FloatingDrag :width="120" :height="120" :initial-position="servicePosition"
  33. @position-change="handlePositionChange" :z-index="20">
  34. <!-- #ifdef MP-ALIPAY -->
  35. <button class="service-btn" @click="navigateToCustomerService">
  36. <image src="/pages-sell/static/goods/icon-kefu.png" class="cs-icon" mode="aspectFit"></image>
  37. </button>
  38. <!-- #endif -->
  39. <!-- #ifndef MP-ALIPAY -->
  40. <button class="service-btn" open-type="contact">
  41. <image src="/pages-sell/static/goods/icon-kefu.png" class="cs-icon" mode="aspectFit"></image>
  42. </button>
  43. <!-- #endif -->
  44. </FloatingDrag>
  45. <!-- Tabs -->
  46. <view class="tabs-header">
  47. <view class="tab-item" :class="{ active: currentTab === 0 }" @click="switchTab(0)">
  48. <text>商品详情</text>
  49. <view class="indicator" v-if="currentTab === 0"></view>
  50. </view>
  51. <view class="tab-item" :class="{ active: currentTab === 1 }" @click="switchTab(1)">
  52. <text>相关推荐</text>
  53. <view class="indicator" v-if="currentTab === 1"></view>
  54. </view>
  55. </view>
  56. <!-- Product Detail Content -->
  57. <ProductContent :currentTab="currentTab" :product="product" :tipsContent="tipsContent"
  58. :relatedBooksList="relatedBooksList" @bookClick="onBookClick">
  59. </ProductContent>
  60. <u-gap height="220"></u-gap>
  61. </view>
  62. <!-- Footer -->
  63. <FooterBar :hasStock="hasStock" :isCollect="product.isCollect" @addCart="openSelectPopup" @notify="handleNotify" @collect="handleCollect"></FooterBar>
  64. <!-- Select Popup -->
  65. <SelectGoodPopup ref="selectPopup" @confirm="onPopupConfirm"></SelectGoodPopup>
  66. <!-- Share Popup -->
  67. <SharePopup ref="sharePopup" :product="product"></SharePopup>
  68. </view>
  69. </template>
  70. <script>
  71. import Navbar from '@/components/navbar/navbar.vue'
  72. import SelectGoodPopup from '../components/select-good-popup/index.vue'
  73. import InfoCard from '../components/detail/info-card.vue'
  74. import ServiceCard from '../components/detail/service-card.vue'
  75. import ProductContent from '../components/detail/product-content.vue'
  76. import FooterBar from '../components/detail/footer-bar.vue'
  77. import FloatingDrag from "@/components/floating-drag.vue";
  78. import SharePopup from '../components/detail/share-popup.vue';
  79. export default {
  80. components: {
  81. Navbar,
  82. SelectGoodPopup,
  83. InfoCard,
  84. ServiceCard,
  85. ProductContent,
  86. FooterBar,
  87. FloatingDrag,
  88. SharePopup
  89. },
  90. data() {
  91. return {
  92. currentTab: 0,
  93. hasStock: false, // Toggle this to test stock status
  94. tipsContent: [
  95. '印刷版次较多,二手图书封面、版次、原价等信息可能与商品介绍有差异,具体以收到实物为准;',
  96. '二手图书性质特殊,不保证随新书赠送的光盘、海报、卡片等内容,仅支持图书质量问题退款,否则将扣除运费成本;',
  97. '收到的图书如有质量问题,请于七天内联系客服处理,超出售后时效,不予处理。'
  98. ],
  99. relatedBooksList: [],
  100. product: {},
  101. servicePosition: {
  102. left: "auto",
  103. right: 0,
  104. bottom: "300rpx",
  105. },
  106. }
  107. },
  108. onLoad(options) {
  109. const isbn = options.isbn || options.id; // Support both just in case
  110. if (isbn) {
  111. this.getBookDetail(isbn);
  112. } else {
  113. uni.showToast({
  114. title: '参数错误',
  115. icon: 'none'
  116. });
  117. setTimeout(() => {
  118. uni.navigateBack();
  119. }, 1500);
  120. }
  121. },
  122. methods: {
  123. getBookDetail(isbn) {
  124. uni.showLoading({ title: '加载中' });
  125. this.$u.api.getBookDetailAjax({ isbn }).then(res => {
  126. uni.hideLoading();
  127. if (res.code === 200) {
  128. this.product = res.data;
  129. this.hasStock = res.data.skuList.some(sku => sku.stockNum > 0);
  130. if (res.data.recommendList) {
  131. this.relatedBooksList = res.data.recommendList;
  132. }
  133. } else {
  134. uni.showToast({
  135. title: res.msg || '获取详情失败',
  136. icon: 'none'
  137. });
  138. }
  139. }).catch(() => {
  140. uni.hideLoading();
  141. });
  142. },
  143. switchTab(index) {
  144. this.currentTab = index;
  145. },
  146. openSelectPopup(sourceFrom) {
  147. this.$refs.selectPopup.open(this.product, sourceFrom);
  148. },
  149. handleNotify() {
  150. uni.showToast({
  151. title: '已订阅到货通知',
  152. icon: 'success'
  153. });
  154. },
  155. onPopupConfirm(data) {
  156. console.log('Added to cart:', data);
  157. uni.showToast({
  158. title: '已加入购物车',
  159. icon: 'success',
  160. duration: 3000
  161. });
  162. this.$updateCartBadge();
  163. },
  164. handleCollect() {
  165. if (!this.product || !this.product.isbn) {
  166. return this.$u.toast('商品信息不完整');
  167. }
  168. const isCollect = this.product.isCollect;
  169. const api = isCollect ? this.$u.api.removeCollectAjax : this.$u.api.addCollectAjax;
  170. const params = isCollect ? [this.product.isbn] : this.product.isbn;
  171. uni.showLoading({ mask: true });
  172. api(params).then(res => {
  173. uni.hideLoading();
  174. if (res.code === 200) {
  175. this.$set(this.product, 'isCollect', !isCollect);
  176. this.$u.toast(isCollect ? '已取消收藏' : '收藏成功');
  177. } else {
  178. this.$u.toast(res.msg);
  179. }
  180. }).catch(() => {
  181. uni.hideLoading();
  182. });
  183. },
  184. showServicePopup() {
  185. // Placeholder for service popup
  186. },
  187. onBookClick(book) {
  188. console.log('Book clicked:', book);
  189. uni.navigateTo({
  190. url: '/pages-sell/pages/detail?id=' + encodeURIComponent(book.title)
  191. });
  192. },
  193. openSharePopup() {
  194. this.$refs.sharePopup.open();
  195. },
  196. // 处理位置变更
  197. handlePositionChange(position) {
  198. this.servicePosition = position;
  199. },
  200. //支付宝小程序的客服
  201. navigateToCustomerService() {
  202. uni.navigateTo({
  203. url: "/pages-mine/pages/customer-service",
  204. });
  205. },
  206. },
  207. onShareAppMessage() {
  208. return {
  209. title: `${this.product.bookName}`,
  210. path: `/pages-sell/pages/detail?isbn=${this.product.isbn}`,
  211. imageUrl: this.product.cover
  212. };
  213. }
  214. }
  215. </script>
  216. <style lang="scss" scoped>
  217. .detail-page {
  218. min-height: 100vh;
  219. background-color: #f5f5f5;
  220. position: relative;
  221. padding-bottom: 100rpx;
  222. }
  223. .header-bg {
  224. position: absolute;
  225. top: 0;
  226. left: 0;
  227. width: 100%;
  228. height: 664rpx;
  229. background: linear-gradient(0deg, #4ED868 0%, #D1FFE5 100%);
  230. z-index: 0;
  231. }
  232. .notification-bar {
  233. position: fixed;
  234. top: 180rpx;
  235. /* Adjust based on navbar height */
  236. left: 30rpx;
  237. z-index: 10;
  238. background: rgba(0, 0, 0, 0.3);
  239. border-radius: 30rpx;
  240. padding: 6rpx 20rpx 6rpx 6rpx;
  241. display: flex;
  242. align-items: center;
  243. .notif-text {
  244. font-size: 24rpx;
  245. color: #fff;
  246. margin-left: 10rpx;
  247. }
  248. }
  249. .content-scroll {
  250. position: relative;
  251. z-index: 1;
  252. height: 100vh;
  253. }
  254. .cover-area {
  255. position: relative;
  256. display: flex;
  257. justify-content: center;
  258. padding-top: 60rpx;
  259. padding-bottom: 40rpx;
  260. .book-cover {
  261. width: 360rpx;
  262. height: 360rpx;
  263. box-shadow: 0 10rpx 20rpx rgba(0, 0, 0, 0.1);
  264. }
  265. .share-btn {
  266. position: absolute;
  267. right: 50rpx;
  268. top: 50rpx;
  269. display: flex;
  270. flex-direction: column;
  271. align-items: center;
  272. z-index: 10; // Ensure it's clickable
  273. .share-icon {
  274. width: 40rpx;
  275. height: 40rpx;
  276. margin-bottom: 4rpx;
  277. }
  278. text {
  279. font-size: 20rpx;
  280. color: #333;
  281. }
  282. }
  283. }
  284. .banner-area {
  285. background: #f5f5f5;
  286. padding: 20rpx;
  287. .banner-img {
  288. width: 100%;
  289. border-radius: 20rpx;
  290. }
  291. }
  292. .service-btn {
  293. width: 100%;
  294. height: 100%;
  295. display: flex;
  296. justify-content: center;
  297. align-items: center;
  298. padding: 0;
  299. margin: 0;
  300. background-color: transparent;
  301. line-height: 1;
  302. border-radius: 0;
  303. &::after {
  304. border: none;
  305. }
  306. .cs-icon {
  307. width: 100rpx;
  308. height: 100rpx;
  309. }
  310. }
  311. .tabs-header {
  312. display: flex;
  313. justify-content: center;
  314. /* Center the tabs */
  315. background: #F8F8F8;
  316. padding: 20rpx 0;
  317. /* Remove horizontal padding as we center items */
  318. .tab-item {
  319. padding: 0 30rpx;
  320. /* Add internal padding for hit area */
  321. position: relative;
  322. text {
  323. font-family: 'Source Han Sans SC';
  324. font-size: 30rpx;
  325. /* Assuming 30px from design tool = 30rpx */
  326. color: #666666;
  327. transition: all 0.3s;
  328. }
  329. &.active {
  330. text {
  331. font-size: 30rpx;
  332. /* Keep consistent size or adjust if 'big' effect needed, user said 30px */
  333. font-weight: bold;
  334. color: #333333;
  335. }
  336. .indicator {
  337. position: absolute;
  338. bottom: 2rpx;
  339. /* Adjust vertical position */
  340. left: 50%;
  341. transform: translateX(-50%);
  342. width: 120rpx;
  343. /* Make it wider or relative to text? Usually fixed or text width. Let's try matching text width visually or a fixed width */
  344. height: 8rpx;
  345. /* Slightly thicker for gradient visibility */
  346. background: linear-gradient(90deg, rgba(78, 217, 100, 0.1) 0%, #4ED964 100%);
  347. border-radius: 4rpx;
  348. }
  349. }
  350. }
  351. }
  352. </style>