mall-detail.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <template>
  2. <view class="detail-container">
  3. <!-- 商品轮播图 -->
  4. <view class="swiper-container">
  5. <swiper class="goods-swiper" :indicator-dots="true" :autoplay="true" :circular="true">
  6. <swiper-item v-for="(image, index) in goodsImages" :key="index">
  7. <image class="swiper-image" :src=image.url mode="aspectFill"></image>
  8. </swiper-item>
  9. </swiper>
  10. </view>
  11. <!-- 商品基本信息 -->
  12. <view class="goods-basic-info">
  13. <view class="goods-title">{{ goodsDetail.title }}</view>
  14. <view class="goods-subtitle">{{ goodsDetail.description }}</view>
  15. <view class="price-container">
  16. <text class="current-price">¥{{ goodsDetail.price }}</text>
  17. <text class="price-unit">{{ goodsDetail.unit }}</text>
  18. <text class="original-price" v-if="goodsDetail.originalPrice">¥{{ goodsDetail.originalPrice }}</text>
  19. </view>
  20. <view class="specs-info">
  21. <text class="specs-label">规格:</text>
  22. <text class="specs-value">{{ goodsDetail.specifications }}</text>
  23. </view>
  24. </view>
  25. <!-- 商品详情介绍 -->
  26. <view class="goods-detail-info">
  27. <view class="detail-title">商品详情</view>
  28. <!-- 产品特点 -->
  29. <view class="detail-section">
  30. <view class="section-title">产品特点</view>
  31. <view class="feature-list">
  32. <view
  33. class="feature-item"
  34. v-for="(feature, index) in goodsDetail.features"
  35. :key="index"
  36. >
  37. <view class="feature-icon">✓</view>
  38. <text class="feature-text">{{ feature }}</text>
  39. </view>
  40. </view>
  41. </view>
  42. <!-- 使用说明 -->
  43. <view class="detail-section">
  44. <view class="section-title">使用说明</view>
  45. <view class="usage-content">
  46. <text>{{ goodsDetail.usageGuide }}</text>
  47. </view>
  48. </view>
  49. <!-- 产品图片展示 -->
  50. <view class="detail-section">
  51. <view class="section-title">产品展示</view>
  52. <view class="detail-images">
  53. <image
  54. class="detail-image"
  55. v-for="(item, index) in goodsDetail.detailImages"
  56. :key="index"
  57. :src="item.url"
  58. mode="widthFix"
  59. @click="previewImage(item, index)"
  60. ></image>
  61. </view>
  62. </view>
  63. </view>
  64. <!-- 底部操作栏 -->
  65. <view class="bottom-actions">
  66. <view class="action-btn consult-btn" @click="handleConsult">
  67. 立即咨询
  68. </view>
  69. </view>
  70. </view>
  71. </template>
  72. <script setup>
  73. import { ref, onMounted } from 'vue'
  74. import { getMallById } from '@/api/services/mall.js'
  75. const goodsId = ref('')
  76. const goodsDetail = ref({})
  77. const goodsImages = ref([])
  78. // 页面加载
  79. onMounted(() => {
  80. const pages = getCurrentPages()
  81. const currentPage = pages[pages.length - 1]
  82. const options = currentPage.options
  83. if (options.id) {
  84. goodsId.value = options.id
  85. loadGoodsDetail(goodsId.value)
  86. }
  87. if (options.title) {
  88. uni.setNavigationBarTitle({
  89. title: decodeURIComponent(options.title)
  90. })
  91. }
  92. })
  93. // 加载商品详情
  94. const loadGoodsDetail = (id) => {
  95. uni.showLoading({
  96. title: '加载中'
  97. })
  98. getMallById(id).then(res => {
  99. if (res.data.code === 200) {
  100. const { data } = res.data
  101. goodsDetail.value = data
  102. // 处理图片数据
  103. if (goodsDetail.value.detailImages && goodsDetail.value.swiperImages) {
  104. try {
  105. // 尝试解析图片数据字符串
  106. const imageUrls = goodsDetail.value.detailImages.split(',')
  107. const swiperImages = goodsDetail.value.swiperImages.split(',')
  108. goodsDetail.value.detailImages = imageUrls.filter(url => url && url.trim()).map(url => ({
  109. url: url.trim(),
  110. status: 'success'
  111. }))
  112. goodsImages.value = swiperImages.filter(url => url && url.trim()).map(url => ({
  113. url: url.trim(),
  114. status: 'success'
  115. }))
  116. } catch (e) {
  117. console.error('解析图片数据失败:', e)
  118. goodsDetail.value.detailImages = []
  119. goodsImages.value = []
  120. }
  121. } else {
  122. goodsDetail.value.detailImages = []
  123. goodsImages.value = []
  124. }
  125. uni.hideLoading()
  126. } else {
  127. uni.showToast({
  128. title: res.data.msg || '获取商品信息失败',
  129. icon: 'none'
  130. })
  131. }
  132. })
  133. }
  134. // 预览图片
  135. const previewImage = (image, index) => {
  136. const urls = goodsDetail.value.detailImages.map(item => item.url)
  137. uni.previewImage({
  138. urls: urls,
  139. current: index
  140. })
  141. }
  142. // 立即咨询
  143. const handleConsult = () => {
  144. uni.showModal({
  145. title: '咨询服务',
  146. content: '您可以通过以下方式联系我们:\n1. 拨打客服热线:400-888-8888\n2. 在线客服(工作时间:9:00-18:00)',
  147. confirmText: '拨打电话',
  148. cancelText: '取消',
  149. success: (res) => {
  150. if (res.confirm) {
  151. uni.makePhoneCall({
  152. phoneNumber: '400-888-8888'
  153. })
  154. }
  155. }
  156. })
  157. }
  158. </script>
  159. <style lang="scss">
  160. .detail-container {
  161. min-height: 100vh;
  162. background-color: #f5f5f5;
  163. padding-bottom: 120rpx; // 为底部操作栏留出空间
  164. }
  165. .swiper-container {
  166. width: 100%;
  167. height: 600rpx;
  168. background-color: #fff;
  169. }
  170. .goods-swiper {
  171. width: 100%;
  172. height: 100%;
  173. }
  174. .swiper-image {
  175. width: 100%;
  176. height: 100%;
  177. }
  178. .goods-basic-info {
  179. background-color: #fff;
  180. padding: 30rpx;
  181. margin-bottom: 20rpx;
  182. }
  183. .goods-title {
  184. font-size: 36rpx;
  185. font-weight: bold;
  186. color: #333;
  187. line-height: 1.4;
  188. margin-bottom: 16rpx;
  189. }
  190. .goods-subtitle {
  191. font-size: 28rpx;
  192. color: #666;
  193. line-height: 1.5;
  194. margin-bottom: 24rpx;
  195. }
  196. .price-container {
  197. display: flex;
  198. align-items: baseline;
  199. margin-bottom: 24rpx;
  200. }
  201. .current-price {
  202. font-size: 40rpx;
  203. font-weight: bold;
  204. color: #4CAF50;
  205. }
  206. .price-unit {
  207. font-size: 28rpx;
  208. color: #999;
  209. margin-left: 8rpx;
  210. margin-right: 16rpx;
  211. }
  212. .original-price {
  213. font-size: 28rpx;
  214. color: #999;
  215. text-decoration: line-through;
  216. }
  217. .specs-info {
  218. display: flex;
  219. align-items: center;
  220. }
  221. .specs-label {
  222. font-size: 28rpx;
  223. color: #666;
  224. }
  225. .specs-value {
  226. font-size: 28rpx;
  227. color: #333;
  228. }
  229. .goods-detail-info {
  230. background-color: #fff;
  231. padding: 30rpx;
  232. }
  233. .detail-title {
  234. font-size: 32rpx;
  235. font-weight: bold;
  236. color: #333;
  237. margin-bottom: 30rpx;
  238. text-align: center;
  239. }
  240. .detail-section {
  241. margin-bottom: 40rpx;
  242. &:last-child {
  243. margin-bottom: 0;
  244. }
  245. }
  246. .section-title {
  247. font-size: 30rpx;
  248. font-weight: bold;
  249. color: #333;
  250. margin-bottom: 20rpx;
  251. padding-left: 20rpx;
  252. position: relative;
  253. &::before {
  254. content: '';
  255. position: absolute;
  256. left: 0;
  257. top: 50%;
  258. transform: translateY(-50%);
  259. width: 8rpx;
  260. height: 32rpx;
  261. background-color: #4CAF50;
  262. border-radius: 4rpx;
  263. }
  264. }
  265. .feature-list {
  266. .feature-item {
  267. display: flex;
  268. align-items: center;
  269. margin-bottom: 16rpx;
  270. .feature-icon {
  271. width: 32rpx;
  272. height: 32rpx;
  273. background-color: #4CAF50;
  274. color: #fff;
  275. border-radius: 50%;
  276. display: flex;
  277. align-items: center;
  278. justify-content: center;
  279. font-size: 20rpx;
  280. font-weight: bold;
  281. margin-right: 16rpx;
  282. flex-shrink: 0;
  283. }
  284. .feature-text {
  285. font-size: 28rpx;
  286. color: #666;
  287. line-height: 1.5;
  288. }
  289. }
  290. }
  291. .usage-content {
  292. font-size: 28rpx;
  293. color: #666;
  294. line-height: 1.6;
  295. padding: 20rpx;
  296. background-color: #f8f8f8;
  297. border-radius: 12rpx;
  298. }
  299. .detail-images {
  300. display: flex;
  301. flex-direction: column;
  302. gap: 20rpx;
  303. }
  304. .detail-image {
  305. width: 100%;
  306. border-radius: 12rpx;
  307. }
  308. .bottom-actions {
  309. position: fixed;
  310. bottom: 0;
  311. left: 0;
  312. right: 0;
  313. background-color: #fff;
  314. padding: 20rpx 30rpx;
  315. border-top: 1rpx solid #f0f0f0;
  316. z-index: 1000;
  317. }
  318. .action-btn {
  319. text-align: center;
  320. padding: 24rpx 0;
  321. border-radius: 12rpx;
  322. font-size: 32rpx;
  323. font-weight: bold;
  324. }
  325. .consult-btn {
  326. background-color: #4CAF50;
  327. color: #fff;
  328. }
  329. </style>