detail.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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" :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. </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. onNoticeChange(val) {
  150. this.$set(this.product, 'hasArrivalNotice', val);
  151. },
  152. handleNotify() {
  153. const isCancel = this.product.hasArrivalNotice === 1;
  154. const apiUrl = isCancel ? '/token/shop/user/noticeArrivalCancel' : '/token/shop/user/noticeArrival';
  155. uni.showLoading({ mask: true });
  156. uni.$u.http.post(apiUrl, { isbn: this.product.isbn }).then(res => {
  157. uni.hideLoading();
  158. if (res.code === 200) {
  159. this.$set(this.product, 'hasArrivalNotice', isCancel ? 0 : 1);
  160. uni.showToast({
  161. title: isCancel ? '已取消到货通知' : '已订阅到货通知',
  162. icon: 'success'
  163. });
  164. } else {
  165. uni.showToast({
  166. title: res.msg || '操作失败',
  167. icon: 'none'
  168. });
  169. }
  170. }).catch(() => {
  171. uni.hideLoading();
  172. });
  173. },
  174. onPopupConfirm(data) {
  175. console.log('Added to cart:', data);
  176. uni.showToast({
  177. title: '已加入购物车',
  178. icon: 'success',
  179. duration: 3000
  180. });
  181. this.$updateCartBadge();
  182. },
  183. handleCollect() {
  184. if (!this.product || !this.product.isbn) {
  185. return this.$u.toast('商品信息不完整');
  186. }
  187. const isCollect = this.product.isCollect;
  188. const api = isCollect ? this.$u.api.removeCollectAjax : this.$u.api.addCollectAjax;
  189. const params = isCollect ? [this.product.isbn] : this.product.isbn;
  190. uni.showLoading({ mask: true });
  191. api(params).then(res => {
  192. uni.hideLoading();
  193. if (res.code === 200) {
  194. this.$set(this.product, 'isCollect', !isCollect);
  195. this.$u.toast(isCollect ? '已取消收藏' : '收藏成功');
  196. } else {
  197. this.$u.toast(res.msg);
  198. }
  199. }).catch(() => {
  200. uni.hideLoading();
  201. });
  202. },
  203. showServicePopup() {
  204. // Placeholder for service popup
  205. },
  206. onBookClick(book) {
  207. console.log('Book clicked:', book);
  208. uni.navigateTo({
  209. url: '/pages-sell/pages/detail?id=' + encodeURIComponent(book.title)
  210. });
  211. },
  212. openSharePopup() {
  213. this.$refs.sharePopup.open();
  214. },
  215. // 处理位置变更
  216. handlePositionChange(position) {
  217. this.servicePosition = position;
  218. },
  219. //支付宝小程序的客服
  220. navigateToCustomerService() {
  221. uni.navigateTo({
  222. url: "/pages-mine/pages/customer-service",
  223. });
  224. },
  225. },
  226. onShareAppMessage() {
  227. return {
  228. title: `${this.product.bookName}`,
  229. path: `/pages-sell/pages/detail?isbn=${this.product.isbn}`,
  230. imageUrl: this.product.cover
  231. };
  232. }
  233. }
  234. </script>
  235. <style lang="scss" scoped>
  236. .detail-page {
  237. min-height: 100vh;
  238. background-color: #f5f5f5;
  239. position: relative;
  240. padding-bottom: 100rpx;
  241. }
  242. .header-bg {
  243. position: absolute;
  244. top: 0;
  245. left: 0;
  246. width: 100%;
  247. height: 664rpx;
  248. background: linear-gradient(0deg, #4ED868 0%, #D1FFE5 100%);
  249. z-index: 0;
  250. }
  251. .notification-bar {
  252. position: fixed;
  253. top: 180rpx;
  254. /* Adjust based on navbar height */
  255. left: 30rpx;
  256. z-index: 10;
  257. background: rgba(0, 0, 0, 0.3);
  258. border-radius: 30rpx;
  259. padding: 6rpx 20rpx 6rpx 6rpx;
  260. display: flex;
  261. align-items: center;
  262. .notif-text {
  263. font-size: 24rpx;
  264. color: #fff;
  265. margin-left: 10rpx;
  266. }
  267. }
  268. .content-scroll {
  269. position: relative;
  270. z-index: 1;
  271. height: 100vh;
  272. }
  273. .cover-area {
  274. position: relative;
  275. display: flex;
  276. justify-content: center;
  277. padding-top: 60rpx;
  278. padding-bottom: 40rpx;
  279. .book-cover {
  280. width: 360rpx;
  281. height: 360rpx;
  282. box-shadow: 0 10rpx 20rpx rgba(0, 0, 0, 0.1);
  283. }
  284. .share-btn {
  285. position: absolute;
  286. right: 50rpx;
  287. top: 50rpx;
  288. display: flex;
  289. flex-direction: column;
  290. align-items: center;
  291. z-index: 10; // Ensure it's clickable
  292. .share-icon {
  293. width: 40rpx;
  294. height: 40rpx;
  295. margin-bottom: 4rpx;
  296. }
  297. text {
  298. font-size: 20rpx;
  299. color: #333;
  300. }
  301. }
  302. }
  303. .banner-area {
  304. background: #f5f5f5;
  305. padding: 20rpx;
  306. .banner-img {
  307. width: 100%;
  308. border-radius: 20rpx;
  309. }
  310. }
  311. .service-btn {
  312. width: 100%;
  313. height: 100%;
  314. display: flex;
  315. justify-content: center;
  316. align-items: center;
  317. padding: 0;
  318. margin: 0;
  319. background-color: transparent;
  320. line-height: 1;
  321. border-radius: 0;
  322. &::after {
  323. border: none;
  324. }
  325. .cs-icon {
  326. width: 100rpx;
  327. height: 100rpx;
  328. }
  329. }
  330. .tabs-header {
  331. display: flex;
  332. justify-content: center;
  333. /* Center the tabs */
  334. background: #F8F8F8;
  335. padding: 20rpx 0;
  336. /* Remove horizontal padding as we center items */
  337. .tab-item {
  338. padding: 0 30rpx;
  339. /* Add internal padding for hit area */
  340. position: relative;
  341. text {
  342. font-family: 'Source Han Sans SC';
  343. font-size: 30rpx;
  344. /* Assuming 30px from design tool = 30rpx */
  345. color: #666666;
  346. transition: all 0.3s;
  347. }
  348. &.active {
  349. text {
  350. font-size: 30rpx;
  351. /* Keep consistent size or adjust if 'big' effect needed, user said 30px */
  352. font-weight: bold;
  353. color: #333333;
  354. }
  355. .indicator {
  356. position: absolute;
  357. bottom: 2rpx;
  358. /* Adjust vertical position */
  359. left: 50%;
  360. transform: translateX(-50%);
  361. width: 120rpx;
  362. /* Make it wider or relative to text? Usually fixed or text width. Let's try matching text width visually or a fixed width */
  363. height: 8rpx;
  364. /* Slightly thicker for gradient visibility */
  365. background: linear-gradient(90deg, rgba(78, 217, 100, 0.1) 0%, #4ED964 100%);
  366. border-radius: 4rpx;
  367. }
  368. }
  369. }
  370. }
  371. </style>