index.vue 8.8 KB

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