detail.vue 13 KB

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