1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
| <template> <div class="seckill-detail" v-if="product"> <el-container> <el-main> <el-row :gutter="30"> <!-- 商品图片 --> <el-col :span="12"> <div class="product-gallery"> <div class="main-image"> <img :src="currentImage" :alt="product.name"> </div> <div class="thumbnail-list"> <div v-for="(image, index) in product.images" :key="index" class="thumbnail-item" :class="{ active: currentImage === image }" @click="currentImage = image" > <img :src="image" :alt="product.name"> </div> </div> </div> </el-col> <!-- 商品信息 --> <el-col :span="12"> <div class="product-detail"> <div class="seckill-status"> <el-tag type="danger" size="large"> <i class="el-icon-time"></i> 限时秒杀 </el-tag> <div class="countdown"> 距离结束: <span class="time">{{ countdown.hours }}</span>: <span class="time">{{ countdown.minutes }}</span>: <span class="time">{{ countdown.seconds }}</span> </div> </div> <h1 class="product-title">{{ product.name }}</h1> <p class="product-subtitle">{{ product.subtitle }}</p> <div class="price-info"> <div class="seckill-price"> <span class="label">秒杀价:</span> <span class="price">¥{{ product.seckillPrice }}</span> </div> <div class="original-price"> <span class="label">原价:</span> <span class="price">¥{{ product.originalPrice }}</span> </div> <div class="discount"> 省 ¥{{ (product.originalPrice - product.seckillPrice).toFixed(2) }} </div> </div> <div class="stock-info"> <div class="stock-progress"> <div class="stock-text"> <span>仅剩 {{ product.stock }} 件</span> <span>已抢 {{ product.soldCount }} 件</span> </div> <el-progress :percentage="salePercentage" :stroke-width="12" color="#ff6b35" ></el-progress> </div> </div> <div class="spec-selection"> <div class="spec-item"> <span class="spec-label">规格:</span> <el-radio-group v-model="selectedSpec"> <el-radio-button v-for="spec in product.specs" :key="spec.id" :label="spec.id" > {{ spec.name }} </el-radio-button> </el-radio-group> </div> <div class="quantity-item"> <span class="spec-label">数量:</span> <el-input-number v-model="quantity" :min="1" :max="Math.min(5, product.stock)" size="small" ></el-input-number> <span class="limit-text">限购5件</span> </div> </div> <div class="action-buttons"> <el-button type="danger" size="large" :disabled="!canBuy" :loading="buying" @click="handleSeckill" > <i class="el-icon-lightning"></i> 立即秒杀 </el-button> <el-button type="primary" size="large" :disabled="!canBuy" @click="addToCart" > <i class="el-icon-shopping-cart-2"></i> 加入购物车 </el-button> </div> <div class="service-info"> <el-row> <el-col :span="8"> <i class="el-icon-truck"></i> 包邮 </el-col> <el-col :span="8"> <i class="el-icon-refresh"></i> 7天无理由退货 </el-col> <el-col :span="8"> <i class="el-icon-medal"></i> 正品保证 </el-col> </el-row> </div> </div> </el-col> </el-row> <!-- 商品详情 --> <div class="product-description"> <el-tabs v-model="activeTab"> <el-tab-pane label="商品详情" name="detail"> <div v-html="product.description"></div> </el-tab-pane> <el-tab-pane label="规格参数" name="specs"> <el-table :data="product.parameters" border> <el-table-column prop="name" label="参数名称"></el-table-column> <el-table-column prop="value" label="参数值"></el-table-column> </el-table> </el-tab-pane> <el-tab-pane label="用户评价" name="reviews"> <div class="reviews-section"> <div v-for="review in product.reviews" :key="review.id" class="review-item"> <div class="review-user"> <el-avatar :src="review.userAvatar" size="small"></el-avatar> <span>{{ review.username }}</span> <el-rate v-model="review.rating" disabled show-score></el-rate> </div> <p class="review-content">{{ review.content }}</p> <div class="review-images" v-if="review.images"> <img v-for="img in review.images" :key="img" :src="img" alt="评价图片"> </div> </div> </div> </el-tab-pane> </el-tabs> </div> </el-main> </el-container> <!-- 秒杀成功对话框 --> <el-dialog title="秒杀成功!" :visible.sync="successDialogVisible" width="400px" center > <div class="success-content"> <i class="el-icon-success" style="font-size: 60px; color: #67C23A;"></i> <p>恭喜您成功抢到商品!</p> <p>请在15分钟内完成支付</p> </div> <span slot="footer" class="dialog-footer"> <el-button @click="successDialogVisible = false">稍后支付</el-button> <el-button type="primary" @click="goToPay">立即支付</el-button> </span> </el-dialog> </div> </template>
<script> import { mapActions } from 'vuex'
export default { name: 'SeckillDetail', data() { return { product: null, currentImage: '', selectedSpec: null, quantity: 1, activeTab: 'detail', buying: false, successDialogVisible: false, countdown: { hours: '00', minutes: '00', seconds: '00' }, countdownTimer: null } }, computed: { salePercentage() { if (!this.product) return 0 const total = this.product.soldCount + this.product.stock return Math.round((this.product.soldCount / total) * 100) }, canBuy() { return this.product && this.product.stock > 0 && this.selectedSpec } }, async created() { await this.loadProductDetail() this.startCountdown() }, beforeDestroy() { if (this.countdownTimer) { clearInterval(this.countdownTimer) } }, methods: { ...mapActions('cart', ['addToCart']), async loadProductDetail() { const productId = this.$route.query.id // 模拟API调用 // const product = await api.getSeckillProduct(productId) this.product = { id: productId, name: '华为Mate50 Pro 5G手机', subtitle: '麒麟9000芯片,影像旗舰', seckillPrice: 3999, originalPrice: 6999, stock: 50, soldCount: 150, images: [ '/products/phone1.jpg', '/products/phone2.jpg', '/products/phone3.jpg' ], specs: [ { id: 1, name: '8GB+256GB 昆仑玻璃版' }, { id: 2, name: '8GB+512GB 昆仑玻璃版' } ], description: '<div>商品详情内容...</div>', parameters: [ { name: '屏幕尺寸', value: '6.74英寸' }, { name: '处理器', value: '麒麟9000' } ], reviews: [ { id: 1, username: '用户1', userAvatar: '/avatar1.jpg', rating: 5, content: '手机很好用,拍照效果不错' } ] } this.currentImage = this.product.images[0] this.selectedSpec = this.product.specs[0].id }, async handleSeckill() { this.buying = true try { // 模拟秒杀API调用 await new Promise(resolve => setTimeout(resolve, 1000)) this.successDialogVisible = true this.product.stock-- this.product.soldCount++ } catch (error) { this.$message.error('秒杀失败,请重试') } finally { this.buying = false } }, async addToCart() { const cartItem = { productId: this.product.id, name: this.product.name, image: this.currentImage, price: this.product.seckillPrice, specId: this.selectedSpec, quantity: this.quantity } await this.addToCart(cartItem) this.$message.success('已加入购物车') }, goToPay() { this.successDialogVisible = false this.$router.push('/order/pay') }, startCountdown() { // 假设秒杀在2小时后结束 const endTime = new Date() endTime.setHours(endTime.getHours() + 2) this.countdownTimer = setInterval(() => { const now = new Date() const diff = endTime - now if (diff <= 0) { clearInterval(this.countdownTimer) return } const hours = Math.floor(diff / (1000 * 60 * 60)) const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60)) const seconds = Math.floor((diff % (1000 * 60)) / 1000) this.countdown = { hours: hours.toString().padStart(2, '0'), minutes: minutes.toString().padStart(2, '0'), seconds: seconds.toString().padStart(2, '0') } }, 1000) } } } </script>
<style scoped> .seckill-detail { max-width: 1200px; margin: 0 auto; padding: 20px; }
.product-gallery .main-image img { width: 100%; height: 400px; object-fit: cover; border-radius: 8px; }
.thumbnail-list { display: flex; gap: 10px; margin-top: 15px; }
.thumbnail-item { width: 80px; height: 80px; border: 2px solid transparent; border-radius: 4px; cursor: pointer; overflow: hidden; }
.thumbnail-item.active { border-color: #ff6b35; }
.thumbnail-item img { width: 100%; height: 100%; object-fit: cover; }
.seckill-status { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; padding: 15px; background: linear-gradient(45deg, #fff5f5, #ffe6e6); border-radius: 8px; }
.countdown .time { background: #ff6b35; color: white; padding: 2px 6px; border-radius: 4px; margin: 0 2px; }
.product-title { font-size: 24px; color: #333; margin: 0 0 10px 0; }
.product-subtitle { color: #666; margin-bottom: 20px; }
.price-info { background: #f8f9fa; padding: 20px; border-radius: 8px; margin-bottom: 20px; }
.seckill-price .price { font-size: 28px; color: #ff6b35; font-weight: bold; }
.original-price .price { color: #999; text-decoration: line-through; }
.discount { color: #67C23A; font-weight: bold; margin-top: 10px; }
.stock-info { margin-bottom: 20px; }
.stock-text { display: flex; justify-content: space-between; margin-bottom: 10px; font-size: 14px; color: #666; }
.spec-selection { margin-bottom: 30px; }
.spec-item, .quantity-item { display: flex; align-items: center; margin-bottom: 15px; }
.spec-label { width: 80px; color: #333; font-weight: bold; }
.limit-text { margin-left: 10px; color: #999; font-size: 12px; }
.action-buttons { margin-bottom: 30px; }
.action-buttons .el-button { width: 48%; height: 50px; font-size: 16px; }
.action-buttons .el-button:first-child { margin-right: 4%; }
.service-info { text-align: center; color: #666; border-top: 1px solid #eee; padding-top: 20px; }
.service-info .el-col { display: flex; align-items: center; justify-content: center; gap: 5px; }
.product-description { margin-top: 40px; }
.success-content { text-align: center; padding: 20px; }
.review-item { border-bottom: 1px solid #eee; padding: 20px 0; }
.review-user { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.review-images img { width: 80px; height: 80px; object-fit: cover; margin-right: 10px; border-radius: 4px; } </style>
|