product-detail-overlay.vue 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181
  1. <template>
  2. <!-- 遮罩层阻止穿透滚动;面板内由子级 scroll-view 负责滚动 -->
  3. <view v-if="show" class="overlay-root client-theme">
  4. <view class="overlay-mask" @click="emitClose" @touchmove.stop.prevent />
  5. <view class="overlay-panel" :class="{ 'overlay-panel--with-tab': !!tabBarActive }">
  6. <view
  7. class="overlay-body"
  8. :class="{ 'overlay-body--with-inner-bar': !props.readonly && props.bottomMode !== 'none' }"
  9. >
  10. <view v-if="loading" class="overlay-skeleton" aria-label="加载中">
  11. <view class="skeleton-banner shimmer" />
  12. <view class="skeleton-info">
  13. <view class="skeleton-line skeleton-line--lg shimmer" />
  14. <view class="skeleton-line skeleton-line--md shimmer" />
  15. </view>
  16. <view class="skeleton-section">
  17. <view class="skeleton-title shimmer" />
  18. <view class="skeleton-row shimmer" />
  19. <view class="skeleton-row shimmer" />
  20. <view class="skeleton-row skeleton-row--short shimmer" />
  21. </view>
  22. </view>
  23. <view v-else-if="!product && !hasSoldOutFallback" class="empty">商品不存在</view>
  24. <view v-else class="overlay-main">
  25. <view class="overlay-sticky-top">
  26. <view class="banner-wrap">
  27. <swiper
  28. v-if="bannerList.length > 0"
  29. class="banner-swiper"
  30. :indicator-dots="bannerList.length > 1"
  31. :autoplay="true"
  32. :interval="3000"
  33. :circular="bannerList.length > 1"
  34. >
  35. <swiper-item v-for="(banner, index) in bannerList" :key="index">
  36. <view class="banner-media-wrap">
  37. <image
  38. v-if="banner.mediaType === 'image'"
  39. :src="ossImg(banner.fileUrl)"
  40. mode="aspectFill"
  41. class="banner-image"
  42. @load="onBannerMediaLoaded(index)"
  43. @error="onBannerMediaLoaded(index)"
  44. />
  45. <video
  46. v-else
  47. :src="banner.fileUrl"
  48. controls
  49. class="banner-video"
  50. @loadedmetadata="onBannerMediaLoaded(index)"
  51. @error="onBannerMediaLoaded(index)"
  52. />
  53. <view v-if="isBannerMediaLoading(index)" class="media-loading">
  54. <view class="media-loading-spinner" />
  55. </view>
  56. </view>
  57. </swiper-item>
  58. </swiper>
  59. <view v-else class="banner-empty">
  60. <text class="banner-empty-text">暂无轮播图</text>
  61. </view>
  62. <view class="banner-close" :style="{ '--sq-safe-top': `${safeTop}px` }" @click="emitClose">
  63. <image class="banner-close-icon" :src="ICON_ARROW_BOTTOM" mode="aspectFit" />
  64. </view>
  65. </view>
  66. <view class="product-info">
  67. <view class="info-top-row">
  68. <view class="info-left">
  69. <text class="name">{{ displayProductName }}</text>
  70. <text v-if="showSoldOutHint" class="sold-out-hint">{{ soldOutHintText }}</text>
  71. <view v-if="showPriceRow" class="price-row">
  72. <text class="price">¥{{ formatPrice(displayPriceFen) }}</text>
  73. <text v-if="showUnitInPriceRow" class="unit">/{{ displayMeasureText }}</text>
  74. </view>
  75. </view>
  76. <view v-if="!props.readonly" class="info-right" @click.stop>
  77. <view v-if="currentCartQty === 0" class="add-btn" @click.stop="addOneToCart">
  78. <text class="add-btn-plus">+</text>
  79. </view>
  80. <view v-else class="quantity-control">
  81. <view class="qty-btn" @click.stop="updateQuantity(-1)">
  82. <text>-</text>
  83. </view>
  84. <text class="qty-num">{{ currentCartQty }}</text>
  85. <view class="qty-btn" @click.stop="updateQuantity(1)">
  86. <text>+</text>
  87. </view>
  88. </view>
  89. </view>
  90. </view>
  91. </view>
  92. </view>
  93. <scroll-view scroll-y class="overlay-scroll" :show-scrollbar="true">
  94. <view class="overlay-scroll-inner">
  95. <view v-if="purchaseInfo" class="purchase-section">
  96. <view class="section-title">采购信息</view>
  97. <view class="purchase-grid">
  98. <view class="purchase-item">
  99. <text class="purchase-label">规格</text>
  100. <text class="purchase-value">{{ purchaseInfo.measureText || '-' }}</text>
  101. </view>
  102. <view class="purchase-item">
  103. <text class="purchase-label">单价</text>
  104. <text class="purchase-value">¥{{ formatPrice(purchaseInfo.unitPrice) }}</text>
  105. </view>
  106. <view class="purchase-item">
  107. <text class="purchase-label">数量</text>
  108. <text class="purchase-value">{{ purchaseInfo.quantity == null ? '-' : purchaseInfo.quantity }}</text>
  109. </view>
  110. <view class="purchase-item">
  111. <text class="purchase-label">小计</text>
  112. <text class="purchase-value purchase-value--strong">¥{{ formatPrice(purchaseInfo.amount) }}</text>
  113. </view>
  114. </view>
  115. </view>
  116. <view class="detail-section" v-if="detailContent">
  117. <view class="section-title">商品详情</view>
  118. <view class="rich-content">
  119. <rich-text :nodes="detailContent"></rich-text>
  120. </view>
  121. </view>
  122. <view class="params-section" v-if="parameterValues.length > 0">
  123. <view class="section-title">商品参数</view>
  124. <view class="params-list">
  125. <view v-for="param in parameterValues" :key="param.parameterId" class="param-item">
  126. <text class="param-name">{{ param.parameterName }}</text>
  127. <text class="param-value">{{ param.paramValue }}</text>
  128. </view>
  129. </view>
  130. </view>
  131. <view class="detail-section" v-if="detailMediaList.length > 0">
  132. <view class="section-title">详情图片/视频</view>
  133. <view class="detail-media-list">
  134. <view v-for="(m, idx) in detailMediaList" :key="m.id || `dm-${idx}`" class="detail-media-item">
  135. <view class="detail-media-wrap">
  136. <image
  137. v-if="m.contentType === 'image'"
  138. :src="ossImg(m.fileUrl)"
  139. mode="widthFix"
  140. class="detail-media-img"
  141. @load="onDetailMediaLoaded(idx)"
  142. @error="onDetailMediaLoaded(idx)"
  143. />
  144. <video
  145. v-else
  146. :src="m.fileUrl"
  147. :poster="ossImg(m.thumbnailUrl || '')"
  148. controls
  149. class="detail-media-video"
  150. @loadedmetadata="onDetailMediaLoaded(idx)"
  151. @error="onDetailMediaLoaded(idx)"
  152. />
  153. <view v-if="isDetailMediaLoading(idx)" class="media-loading">
  154. <view class="media-loading-spinner" />
  155. </view>
  156. </view>
  157. <text v-if="m.description" class="detail-media-desc">{{ m.description }}</text>
  158. </view>
  159. </view>
  160. </view>
  161. </view>
  162. </scroll-view>
  163. </view>
  164. </view>
  165. <view v-if="product && !props.readonly && props.bottomMode !== 'none'" class="bottom-bar">
  166. <view class="cart-inner" @click="goToCart">
  167. <view class="cart-left">
  168. <view class="cart-count">
  169. <text>{{ cartCount > 99 ? '99+' : cartCount }}</text>
  170. </view>
  171. <view class="cart-text-col">
  172. <text class="cart-items-label">已选商品</text>
  173. <text class="cart-total-money">¥{{ formatPrice(cartStore.totalAmount) }}</text>
  174. </view>
  175. </view>
  176. <view class="cart-settle">
  177. <text>{{ props.bottomMode === 'cart' ? '去购物车' : '去结算' }}</text>
  178. </view>
  179. </view>
  180. </view>
  181. </view>
  182. <!-- 与订单详情等非 tabBar 页一致:浮层内展示底部导航,避免全屏遮挡为空白 -->
  183. <view v-if="tabBarActive" class="overlay-tab-bar-wrap">
  184. <ClientTabBar :active="tabBarActive" />
  185. </view>
  186. </view>
  187. </template>
  188. <script setup>
  189. import { computed, ref, watch } from 'vue'
  190. import ClientTabBar from '@/components/client/client-tab-bar.vue'
  191. import { request, parseResponseJson } from '@/utils/request'
  192. import { useCartStore } from '@/stores/cart'
  193. import { formatYuan } from '@/utils/format'
  194. import { ICON_ARROW_BOTTOM } from '@/utils/staticAsset'
  195. import { withOssVersion } from '@/utils/ossCache'
  196. const props = defineProps({
  197. show: { type: Boolean, default: false },
  198. productId: { type: String, default: '' },
  199. readonly: { type: Boolean, default: false },
  200. bottomMode: { type: String, default: 'checkout' },
  201. tabBarActive: { type: String, default: undefined },
  202. initialCartQty: { type: Number, default: undefined },
  203. fallbackProductName: { type: String, default: '' },
  204. fallbackMeasureText: { type: String, default: '' },
  205. fallbackPrice: { type: Number, default: null },
  206. fallbackImageUrl: { type: String, default: '' },
  207. fallbackQuantity: { type: Number, default: null },
  208. fallbackLineAmount: { type: Number, default: null },
  209. fallbackHintText: { type: String, default: '此商品目前已售罄' }
  210. })
  211. const emit = defineEmits(['close'])
  212. const cartStore = useCartStore()
  213. const ossImg = withOssVersion
  214. const loading = ref(false)
  215. const product = ref(null)
  216. const bannerList = ref([])
  217. const parameterValues = ref([])
  218. const detailContent = ref('')
  219. const detailMediaList = ref([])
  220. const bannerMediaLoadedMap = ref({})
  221. const detailMediaLoadedMap = ref({})
  222. const soldOutFallbackActive = ref(false)
  223. const cartCount = ref(0)
  224. const localCartQty = ref(null)
  225. const qtyUpdating = ref(false)
  226. const safeTop = ref(0)
  227. const formatPrice = (fen) => formatYuan(fen ?? 0)
  228. function formatMeasureText(measureValue, unitName) {
  229. const unitText = (unitName || '').trim()
  230. if (measureValue == null || measureValue === '') {
  231. return unitText ? `- ${unitText}` : '-'
  232. }
  233. const num = Number(measureValue)
  234. if (!Number.isNaN(num)) {
  235. const measureText = String(num).replace(/\.?0+$/, '')
  236. return unitText ? `${measureText} ${unitText}` : measureText
  237. }
  238. const measureText = String(measureValue).trim()
  239. return unitText ? `${measureText} ${unitText}` : measureText || '-'
  240. }
  241. const currentCartQty = computed(() => {
  242. if (localCartQty.value != null) return Math.max(0, Number(localCartQty.value) || 0)
  243. const pid = product.value?.id
  244. if (!pid) return 0
  245. const pidStr = String(pid)
  246. const item = cartStore.items.find((i) => String(i.productId) === pidStr)
  247. if (item) return Number(item.quantity) || 0
  248. if (
  249. props.initialCartQty != null &&
  250. props.productId &&
  251. String(props.productId) === pidStr
  252. ) {
  253. return Number(props.initialCartQty) || 0
  254. }
  255. return 0
  256. })
  257. const hasSoldOutFallback = computed(() => {
  258. if (!props.readonly || !props.fallbackProductName) return false
  259. return soldOutFallbackActive.value || !props.productId
  260. })
  261. const soldOutHintText = computed(() => (props.fallbackHintText || '此商品目前已售罄').trim())
  262. const unavailableInRegion = ref(false)
  263. const displayProductName = computed(() => {
  264. if (product.value?.name) return product.value.name
  265. if (hasSoldOutFallback.value) return props.fallbackProductName
  266. return ''
  267. })
  268. const displayMeasureText = computed(() => {
  269. if (hasSoldOutFallback.value) return props.fallbackMeasureText || ''
  270. if (product.value) return formatMeasureText(product.value.measureValue, product.value.unitName)
  271. return ''
  272. })
  273. const displayPriceFen = computed(() => {
  274. // 订单详情只读场景:优先展示历史成交价(fallbackPrice),不受当前价目表影响
  275. if (props.readonly && props.fallbackPrice != null) return Number(props.fallbackPrice) || 0
  276. if (product.value?.price != null) return Number(product.value.price) || 0
  277. if (hasSoldOutFallback.value && props.fallbackPrice != null) return Number(props.fallbackPrice) || 0
  278. return null
  279. })
  280. const showPriceRow = computed(() => displayPriceFen.value != null)
  281. const showUnitInPriceRow = computed(() => {
  282. if (!displayMeasureText.value) return false
  283. // 订单详情等只读弹窗:价格后计量单位需要展示(即使当前区域不出售)
  284. if (props.readonly) return true
  285. return !unavailableInRegion.value
  286. })
  287. const showSoldOutHint = computed(() => hasSoldOutFallback.value || unavailableInRegion.value)
  288. const purchaseInfo = computed(() => {
  289. // 仅在无法加载商品详情、降级到历史快照时展示“采购信息”
  290. if (!props.readonly || !soldOutFallbackActive.value) return null
  291. const qty = props.fallbackQuantity
  292. const unitPrice = props.fallbackPrice
  293. const amount = props.fallbackLineAmount
  294. const measureText = (props.fallbackMeasureText || '').trim()
  295. return {
  296. unitPrice: unitPrice == null ? null : Number(unitPrice) || 0,
  297. quantity: qty == null ? null : Number(qty) || 0,
  298. amount: amount == null ? null : Number(amount) || 0,
  299. measureText
  300. }
  301. })
  302. function resetMediaLoadingState() {
  303. bannerMediaLoadedMap.value = {}
  304. detailMediaLoadedMap.value = {}
  305. }
  306. function onBannerMediaLoaded(index) {
  307. bannerMediaLoadedMap.value = {
  308. ...bannerMediaLoadedMap.value,
  309. [index]: true
  310. }
  311. }
  312. function onDetailMediaLoaded(index) {
  313. detailMediaLoadedMap.value = {
  314. ...detailMediaLoadedMap.value,
  315. [index]: true
  316. }
  317. }
  318. function isBannerMediaLoading(index) {
  319. return !bannerMediaLoadedMap.value[index]
  320. }
  321. function isDetailMediaLoading(index) {
  322. return !detailMediaLoadedMap.value[index]
  323. }
  324. function emitClose() {
  325. emit('close')
  326. }
  327. async function addOneToCart() {
  328. if (!product.value?.id) return
  329. if (qtyUpdating.value) return
  330. qtyUpdating.value = true
  331. const prev = currentCartQty.value
  332. localCartQty.value = prev + 1
  333. try {
  334. const ok = await cartStore.addToCart(product.value, 1)
  335. if (!ok) {
  336. localCartQty.value = prev
  337. }
  338. cartCount.value = cartStore.totalCount
  339. } finally {
  340. qtyUpdating.value = false
  341. }
  342. }
  343. async function updateQuantity(delta) {
  344. const pid = product.value?.id
  345. if (!pid) return
  346. if (qtyUpdating.value) return
  347. const pidStr = String(pid)
  348. const cartItem = cartStore.items.find((item) => String(item.productId) === pidStr)
  349. const prev = currentCartQty.value
  350. const target = prev + delta
  351. if (target < 0) return
  352. qtyUpdating.value = true
  353. localCartQty.value = target
  354. if (cartItem) {
  355. if (target <= 0) {
  356. const ok = await cartStore.removeItem(cartItem.id)
  357. if (!ok) {
  358. localCartQty.value = prev
  359. }
  360. } else {
  361. const ok = await cartStore.updateQuantity(cartItem.id, target)
  362. if (!ok) {
  363. localCartQty.value = prev
  364. }
  365. }
  366. cartCount.value = cartStore.totalCount
  367. qtyUpdating.value = false
  368. return
  369. }
  370. if (delta > 0) {
  371. const ok = await cartStore.addToCart(product.value, delta)
  372. if (!ok) {
  373. localCartQty.value = prev
  374. }
  375. cartCount.value = cartStore.totalCount
  376. }
  377. qtyUpdating.value = false
  378. }
  379. async function loadProductDetail(productId) {
  380. loading.value = true
  381. soldOutFallbackActive.value = false
  382. unavailableInRegion.value = false
  383. resetMediaLoadingState()
  384. const applySoldOutFallback = () => {
  385. soldOutFallbackActive.value = true
  386. product.value = {
  387. id: productId || '',
  388. name: props.fallbackProductName || '',
  389. measureValue: '',
  390. unitName: '',
  391. price: props.fallbackPrice == null ? 0 : Number(props.fallbackPrice) || 0
  392. }
  393. bannerList.value = props.fallbackImageUrl
  394. ? [{ mediaType: 'image', fileUrl: props.fallbackImageUrl }]
  395. : []
  396. parameterValues.value = []
  397. detailContent.value = ''
  398. detailMediaList.value = []
  399. bannerMediaLoadedMap.value = Object.fromEntries(bannerList.value.map((_, i) => [i, false]))
  400. detailMediaLoadedMap.value = {}
  401. }
  402. try {
  403. // 只读(订单详情)优先尝试价目表接口:用于判断“该区域是否出售”
  404. let body = null
  405. if (props.readonly) {
  406. const resCheck = await request({ url: `/mini/client/products/${productId}`, method: 'GET' })
  407. const checkBody = parseResponseJson(resCheck) || {}
  408. const msg = String(checkBody.message || '')
  409. const notInPriceList = msg.includes('商品不存在或不在当前价目表')
  410. if (checkBody.code === 200 && checkBody.data) {
  411. body = checkBody
  412. } else if (notInPriceList) {
  413. unavailableInRegion.value = true
  414. }
  415. }
  416. // 非只读 / 或只读但价目表接口不可用:拉“只读详情”保证内容完整展示
  417. if (!body) {
  418. const res = await request({
  419. url: props.readonly ? `/mini/client/products-ro/${productId}` : `/mini/client/products/${productId}`,
  420. method: 'GET'
  421. })
  422. body = parseResponseJson(res) || {}
  423. }
  424. if (body.code !== 200 || !body.data) {
  425. product.value = null
  426. const msg = String(body.message || '')
  427. const unavailable = msg.includes('商品不存在或不在当前价目表')
  428. if (props.readonly && unavailable && props.fallbackProductName) {
  429. applySoldOutFallback()
  430. return
  431. }
  432. if (props.readonly && props.fallbackProductName) {
  433. applySoldOutFallback()
  434. return
  435. }
  436. uni.showToast({ title: body.message || '加载失败', icon: 'none' })
  437. return
  438. }
  439. product.value = body.data.product || body.data || null
  440. bannerList.value = Array.isArray(body.data.banners) ? body.data.banners : []
  441. parameterValues.value = Array.isArray(body.data.parameterValues) ? body.data.parameterValues : []
  442. detailContent.value = product.value?.detailContent || ''
  443. detailMediaList.value = Array.isArray(body.data.detailMedia)
  444. ? body.data.detailMedia.map((item) => ({
  445. id: item.id,
  446. contentType: item.contentType || item.content_type || 'image',
  447. fileUrl: item.fileUrl || item.file_url || '',
  448. thumbnailUrl: item.thumbnailUrl || item.thumbnail_url,
  449. description: item.description,
  450. sortOrder: item.sortOrder ?? item.sort_order ?? 0
  451. }))
  452. : []
  453. bannerMediaLoadedMap.value = Object.fromEntries(bannerList.value.map((_, i) => [i, false]))
  454. detailMediaLoadedMap.value = Object.fromEntries(detailMediaList.value.map((_, i) => [i, false]))
  455. } catch {
  456. if (props.readonly && props.fallbackProductName) {
  457. applySoldOutFallback()
  458. return
  459. }
  460. uni.showToast({ title: '加载失败', icon: 'none' })
  461. } finally {
  462. loading.value = false
  463. }
  464. }
  465. function goToCart() {
  466. emitClose()
  467. uni.switchTab({
  468. url: '/pages/client/cart/cart',
  469. fail: () => {
  470. uni.reLaunch({ url: '/pages/client/cart/cart' })
  471. }
  472. })
  473. }
  474. function ensureSafeTop() {
  475. const si = uni.getSystemInfoSync?.()
  476. let top = 0
  477. // H5 真机(浏览器/微信内置浏览器)下 safeAreaInsets.top 在部分机型会偏大,
  478. // 这里统一让 H5 走 CSS 的 env(safe-area-inset-top);小程序端再走系统值。
  479. // #ifdef MP-WEIXIN
  480. // 统一口径:让“关闭按钮”的顶部偏移 = 设备安全区顶部 - 当前页面 webview 顶部(windowTop)
  481. // - 自定义导航栏页:windowTop 通常为 0 => top ≈ statusBarHeight
  482. // - 原生导航栏页:windowTop 通常包含导航栏占位 => top 变为 0(避免叠加导致按钮偏下)
  483. const safeInsetTop = Number(si?.safeAreaInsets?.top ?? si?.statusBarHeight ?? 0) || 0
  484. const windowTop = Number(si?.windowTop ?? 0) || 0
  485. top = safeInsetTop - windowTop
  486. // #endif
  487. // #ifndef MP-WEIXIN
  488. top = 0
  489. // #endif
  490. // 保护:出现异常大值时,直接归零(避免按钮被推得很靠下)
  491. const n = Math.max(0, Number(top) || 0)
  492. safeTop.value = n > 60 ? 0 : n
  493. }
  494. watch(
  495. () => props.show,
  496. (v) => {
  497. if (v) {
  498. ensureSafeTop()
  499. cartCount.value = cartStore.totalCount
  500. localCartQty.value = null
  501. if (props.productId) void loadProductDetail(props.productId)
  502. } else {
  503. loading.value = false
  504. localCartQty.value = null
  505. qtyUpdating.value = false
  506. soldOutFallbackActive.value = false
  507. }
  508. },
  509. { immediate: true }
  510. )
  511. watch(
  512. () => props.productId,
  513. (id) => {
  514. if (props.show && id) void loadProductDetail(id)
  515. }
  516. )
  517. </script>
  518. <style lang="scss" scoped>
  519. .overlay-root {
  520. position: fixed;
  521. inset: 0;
  522. z-index: 99999;
  523. }
  524. .overlay-mask {
  525. position: absolute;
  526. inset: 0;
  527. background: rgba(0, 0, 0, 0.4);
  528. }
  529. .overlay-panel {
  530. position: absolute;
  531. inset: 0;
  532. background: #fff;
  533. display: flex;
  534. flex-direction: column;
  535. }
  536. /* 为底部自定义 Tab 留出空间,避免白面板盖住导航栏区域 */
  537. .overlay-panel--with-tab {
  538. bottom: calc(88rpx + env(safe-area-inset-bottom, 0px));
  539. }
  540. /* 有底部 Tab 时,面板已整体上移,body 不再额外加底部留白,避免出现透明空层 */
  541. .overlay-panel--with-tab .overlay-body {
  542. padding-bottom: 0;
  543. }
  544. .overlay-tab-bar-wrap {
  545. position: fixed;
  546. left: 0;
  547. right: 0;
  548. bottom: 0;
  549. z-index: 100001;
  550. }
  551. .overlay-body {
  552. flex: 1;
  553. min-height: 0;
  554. background: #ffffff;
  555. display: flex;
  556. flex-direction: column;
  557. padding-bottom: calc(24rpx + env(safe-area-inset-bottom));
  558. }
  559. .overlay-body--with-inner-bar {
  560. padding-bottom: calc(120rpx + env(safe-area-inset-bottom));
  561. }
  562. .overlay-main {
  563. flex: 1;
  564. min-height: 0;
  565. display: flex;
  566. flex-direction: column;
  567. }
  568. .overlay-sticky-top {
  569. flex-shrink: 0;
  570. }
  571. .overlay-scroll {
  572. flex: 1;
  573. min-height: 0;
  574. height: 0;
  575. background: var(--c-bg);
  576. }
  577. .overlay-skeleton {
  578. padding-bottom: calc(24rpx + env(safe-area-inset-bottom));
  579. background: var(--c-bg);
  580. }
  581. .skeleton-banner {
  582. aspect-ratio: 4 / 3;
  583. height: auto;
  584. background: #e8f1ed;
  585. }
  586. .skeleton-info {
  587. background: #fff;
  588. padding: 20rpx;
  589. border-bottom: 12rpx solid var(--c-bg);
  590. }
  591. .skeleton-line {
  592. height: 28rpx;
  593. border-radius: 14rpx;
  594. background: #e8f1ed;
  595. margin-bottom: 14rpx;
  596. }
  597. .skeleton-line--lg {
  598. height: 40rpx;
  599. width: 72%;
  600. }
  601. .skeleton-line--md {
  602. width: 48%;
  603. margin-bottom: 0;
  604. }
  605. .skeleton-section {
  606. background: #fff;
  607. padding: 20rpx;
  608. }
  609. .skeleton-title {
  610. width: 180rpx;
  611. height: 32rpx;
  612. border-radius: 14rpx;
  613. background: #e8f1ed;
  614. margin-bottom: 18rpx;
  615. }
  616. .skeleton-row {
  617. height: 24rpx;
  618. border-radius: 12rpx;
  619. background: #e8f1ed;
  620. margin-bottom: 14rpx;
  621. }
  622. .skeleton-row--short {
  623. width: 68%;
  624. margin-bottom: 0;
  625. }
  626. .shimmer {
  627. position: relative;
  628. overflow: hidden;
  629. }
  630. .shimmer::after {
  631. content: '';
  632. position: absolute;
  633. inset: 0;
  634. transform: translateX(-100%);
  635. background: linear-gradient(90deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.52), rgba(255, 255, 255, 0));
  636. animation: shimmer-slide 1.2s infinite;
  637. }
  638. @keyframes shimmer-slide {
  639. 100% {
  640. transform: translateX(100%);
  641. }
  642. }
  643. .overlay-scroll-inner {
  644. padding-bottom: 0;
  645. }
  646. .loading,
  647. .empty {
  648. padding: 40rpx;
  649. text-align: center;
  650. color: #909399;
  651. font-size: 26rpx;
  652. }
  653. .banner-wrap {
  654. position: relative;
  655. border-top-left-radius: 24rpx;
  656. border-top-right-radius: 24rpx;
  657. overflow: hidden;
  658. border-bottom: 12rpx solid var(--c-bg);
  659. }
  660. .banner-swiper {
  661. width: 100%;
  662. aspect-ratio: 4 / 3;
  663. height: auto;
  664. background: #fff;
  665. .banner-image,
  666. .banner-video {
  667. width: 100%;
  668. height: 100%;
  669. }
  670. }
  671. .banner-media-wrap,
  672. .detail-media-wrap {
  673. position: relative;
  674. height: 100%;
  675. }
  676. .banner-empty {
  677. width: 100%;
  678. aspect-ratio: 4 / 3;
  679. height: auto;
  680. background: #f5f7fa;
  681. display: flex;
  682. align-items: center;
  683. justify-content: center;
  684. .banner-empty-text {
  685. font-size: 28rpx;
  686. color: #c0c4cc;
  687. }
  688. }
  689. /* 小程序端对 aspect-ratio 支持不稳定:给轮播图明确高度,避免 loading 遮罩飘到顶部 */
  690. /* #ifndef H5 */
  691. .banner-swiper,
  692. .banner-empty {
  693. height: 540rpx;
  694. }
  695. /* #endif */
  696. .banner-close {
  697. position: absolute;
  698. left: 20rpx;
  699. z-index: 999;
  700. width: 60rpx;
  701. height: 60rpx;
  702. border-radius: 50%;
  703. background: rgba(239, 243, 246, 0.92);
  704. display: flex;
  705. align-items: center;
  706. justify-content: center;
  707. border: 1rpx solid rgba(221, 229, 235, 0.9);
  708. }
  709. /* 小程序:只用系统状态栏高度(safeTop),避免与 env(...) 叠加导致 top 过大 */
  710. /* #ifdef MP-WEIXIN */
  711. .banner-close {
  712. top: calc(var(--sq-safe-top, 0px) + 8px);
  713. }
  714. /* #endif */
  715. /* H5:用 env(safe-area-inset-top) 适配刘海屏 */
  716. /* #ifndef MP-WEIXIN */
  717. .banner-close {
  718. top: calc(env(safe-area-inset-top, 0px) + 8px);
  719. }
  720. /* #endif */
  721. .banner-close-icon {
  722. width: 28rpx;
  723. height: 28rpx;
  724. }
  725. .product-info {
  726. margin-top: 0;
  727. background: #fff;
  728. padding: 20rpx;
  729. border-bottom: 12rpx solid var(--c-bg);
  730. .info-top-row {
  731. display: flex;
  732. align-items: flex-start;
  733. justify-content: space-between;
  734. gap: 18rpx;
  735. }
  736. .info-left {
  737. flex: 1;
  738. min-width: 0;
  739. }
  740. .info-right {
  741. flex-shrink: 0;
  742. display: flex;
  743. align-items: center;
  744. justify-content: flex-end;
  745. min-width: 180rpx;
  746. padding-top: 6rpx;
  747. }
  748. .price-row {
  749. display: flex;
  750. align-items: baseline;
  751. gap: 8rpx;
  752. margin-bottom: 12rpx;
  753. }
  754. .price {
  755. font-size: 44rpx;
  756. color: var(--c-danger);
  757. font-weight: 700;
  758. }
  759. .unit {
  760. font-size: 26rpx;
  761. color: #909399;
  762. }
  763. .name {
  764. display: block;
  765. font-size: 32rpx;
  766. color: var(--c-text);
  767. font-weight: 600;
  768. line-height: 1.45;
  769. white-space: normal;
  770. word-break: break-word;
  771. overflow-wrap: break-word;
  772. }
  773. .measure-text {
  774. display: block;
  775. margin-top: 10rpx;
  776. font-size: 24rpx;
  777. color: var(--c-muted);
  778. line-height: 1.4;
  779. }
  780. .sold-out-hint {
  781. display: block;
  782. margin-top: 8rpx;
  783. font-size: 24rpx;
  784. color: #d97706;
  785. line-height: 1.4;
  786. }
  787. }
  788. .add-btn {
  789. width: 54rpx;
  790. height: 54rpx;
  791. background: var(--c-brand-green);
  792. border-radius: 50%;
  793. display: flex;
  794. align-items: center;
  795. justify-content: center;
  796. color: #ffffff;
  797. font-size: 34rpx;
  798. font-weight: 700;
  799. box-sizing: border-box;
  800. padding: 0;
  801. line-height: 1;
  802. }
  803. /* 「+」在圆内几何居中:抵消 text 默认行高/基线导致的视觉偏移 */
  804. .add-btn-plus {
  805. line-height: 1;
  806. font-size: inherit;
  807. font-weight: inherit;
  808. color: inherit;
  809. text-align: center;
  810. display: block;
  811. transform: translateY(-2rpx);
  812. }
  813. .quantity-control {
  814. display: flex;
  815. align-items: center;
  816. gap: 10rpx;
  817. }
  818. .qty-btn {
  819. width: 48rpx;
  820. height: 48rpx;
  821. border: 2rpx solid var(--c-brand-green);
  822. border-radius: 50%;
  823. display: flex;
  824. align-items: center;
  825. justify-content: center;
  826. color: var(--c-brand-green);
  827. font-size: 28rpx;
  828. font-weight: 700;
  829. background: #fff;
  830. }
  831. .qty-num {
  832. min-width: 40rpx;
  833. text-align: center;
  834. font-size: 28rpx;
  835. color: var(--c-text);
  836. }
  837. .section-title {
  838. padding: 18rpx 20rpx;
  839. font-size: 28rpx;
  840. color: var(--c-text);
  841. font-weight: 600;
  842. background: #fff;
  843. border-top: 1rpx solid var(--c-border);
  844. }
  845. .detail-section {
  846. margin-top: 0;
  847. background: #fff;
  848. border-bottom: 12rpx solid var(--c-bg);
  849. .rich-content {
  850. padding: 0 20rpx 16rpx;
  851. font-size: 28rpx;
  852. line-height: 1.6;
  853. color: var(--c-text);
  854. }
  855. .detail-media-list {
  856. padding-bottom: 8rpx;
  857. }
  858. .detail-media-item {
  859. border-top: 1rpx solid #f5f7fa;
  860. }
  861. .detail-media-img {
  862. width: 100%;
  863. display: block;
  864. }
  865. .detail-media-video {
  866. width: 100%;
  867. height: 420rpx;
  868. display: block;
  869. background: #000;
  870. }
  871. .detail-media-desc {
  872. display: block;
  873. padding: 16rpx 24rpx 24rpx;
  874. font-size: 24rpx;
  875. color: #606266;
  876. line-height: 1.5;
  877. }
  878. }
  879. .media-loading {
  880. position: absolute;
  881. inset: 0;
  882. background: rgba(245, 248, 247, 0.85);
  883. display: flex;
  884. align-items: center;
  885. justify-content: center;
  886. z-index: 2;
  887. }
  888. .media-loading-spinner {
  889. width: 40rpx;
  890. height: 40rpx;
  891. border-radius: 50%;
  892. border: 4rpx solid rgba(10, 159, 109, 0.2);
  893. border-top-color: var(--c-brand-green);
  894. animation: spin 0.9s linear infinite;
  895. }
  896. @keyframes spin {
  897. to {
  898. transform: rotate(360deg);
  899. }
  900. }
  901. .params-section {
  902. margin-top: 0;
  903. background: #fff;
  904. border-bottom: 12rpx solid var(--c-bg);
  905. .params-list {
  906. padding: 0 20rpx 16rpx;
  907. }
  908. .param-item {
  909. display: flex;
  910. padding: 10rpx 0;
  911. border-bottom: 1rpx solid #f5f7fa;
  912. &:last-child {
  913. border-bottom: none;
  914. }
  915. }
  916. .param-name {
  917. width: 180rpx;
  918. font-size: 26rpx;
  919. color: #909399;
  920. }
  921. .param-value {
  922. flex: 1;
  923. font-size: 26rpx;
  924. color: var(--c-text);
  925. }
  926. }
  927. .purchase-section {
  928. margin-top: 0;
  929. background: #fff;
  930. border-bottom: 12rpx solid var(--c-bg);
  931. }
  932. .purchase-grid {
  933. padding: 6rpx 20rpx 18rpx;
  934. display: grid;
  935. grid-template-columns: repeat(2, minmax(0, 1fr));
  936. gap: 16rpx 18rpx;
  937. box-sizing: border-box;
  938. }
  939. .purchase-item {
  940. min-width: 0;
  941. padding: 14rpx 16rpx;
  942. border: 1rpx solid #eef3f0;
  943. border-radius: 18rpx;
  944. background: #fbfdfc;
  945. box-sizing: border-box;
  946. }
  947. .purchase-label {
  948. display: block;
  949. font-size: 22rpx;
  950. color: var(--c-muted);
  951. line-height: 1.2;
  952. }
  953. .purchase-value {
  954. display: block;
  955. margin-top: 10rpx;
  956. font-size: 28rpx;
  957. color: var(--c-text);
  958. font-weight: 600;
  959. line-height: 1.25;
  960. word-break: break-word;
  961. }
  962. .purchase-value--strong {
  963. color: var(--c-danger);
  964. }
  965. /* 最后一个内容块不再额外留底部分隔,避免尾部出现空白条 */
  966. .overlay-scroll-inner > view:last-child {
  967. border-bottom: 0;
  968. }
  969. .bottom-bar {
  970. position: absolute;
  971. left: 50%;
  972. transform: translateX(-50%);
  973. z-index: 4;
  974. width: 100%;
  975. max-width: 840rpx;
  976. bottom: constant(safe-area-inset-bottom);
  977. bottom: env(safe-area-inset-bottom, 0px);
  978. padding: 0 24rpx 14rpx;
  979. background: transparent;
  980. box-sizing: border-box;
  981. }
  982. .cart-inner {
  983. min-height: 96rpx;
  984. border-radius: 36rpx;
  985. background: linear-gradient(145deg, #ffffff, #f5fbf8);
  986. border: 1rpx solid #d9ebe3;
  987. color: var(--c-text);
  988. display: flex;
  989. align-items: center;
  990. justify-content: space-between;
  991. padding: 12rpx;
  992. box-shadow: 0 16rpx 36rpx rgba(10, 159, 109, 0.12);
  993. box-sizing: border-box;
  994. }
  995. .cart-left {
  996. display: flex;
  997. align-items: center;
  998. gap: 20rpx;
  999. padding-left: 8rpx;
  1000. flex: 1;
  1001. min-width: 0;
  1002. }
  1003. .cart-count {
  1004. min-width: 52rpx;
  1005. height: 52rpx;
  1006. padding: 0 8rpx;
  1007. border-radius: 26rpx;
  1008. background: linear-gradient(145deg, var(--c-brand-green), var(--c-brand-green-2));
  1009. display: inline-flex;
  1010. align-items: center;
  1011. justify-content: center;
  1012. box-sizing: border-box;
  1013. text {
  1014. font-size: 24rpx;
  1015. font-weight: 700;
  1016. color: #fff;
  1017. }
  1018. }
  1019. .cart-text-col {
  1020. display: flex;
  1021. flex-direction: column;
  1022. gap: 2rpx;
  1023. min-width: 0;
  1024. }
  1025. .cart-items-label {
  1026. font-size: 22rpx;
  1027. color: #6f8179;
  1028. }
  1029. .cart-total-money {
  1030. font-size: 32rpx;
  1031. font-weight: 700;
  1032. letter-spacing: 0.4rpx;
  1033. color: #1f2a26;
  1034. }
  1035. .cart-settle {
  1036. flex-shrink: 0;
  1037. min-height: 72rpx;
  1038. padding: 0 32rpx;
  1039. border-radius: 28rpx;
  1040. background: linear-gradient(145deg, var(--c-barley-yellow), #e4b458);
  1041. color: #fff;
  1042. display: inline-flex;
  1043. align-items: center;
  1044. justify-content: center;
  1045. font-size: 28rpx;
  1046. font-weight: 700;
  1047. box-shadow: inset 0 -2rpx 0 rgba(0, 0, 0, 0.1);
  1048. text {
  1049. color: #fff;
  1050. }
  1051. }
  1052. </style>