detail.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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="navbarTitleColor" :back-icon-color="navbarIconColor"
  7. :background="navbarBackground">
  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="heightFix"></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="showReduceRulePopup" :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" :hasArrivalNotice="product.hasArrivalNotice" @addCart="openSelectPopup" @notify="handleNotify" @collect="handleCollect"></FooterBar>
  64. <!-- Select Popup -->
  65. <SelectGoodPopup ref="selectPopup" @confirm="onPopupConfirm" @notice-change="onNoticeChange"></SelectGoodPopup>
  66. <!-- Share Popup -->
  67. <SharePopup ref="sharePopup" :product="product"></SharePopup>
  68. <!-- Reduce Rule Popup -->
  69. <ReduceRulePopup ref="reduceRulePopup"></ReduceRulePopup>
  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. import ReduceRulePopup from '../components/reduce-rule-popup/index.vue';
  82. export default {
  83. components: {
  84. Navbar,
  85. SelectGoodPopup,
  86. InfoCard,
  87. ServiceCard,
  88. ProductContent,
  89. FooterBar,
  90. FloatingDrag,
  91. SharePopup,
  92. ReduceRulePopup
  93. },
  94. data() {
  95. return {
  96. currentTab: 0,
  97. hasStock: false, // Toggle this to test stock status
  98. navbarBackground: 'transparent',
  99. navbarTitleColor: '#ffffff',
  100. navbarIconColor: '#ffffff',
  101. tipsContent: [
  102. '印刷版次较多,二手图书封面、版次、原价等信息可能与商品介绍有差异,具体以收到实物为准;',
  103. '二手图书性质特殊,不保证随新书赠送的光盘、海报、卡片等内容,仅支持图书质量问题退款,否则将扣除运费成本;',
  104. '收到的图书如有质量问题,请于七天内联系客服处理,超出售后时效,不予处理。'
  105. ],
  106. relatedBooksList: [],
  107. product: {},
  108. servicePosition: {
  109. left: "auto",
  110. right: 0,
  111. bottom: "300rpx",
  112. },
  113. }
  114. },
  115. onLoad(options) {
  116. const isbn = options.isbn || options.id; // Support both just in case
  117. if (isbn) {
  118. this.getBookDetail(isbn);
  119. } else {
  120. uni.showToast({
  121. title: '参数错误',
  122. icon: 'none'
  123. });
  124. setTimeout(() => {
  125. uni.navigateBack();
  126. }, 1500);
  127. }
  128. },
  129. onPageScroll(e) {
  130. if (e.scrollTop > 0) {
  131. this.navbarBackground = '#ffffff';
  132. this.navbarTitleColor = '#000000';
  133. this.navbarIconColor = '#000000';
  134. } else {
  135. this.navbarBackground = 'transparent';
  136. this.navbarTitleColor = '#ffffff';
  137. this.navbarIconColor = '#ffffff';
  138. }
  139. },
  140. methods: {
  141. getBookDetail(isbn) {
  142. uni.showLoading({ title: '加载中' });
  143. this.$u.api.getBookDetailAjax({ isbn }).then(res => {
  144. uni.hideLoading();
  145. if (res.code === 200) {
  146. this.product = res.data;
  147. this.hasStock = res.data.skuList.some(sku => sku.stockNum > 0);
  148. if (res.data.recommendList) {
  149. this.relatedBooksList = res.data.recommendList;
  150. }
  151. } else {
  152. uni.showToast({
  153. title: res.msg || '获取详情失败',
  154. icon: 'none'
  155. });
  156. }
  157. }).catch(() => {
  158. uni.hideLoading();
  159. });
  160. },
  161. switchTab(index) {
  162. this.currentTab = index;
  163. },
  164. openSelectPopup(sourceFrom) {
  165. this.$refs.selectPopup.open(this.product, sourceFrom);
  166. },
  167. onNoticeChange(val) {
  168. this.$set(this.product, 'hasArrivalNotice', val);
  169. },
  170. handleNotify() {
  171. const isCancel = this.product.hasArrivalNotice === 1;
  172. const apiUrl = isCancel ? '/token/shop/user/noticeArrivalCancel' : '/token/shop/user/noticeArrival';
  173. uni.showLoading({ mask: true });
  174. uni.$u.http.post(apiUrl, { isbn: this.product.isbn }).then(res => {
  175. uni.hideLoading();
  176. if (res.code === 200) {
  177. this.$set(this.product, 'hasArrivalNotice', isCancel ? 0 : 1);
  178. uni.showToast({
  179. title: isCancel ? '已取消到货通知' : '已订阅到货通知',
  180. icon: 'success'
  181. });
  182. } else {
  183. uni.showToast({
  184. title: res.msg || '操作失败',
  185. icon: 'none'
  186. });
  187. }
  188. }).catch(() => {
  189. uni.hideLoading();
  190. });
  191. },
  192. async onPopupConfirm(data) {
  193. console.log('Added to cart:', data);
  194. await this.$updateCartBadge();
  195. uni.showToast({
  196. title: '已加入购物车',
  197. icon: 'success',
  198. duration: 3000
  199. });
  200. },
  201. handleCollect() {
  202. if (!this.product || !this.product.isbn) {
  203. return this.$u.toast('商品信息不完整');
  204. }
  205. const isCollect = this.product.isCollect;
  206. const api = isCollect ? this.$u.api.removeCollectAjax : this.$u.api.addCollectAjax;
  207. const params = isCollect ? [this.product.isbn] : this.product.isbn;
  208. uni.showLoading({ mask: true });
  209. api(params).then(res => {
  210. uni.hideLoading();
  211. if (res.code === 200) {
  212. this.$set(this.product, 'isCollect', !isCollect);
  213. this.$u.toast(isCollect ? '已取消收藏' : '收藏成功');
  214. } else {
  215. this.$u.toast(res.msg);
  216. }
  217. }).catch(() => {
  218. uni.hideLoading();
  219. });
  220. },
  221. showReduceRulePopup() {
  222. this.$refs.reduceRulePopup.open();
  223. },
  224. onBookClick(book) {
  225. console.log('Book clicked:', book);
  226. uni.navigateTo({
  227. url: '/pages-sell/pages/detail?id=' + encodeURIComponent(book.title)
  228. });
  229. },
  230. openSharePopup() {
  231. this.$refs.sharePopup.open();
  232. },
  233. // 处理位置变更
  234. handlePositionChange(position) {
  235. this.servicePosition = position;
  236. },
  237. //支付宝小程序的客服
  238. navigateToCustomerService() {
  239. uni.navigateTo({
  240. url: "/pages-mine/pages/customer-service",
  241. });
  242. },
  243. },
  244. onShareAppMessage(res) {
  245. if (res && res.from === 'button' && res.target && res.target.dataset && res.target.dataset.shareType === 'product') {
  246. const dataset = res.target.dataset;
  247. return {
  248. title: dataset.title || '',
  249. path: `/pages-sell/pages/detail?isbn=${dataset.isbn}`,
  250. imageUrl: dataset.image || ''
  251. };
  252. }
  253. return {
  254. title: `${this.product.bookName}`,
  255. path: `/pages-sell/pages/detail?isbn=${this.product.isbn}`,
  256. imageUrl: this.product.cover
  257. };
  258. }
  259. }
  260. </script>
  261. <style lang="scss" scoped>
  262. .detail-page {
  263. min-height: 100vh;
  264. background-color: #f5f5f5;
  265. position: relative;
  266. padding-bottom: 100rpx;
  267. }
  268. .header-bg {
  269. position: absolute;
  270. top: 0;
  271. left: 0;
  272. width: 100%;
  273. height: 664rpx;
  274. background: linear-gradient(0deg, #4ED868 0%, #D1FFE5 100%);
  275. z-index: 0;
  276. }
  277. .notification-bar {
  278. position: fixed;
  279. top: 180rpx;
  280. /* Adjust based on navbar height */
  281. left: 30rpx;
  282. z-index: 10;
  283. background: rgba(0, 0, 0, 0.3);
  284. border-radius: 30rpx;
  285. padding: 6rpx 20rpx 6rpx 6rpx;
  286. display: flex;
  287. align-items: center;
  288. .notif-text {
  289. font-size: 24rpx;
  290. color: #fff;
  291. margin-left: 10rpx;
  292. }
  293. }
  294. .content-scroll {
  295. position: relative;
  296. z-index: 1;
  297. height: 100vh;
  298. }
  299. .cover-area {
  300. position: relative;
  301. display: flex;
  302. justify-content: center;
  303. padding-top: 60rpx;
  304. padding-bottom: 40rpx;
  305. .book-cover {
  306. width: 360rpx;
  307. height: 360rpx;
  308. box-shadow: 0 10rpx 20rpx rgba(0, 0, 0, 0.1);
  309. }
  310. .share-btn {
  311. position: absolute;
  312. right: 50rpx;
  313. top: 50rpx;
  314. display: flex;
  315. flex-direction: column;
  316. align-items: center;
  317. z-index: 10; // Ensure it's clickable
  318. .share-icon {
  319. width: 40rpx;
  320. height: 40rpx;
  321. margin-bottom: 4rpx;
  322. }
  323. text {
  324. font-size: 20rpx;
  325. color: #333;
  326. }
  327. }
  328. }
  329. .banner-area {
  330. background: #f5f5f5;
  331. padding: 20rpx;
  332. .banner-img {
  333. width: 100%;
  334. border-radius: 20rpx;
  335. }
  336. }
  337. .service-btn {
  338. width: 100%;
  339. height: 100%;
  340. display: flex;
  341. justify-content: center;
  342. align-items: center;
  343. padding: 0;
  344. margin: 0;
  345. background-color: transparent;
  346. line-height: 1;
  347. border-radius: 0;
  348. &::after {
  349. border: none;
  350. }
  351. .cs-icon {
  352. width: 100rpx;
  353. height: 100rpx;
  354. }
  355. }
  356. .tabs-header {
  357. display: flex;
  358. justify-content: center;
  359. /* Center the tabs */
  360. background: #F8F8F8;
  361. padding: 20rpx 0;
  362. /* Remove horizontal padding as we center items */
  363. .tab-item {
  364. padding: 0 30rpx;
  365. /* Add internal padding for hit area */
  366. position: relative;
  367. text {
  368. font-family: 'Source Han Sans SC';
  369. font-size: 30rpx;
  370. /* Assuming 30px from design tool = 30rpx */
  371. color: #666666;
  372. transition: all 0.3s;
  373. }
  374. &.active {
  375. text {
  376. font-size: 30rpx;
  377. /* Keep consistent size or adjust if 'big' effect needed, user said 30px */
  378. font-weight: bold;
  379. color: #333333;
  380. }
  381. .indicator {
  382. position: absolute;
  383. bottom: 2rpx;
  384. /* Adjust vertical position */
  385. left: 50%;
  386. transform: translateX(-50%);
  387. width: 120rpx;
  388. /* Make it wider or relative to text? Usually fixed or text width. Let's try matching text width visually or a fixed width */
  389. height: 8rpx;
  390. /* Slightly thicker for gradient visibility */
  391. background: linear-gradient(90deg, rgba(78, 217, 100, 0.1) 0%, #4ED964 100%);
  392. border-radius: 4rpx;
  393. }
  394. }
  395. }
  396. }
  397. </style>