mall-detail.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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>
  73. import { getMallById } from '@/api/services/mall.js';
  74. import api from "@/config/api.js";
  75. export default {
  76. data() {
  77. return {
  78. goodsId: '',
  79. goodsDetail: {
  80. // title: '高产玉米种子',
  81. // description: '优质杂交种,抗病性强,适应性广',
  82. // price: '68',
  83. // originalPrice: '88',
  84. // unit: '袋',
  85. // specifications: '500g/袋,发芽率≥95%',
  86. // features: [
  87. // '高产稳产,比普通品种增产15-20%',
  88. // '抗病性强,抗大小斑病、丝黑穗病',
  89. // '适应性广,适合多种土壤和气候条件',
  90. // '株型紧凑,抗倒伏能力强',
  91. // '籽粒饱满,商品性好'
  92. // ],
  93. // usage: '播种前先进行种子处理,选择肥沃、排水良好的土壤,按照每亩3-4千粒的密度播种。播种深度2-3厘米,播种后及时覆土镇压。生长期注意水肥管理,适时中耕除草。',
  94. // detailImages: [
  95. // '/static/images/products/corn-seeds-new.jpg',
  96. // '/static/images/products/seeds-packets.jpg',
  97. // '/static/images/products/agriculture-tools.jpg'
  98. // ]
  99. },
  100. goodsImages: []
  101. }
  102. },
  103. onLoad(options) {
  104. if (options.id) {
  105. this.goodsId = options.id;
  106. this.loadGoodsDetail(this.goodsId);
  107. }
  108. if (options.title) {
  109. uni.setNavigationBarTitle({
  110. title: decodeURIComponent(options.title)
  111. });
  112. }
  113. },
  114. methods: {
  115. // getImageUrl(item) {
  116. // // 默认返回url或path
  117. // console.log("imageUrls",item);
  118. // if(item == null) return
  119. // // const imageUrls = item.split(',');
  120. // return imageUrls;
  121. // },
  122. // 加载商品详情
  123. loadGoodsDetail(goodsId) {
  124. uni.showLoading({
  125. title: '加载中'
  126. });
  127. getMallById(goodsId).then(res=>{
  128. if (res.data.code === 200) {
  129. const { data } = res.data;
  130. this.goodsDetail = data
  131. console.log("this.goodsDetail", this.goodsDetail);
  132. // 处理图片数据
  133. if (this.goodsDetail.detailImages && this.goodsDetail.swiperImages) {
  134. try {
  135. this.goodsImages = data.swiperImages
  136. // 尝试解析图片数据字符串
  137. const imageUrls = this.goodsDetail.detailImages.split(',');
  138. const swiperImages = this.goodsImages.split(',');
  139. this.goodsDetail.detailImages = imageUrls.filter(url => url && url.trim()).map(url => ({
  140. url: url.trim(), // 保存原始URL,显示时会通过getImageUrl方法处理
  141. status: 'success'
  142. }));
  143. this.goodsImages = swiperImages.filter(url => url && url.trim()).map(url => ({
  144. url: url.trim(), // 保存原始URL,显示时会通过getImageUrl方法处理
  145. status: 'success'
  146. }));
  147. console.log('解析后的图片数据:', this.goodsDetail.detailImages);
  148. } catch (e) {
  149. console.error('解析图片数据失败:', e);
  150. this.goodsDetail.detailImages = [];
  151. this.goodsDetail.swiperImages = [];
  152. }
  153. } else {
  154. this.goodsDetail.detailImages = [];
  155. this.goodsDetail.swiperImages = [];
  156. }
  157. uni.hideLoading();
  158. } else {
  159. uni.showToast({
  160. title: res.data.msg || '获取商品信息失败',
  161. icon: 'none'
  162. });
  163. }
  164. })
  165. // 这里可以根据goodsId从后端获取商品详情
  166. // 目前使用模拟数据
  167. // const goodsData = {
  168. // 1: {
  169. // title: '高产玉米种子',
  170. // description: '优质杂交种,抗病性强,适应性广',
  171. // price: '68',
  172. // originalPrice: '88',
  173. // unit: '袋',
  174. // specifications: '500g/袋,发芽率≥95%',
  175. // features: [
  176. // '高产稳产,比普通品种增产15-20%',
  177. // '抗病性强,抗大小斑病、丝黑穗病',
  178. // '适应性广,适合多种土壤和气候条件',
  179. // '株型紧凑,抗倒伏能力强',
  180. // '籽粒饱满,商品性好'
  181. // ],
  182. // usage: '播种前先进行种子处理,选择肥沃、排水良好的土壤,按照每亩3-4千粒的密度播种。播种深度2-3厘米,播种后及时覆土镇压。生长期注意水肥管理,适时中耕除草。',
  183. // detailImages: [
  184. // '/static/images/products/corn-seeds-new.jpg',
  185. // '/static/images/products/seeds-packets.jpg',
  186. // '/static/images/products/agriculture-tools.jpg'
  187. // ]
  188. // }
  189. // };
  190. // if (goodsData[this.goodsId]) {
  191. // this.goodsDetail = goodsData[this.goodsId];
  192. // // 根据商品类型设置轮播图
  193. // this.setGoodsImages(this.goodsId);
  194. // }
  195. },
  196. // 设置商品轮播图
  197. setGoodsImages(goodsId) {
  198. const imageMap = {
  199. '1': [ // 玉米种子
  200. '/static/images/products/corn-seeds-new.jpg',
  201. '/static/images/products/seeds-packets.jpg',
  202. '/static/images/products/agriculture-tools.jpg',
  203. '/static/images/products/wheat-seeds.jpg'
  204. ],
  205. '2': [ // 复合肥料
  206. '/static/images/products/fertilizer.jpg',
  207. '/static/images/products/organic-fertilizer-new.jpg',
  208. '/static/images/products/soil-test.jpg',
  209. '/static/images/products/greenhouse-film.jpg'
  210. ],
  211. '3': [ // 植物保护剂
  212. '/static/images/products/plant-protection.jpg',
  213. '/static/images/products/agriculture-tools.jpg',
  214. '/static/images/products/pesticide.jpg',
  215. '/static/images/products/insecticide.jpg'
  216. ],
  217. '4': [ // 水稻种子
  218. '/static/images/products/seeds-packets.jpg',
  219. '/static/images/products/rice-seeds.jpg',
  220. '/static/images/products/corn-seeds-new.jpg',
  221. '/static/images/products/wheat-seeds.jpg'
  222. ]
  223. };
  224. if (imageMap[goodsId]) {
  225. this.goodsImages = imageMap[goodsId];
  226. }
  227. },
  228. // 预览图片
  229. previewImage(image, index) {
  230. const urls = this.formData.images.map(item => item.url);
  231. uni.previewImage({
  232. urls: urls,
  233. current: index
  234. });
  235. },
  236. // 立即咨询
  237. handleConsult() {
  238. uni.showModal({
  239. title: '咨询服务',
  240. content: '您可以通过以下方式联系我们:\n1. 拨打客服热线:400-xxx-xxxx\n2. 在线客服(工作时间:9:00-18:00)',
  241. confirmText: '拨打电话',
  242. cancelText: '取消',
  243. success: (res) => {
  244. if (res.confirm) {
  245. uni.makePhoneCall({
  246. phoneNumber: '400-xxx-xxxx'
  247. });
  248. }
  249. }
  250. });
  251. }
  252. }
  253. }
  254. </script>
  255. <style lang="scss">
  256. .detail-container {
  257. min-height: 100vh;
  258. background-color: #f5f5f5;
  259. padding-bottom: 120rpx; // 为底部操作栏留出空间
  260. }
  261. .swiper-container {
  262. width: 100%;
  263. height: 600rpx;
  264. background-color: #fff;
  265. }
  266. .goods-swiper {
  267. width: 100%;
  268. height: 100%;
  269. }
  270. .swiper-image {
  271. width: 100%;
  272. height: 100%;
  273. }
  274. .goods-basic-info {
  275. background-color: #fff;
  276. padding: 30rpx;
  277. margin-bottom: 20rpx;
  278. }
  279. .goods-title {
  280. font-size: 36rpx;
  281. font-weight: bold;
  282. color: #333;
  283. line-height: 1.4;
  284. margin-bottom: 16rpx;
  285. }
  286. .goods-subtitle {
  287. font-size: 28rpx;
  288. color: #666;
  289. line-height: 1.5;
  290. margin-bottom: 24rpx;
  291. }
  292. .price-container {
  293. display: flex;
  294. align-items: baseline;
  295. margin-bottom: 24rpx;
  296. }
  297. .current-price {
  298. font-size: 40rpx;
  299. font-weight: bold;
  300. color: #4CAF50;
  301. }
  302. .price-unit {
  303. font-size: 28rpx;
  304. color: #999;
  305. margin-left: 8rpx;
  306. margin-right: 16rpx;
  307. }
  308. .original-price {
  309. font-size: 28rpx;
  310. color: #999;
  311. text-decoration: line-through;
  312. }
  313. .specs-info {
  314. display: flex;
  315. align-items: center;
  316. }
  317. .specs-label {
  318. font-size: 28rpx;
  319. color: #666;
  320. }
  321. .specs-value {
  322. font-size: 28rpx;
  323. color: #333;
  324. }
  325. .goods-detail-info {
  326. background-color: #fff;
  327. padding: 30rpx;
  328. }
  329. .detail-title {
  330. font-size: 32rpx;
  331. font-weight: bold;
  332. color: #333;
  333. margin-bottom: 30rpx;
  334. text-align: center;
  335. }
  336. .detail-section {
  337. margin-bottom: 40rpx;
  338. &:last-child {
  339. margin-bottom: 0;
  340. }
  341. }
  342. .section-title {
  343. font-size: 30rpx;
  344. font-weight: bold;
  345. color: #333;
  346. margin-bottom: 20rpx;
  347. padding-left: 20rpx;
  348. position: relative;
  349. &::before {
  350. content: '';
  351. position: absolute;
  352. left: 0;
  353. top: 50%;
  354. transform: translateY(-50%);
  355. width: 8rpx;
  356. height: 32rpx;
  357. background-color: #4CAF50;
  358. border-radius: 4rpx;
  359. }
  360. }
  361. .feature-list {
  362. .feature-item {
  363. display: flex;
  364. align-items: center;
  365. margin-bottom: 16rpx;
  366. .feature-icon {
  367. width: 32rpx;
  368. height: 32rpx;
  369. background-color: #4CAF50;
  370. color: #fff;
  371. border-radius: 50%;
  372. display: flex;
  373. align-items: center;
  374. justify-content: center;
  375. font-size: 20rpx;
  376. font-weight: bold;
  377. margin-right: 16rpx;
  378. flex-shrink: 0;
  379. }
  380. .feature-text {
  381. font-size: 28rpx;
  382. color: #666;
  383. line-height: 1.5;
  384. }
  385. }
  386. }
  387. .usage-content {
  388. font-size: 28rpx;
  389. color: #666;
  390. line-height: 1.6;
  391. padding: 20rpx;
  392. background-color: #f8f8f8;
  393. border-radius: 12rpx;
  394. }
  395. .detail-images {
  396. display: flex;
  397. flex-direction: column;
  398. gap: 20rpx;
  399. }
  400. .detail-image {
  401. width: 100%;
  402. border-radius: 12rpx;
  403. }
  404. .bottom-actions {
  405. position: fixed;
  406. bottom: 0;
  407. left: 0;
  408. right: 0;
  409. background-color: #fff;
  410. padding: 20rpx 30rpx;
  411. border-top: 1rpx solid #f0f0f0;
  412. z-index: 1000;
  413. }
  414. .action-btn {
  415. text-align: center;
  416. padding: 24rpx 0;
  417. border-radius: 12rpx;
  418. font-size: 32rpx;
  419. font-weight: bold;
  420. }
  421. .consult-btn {
  422. background-color: #4CAF50;
  423. color: #fff;
  424. }
  425. </style>