detail.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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" @addCart="openSelectPopup" @notify="handleNotify"></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. },
  164. showServicePopup() {
  165. // Placeholder for service popup
  166. },
  167. onBookClick(book) {
  168. console.log('Book clicked:', book);
  169. uni.navigateTo({
  170. url: '/pages-sell/pages/detail?id=' + encodeURIComponent(book.title)
  171. });
  172. },
  173. openSharePopup() {
  174. this.$refs.sharePopup.open();
  175. },
  176. // 处理位置变更
  177. handlePositionChange(position) {
  178. this.servicePosition = position;
  179. },
  180. //支付宝小程序的客服
  181. navigateToCustomerService() {
  182. uni.navigateTo({
  183. url: "/pages-mine/pages/customer-service",
  184. });
  185. },
  186. }
  187. }
  188. </script>
  189. <style lang="scss" scoped>
  190. .detail-page {
  191. min-height: 100vh;
  192. background-color: #f5f5f5;
  193. position: relative;
  194. padding-bottom: 100rpx;
  195. }
  196. .header-bg {
  197. position: absolute;
  198. top: 0;
  199. left: 0;
  200. width: 100%;
  201. height: 664rpx;
  202. background: linear-gradient(0deg, #4ED868 0%, #D1FFE5 100%);
  203. z-index: 0;
  204. }
  205. .notification-bar {
  206. position: fixed;
  207. top: 180rpx;
  208. /* Adjust based on navbar height */
  209. left: 30rpx;
  210. z-index: 10;
  211. background: rgba(0, 0, 0, 0.3);
  212. border-radius: 30rpx;
  213. padding: 6rpx 20rpx 6rpx 6rpx;
  214. display: flex;
  215. align-items: center;
  216. .notif-text {
  217. font-size: 24rpx;
  218. color: #fff;
  219. margin-left: 10rpx;
  220. }
  221. }
  222. .content-scroll {
  223. position: relative;
  224. z-index: 1;
  225. height: 100vh;
  226. }
  227. .cover-area {
  228. position: relative;
  229. display: flex;
  230. justify-content: center;
  231. padding-top: 60rpx;
  232. padding-bottom: 40rpx;
  233. .book-cover {
  234. width: 360rpx;
  235. height: 360rpx;
  236. box-shadow: 0 10rpx 20rpx rgba(0, 0, 0, 0.1);
  237. }
  238. .share-btn {
  239. position: absolute;
  240. right: 50rpx;
  241. top: 50rpx;
  242. display: flex;
  243. flex-direction: column;
  244. align-items: center;
  245. z-index: 10; // Ensure it's clickable
  246. .share-icon {
  247. width: 40rpx;
  248. height: 40rpx;
  249. margin-bottom: 4rpx;
  250. }
  251. text {
  252. font-size: 20rpx;
  253. color: #333;
  254. }
  255. }
  256. }
  257. .banner-area {
  258. background: #f5f5f5;
  259. padding: 20rpx;
  260. .banner-img {
  261. width: 100%;
  262. border-radius: 20rpx;
  263. }
  264. }
  265. .service-btn {
  266. padding: 0;
  267. margin: 0;
  268. background-color: transparent;
  269. line-height: 1;
  270. border-radius: 0;
  271. &::after {
  272. border: none;
  273. }
  274. }
  275. .tabs-header {
  276. display: flex;
  277. justify-content: center;
  278. /* Center the tabs */
  279. background: #F8F8F8;
  280. padding: 20rpx 0;
  281. /* Remove horizontal padding as we center items */
  282. .tab-item {
  283. padding: 0 30rpx;
  284. /* Add internal padding for hit area */
  285. position: relative;
  286. text {
  287. font-family: 'Source Han Sans SC';
  288. font-size: 30rpx;
  289. /* Assuming 30px from design tool = 30rpx */
  290. color: #666666;
  291. transition: all 0.3s;
  292. }
  293. &.active {
  294. text {
  295. font-size: 30rpx;
  296. /* Keep consistent size or adjust if 'big' effect needed, user said 30px */
  297. font-weight: bold;
  298. color: #333333;
  299. }
  300. .indicator {
  301. position: absolute;
  302. bottom: 2rpx;
  303. /* Adjust vertical position */
  304. left: 50%;
  305. transform: translateX(-50%);
  306. width: 120rpx;
  307. /* Make it wider or relative to text? Usually fixed or text width. Let's try matching text width visually or a fixed width */
  308. height: 8rpx;
  309. /* Slightly thicker for gradient visibility */
  310. background: linear-gradient(90deg, rgba(78, 217, 100, 0.1) 0%, #4ED964 100%);
  311. border-radius: 4rpx;
  312. }
  313. }
  314. }
  315. }
  316. </style>