detail.vue 10 KB

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