index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. <template>
  2. <view class="service-detail-page">
  3. <nav-bar title="服务详情"></nav-bar>
  4. <!-- 顶部主图区域 -->
  5. <view class="hero-section">
  6. <image :src="serviceData.heroImg" class="hero-img" mode="aspectFill"></image>
  7. <view class="hero-overlay"></view>
  8. <view class="hero-title-box">
  9. <text class="hero-main-title">{{ serviceData.heroTitle }}</text>
  10. <text class="hero-sub-title">{{ serviceData.heroSubTitle }}</text>
  11. </view>
  12. </view>
  13. <!-- 购买数据 -->
  14. <view class="info-section card">
  15. <view class="service-price-row">
  16. <view class="price-box">
  17. <text class="price-label">订单服务费:</text>
  18. <text class="price-symbol">¥</text>
  19. <text class="price-num">{{ serviceData.price }}</text>
  20. <text class="price-unit">{{ serviceData.unit }}</text>
  21. <text class="price-suffix">起</text>
  22. </view>
  23. </view>
  24. <text class="service-name-text">{{ serviceData.title }}</text>
  25. </view>
  26. <!-- 详情选项卡 -->
  27. <view class="tab-section card">
  28. <view class="tab-header">
  29. <view :class="['tab-btn', { active: activeTab === 'intro' }]" @click="activeTab = 'intro'">
  30. <text>服务介绍</text>
  31. </view>
  32. <view :class="['tab-btn', { active: activeTab === 'notice' }]" @click="activeTab = 'notice'">
  33. <text>下单须知</text>
  34. </view>
  35. </view>
  36. <view class="tab-content" v-if="activeTab === 'intro'">
  37. <text class="content-title">服务介绍</text>
  38. <view class="rich-container">
  39. <rich-text :nodes="processedIntro" class="content-text"></rich-text>
  40. </view>
  41. <view class="intro-images" v-if="serviceData.introImages && serviceData.introImages.length">
  42. <image v-for="(img, idx) in serviceData.introImages" :key="idx" :src="img" class="intro-img"
  43. mode="widthFix"></image>
  44. </view>
  45. </view>
  46. <view class="tab-content" v-if="activeTab === 'notice'">
  47. <text class="content-title">下单须知</text>
  48. <view class="rich-container">
  49. <rich-text :nodes="processedNotice" class="content-text"></rich-text>
  50. </view>
  51. </view>
  52. </view>
  53. <!-- 底部操作栏 -->
  54. <view class="footer-bar safe-bottom" v-if="canBuy">
  55. <button class="buy-btn" @click="goToOrderApply">立即预约</button>
  56. </view>
  57. </view>
  58. </template>
  59. <script setup>
  60. import { ref, computed } from 'vue'
  61. import navBar from '@/components/nav-bar/index.vue'
  62. import { onLoad } from '@dcloudio/uni-app'
  63. const activeTab = ref('intro')
  64. const serviceInfo = ref(null)
  65. const canBuy = ref(true)
  66. const defaultHeroImg = 'https://images.unsplash.com/photo-1544568100-847a948585b9?q=80&w=600&auto=format&fit=crop'
  67. onLoad((options) => {
  68. if (options.buyFlag === 'false') {
  69. canBuy.value = false
  70. }
  71. const storedService = uni.getStorageSync('currentService')
  72. if (storedService) {
  73. serviceInfo.value = storedService
  74. console.log('获取到的服务数据:', storedService)
  75. }
  76. })
  77. const serviceData = computed(() => {
  78. if (!serviceInfo.value) {
  79. return {
  80. heroImg: defaultHeroImg,
  81. heroTitle: '服务详情',
  82. heroSubTitle: '加载中...',
  83. price: '0',
  84. unit: '',
  85. booked: '0 人已约',
  86. title: '服务名称',
  87. intro: '加载中...',
  88. notice: '加载中...',
  89. introImages: []
  90. }
  91. }
  92. const service = serviceInfo.value
  93. const priceInYuan = service.price ? (service.price / 100).toFixed(2) : '0.00'
  94. return {
  95. type: service.id,
  96. title: service.name,
  97. heroTitle: service.name,
  98. heroSubTitle: service.remark || '专业服务',
  99. heroImg: service.iconUrl || defaultHeroImg,
  100. price: priceInYuan,
  101. unit: '',
  102. booked: '0 人已约',
  103. intro: service.introduction || '暂无介绍',
  104. introImages: [],
  105. notice: service.orderInstruction || '暂无须知'
  106. }
  107. })
  108. /**
  109. * 富文本预处理:限制图片宽度、移除溢出样式,兼容H5富文本
  110. */
  111. const processRichText = (html) => {
  112. if (!html) return ''
  113. let processed = html
  114. // 1. 给 img 标签强制添加 max-width:100% + height:auto
  115. processed = processed.replace(/<img([^>]*)>/gi, (match, attrs) => {
  116. let cleanAttrs = attrs
  117. .replace(/\s*width\s*=\s*["'][^"']*["']/gi, '')
  118. .replace(/\s*height\s*=\s*["'][^"']*["']/gi, '')
  119. .replace(/\s*style\s*=\s*["'][^"']*["']/gi, '')
  120. return `<img${cleanAttrs} style="max-width: 100%; height: auto; display: block;">`
  121. })
  122. // 2. 处理 table/pre/code 等可能溢出的块级元素
  123. processed = processed.replace(
  124. /<(table|pre|code)([^>]*)>/gi,
  125. (match, tag, attrs) => `<${tag}${attrs} style="max-width: 100%; overflow-x: auto; word-break: break-word;">`
  126. )
  127. return processed
  128. }
  129. const processedIntro = computed(() => processRichText(serviceData.value.intro))
  130. const processedNotice = computed(() => processRichText(serviceData.value.notice))
  131. const goToOrderApply = () => {
  132. // @Author: Antigravity
  133. if (!serviceInfo.value) return;
  134. // 根据服务的模式(mode为1代表接送)或名称关键字判断跳转类型,以匹配下单页的分类逻辑
  135. let serviceType = 'feed';
  136. const name = serviceInfo.value.name || '';
  137. const mode = String(serviceInfo.value.mode);
  138. if (mode === '1' || name.includes('接送') || name.includes('托运')) {
  139. serviceType = 'transport';
  140. } else if (name.includes('洗') || name.includes('护')) {
  141. serviceType = 'wash';
  142. }
  143. uni.navigateTo({
  144. url: `/pages/order/apply/index?service=${serviceType}&serviceId=${serviceInfo.value.id}`
  145. })
  146. }
  147. </script>
  148. <style lang="scss" scoped>
  149. .service-detail-page {
  150. background-color: #f5f5f5;
  151. min-height: 100vh;
  152. padding-bottom: 40rpx;
  153. }
  154. .hero-section {
  155. position: relative;
  156. width: 100%;
  157. height: 640rpx;
  158. overflow: hidden;
  159. }
  160. .hero-img {
  161. width: 100%;
  162. height: 100%;
  163. }
  164. .hero-overlay {
  165. position: absolute;
  166. top: 0;
  167. left: 0;
  168. right: 0;
  169. bottom: 0;
  170. background: linear-gradient(to bottom, rgba(0, 0, 0, 0.3) 0%, rgba(0, 0, 0, 0) 40%, rgba(0, 0, 0, 0.4) 80%, rgba(0, 0, 0, 0.7) 100%);
  171. }
  172. .hero-title-box {
  173. position: absolute;
  174. bottom: 48rpx;
  175. left: 40rpx;
  176. right: 40rpx;
  177. z-index: 2;
  178. }
  179. .hero-main-title {
  180. display: block;
  181. font-size: 52rpx;
  182. font-weight: 900;
  183. color: #fff;
  184. margin-bottom: 12rpx;
  185. }
  186. .hero-sub-title {
  187. display: block;
  188. font-size: 28rpx;
  189. color: rgba(255, 255, 255, 0.9);
  190. font-weight: 600;
  191. }
  192. .card {
  193. background-color: #fff;
  194. margin-bottom: 20rpx;
  195. }
  196. .info-section {
  197. padding: 32rpx 40rpx;
  198. position: relative;
  199. z-index: 3;
  200. border-radius: 24rpx 24rpx 0 0;
  201. margin-top: -24rpx;
  202. }
  203. .service-price-row {
  204. display: flex;
  205. justify-content: space-between;
  206. align-items: flex-end;
  207. margin-bottom: 20rpx;
  208. }
  209. .price-box {
  210. display: flex;
  211. align-items: baseline;
  212. color: #f44336;
  213. }
  214. .price-label {
  215. font-size: 26rpx;
  216. color: #333;
  217. font-weight: bold;
  218. margin-right: 12rpx;
  219. }
  220. .price-symbol {
  221. font-size: 28rpx;
  222. font-weight: bold;
  223. }
  224. .price-num {
  225. font-size: 56rpx;
  226. font-weight: 900;
  227. line-height: 1;
  228. }
  229. .price-unit {
  230. font-size: 24rpx;
  231. color: #999;
  232. margin-left: 4rpx;
  233. }
  234. .price-suffix {
  235. font-size: 24rpx;
  236. color: #999;
  237. margin-left: 2rpx;
  238. }
  239. .bought-count {
  240. font-size: 24rpx;
  241. color: #999;
  242. background: #f5f5f5;
  243. padding: 4rpx 16rpx;
  244. border-radius: 20rpx;
  245. }
  246. .service-name-text {
  247. font-size: 32rpx;
  248. color: #111;
  249. font-weight: bold;
  250. }
  251. .tab-section {
  252. padding: 0;
  253. }
  254. .tab-header {
  255. display: flex;
  256. border-bottom: 2rpx solid #EEEEEE;
  257. }
  258. .tab-btn {
  259. flex: 1;
  260. text-align: center;
  261. padding: 24rpx 0;
  262. font-size: 28rpx;
  263. color: #666;
  264. position: relative;
  265. }
  266. .tab-btn.active {
  267. color: #fcd53f;
  268. font-weight: bold;
  269. }
  270. .tab-btn.active::after {
  271. content: '';
  272. position: absolute;
  273. bottom: 0;
  274. left: 50%;
  275. transform: translateX(-50%);
  276. width: 60rpx;
  277. height: 6rpx;
  278. background: #fcd53f;
  279. border-radius: 6rpx;
  280. }
  281. .tab-content {
  282. padding: 40rpx 32rpx;
  283. }
  284. .content-title {
  285. display: block;
  286. font-size: 32rpx;
  287. color: #333;
  288. font-weight: 900;
  289. margin-bottom: 24rpx;
  290. padding-left: 20rpx;
  291. position: relative;
  292. }
  293. .content-title::before {
  294. content: '';
  295. position: absolute;
  296. left: 0;
  297. top: 4rpx;
  298. bottom: 4rpx;
  299. width: 8rpx;
  300. background: #fcd53f;
  301. border-radius: 4rpx;
  302. }
  303. .rich-container {
  304. overflow: hidden;
  305. word-break: break-word;
  306. line-height: 1.8;
  307. }
  308. .content-text {
  309. font-size: 28rpx;
  310. color: #555;
  311. line-height: 1.8;
  312. }
  313. .intro-images {
  314. margin-top: 32rpx;
  315. display: flex;
  316. flex-direction: column;
  317. gap: 24rpx;
  318. }
  319. .intro-img {
  320. width: 100%;
  321. border-radius: 20rpx;
  322. }
  323. .footer-bar {
  324. position: fixed;
  325. bottom: 0;
  326. left: 0;
  327. right: 0;
  328. padding: 20rpx 32rpx 40rpx;
  329. background-color: #fff;
  330. z-index: 10;
  331. box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.05);
  332. }
  333. .buy-btn {
  334. width: 100%;
  335. height: 92rpx;
  336. font-size: 32rpx;
  337. font-weight: bold;
  338. color: #fff;
  339. background: linear-gradient(90deg, #ffd53f, #ff9500);
  340. border: none;
  341. border-radius: 46rpx;
  342. line-height: 92rpx;
  343. }
  344. </style>
  345. <!-- 非 scoped 样式:rich-text 内部元素需要穿透生效 -->
  346. <style lang="scss">
  347. .rich-container img {
  348. max-width: 100% !important;
  349. height: auto !important;
  350. display: block;
  351. }
  352. .rich-container table,
  353. .rich-container pre,
  354. .rich-container code {
  355. max-width: 100% !important;
  356. overflow-x: auto;
  357. word-break: break-word;
  358. }
  359. .rich-container p {
  360. margin-bottom: 12px;
  361. }
  362. .rich-container h1,
  363. .rich-container h2,
  364. .rich-container h3,
  365. .rich-container h4,
  366. .rich-container h5,
  367. .rich-container h6 {
  368. margin-top: 16px;
  369. margin-bottom: 8px;
  370. line-height: 1.4;
  371. }
  372. </style>