tanghaolin
2025-04-15 8c3d15eae99d51193e20ff222dedf96cdba57b33
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
<template>
    <div class="container mx-auto px-4 py-8 bg-white">
        <!-- 面包屑导航 -->
        <div class="mb-6 text-gray-500">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item :to="{ path: '/certified-products' }">能效产品</el-breadcrumb-item>
                <el-breadcrumb-item>产品详情</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
 
        <div class="flex gap-8">
            <!-- 左侧商品图片 -->
            <div class="w-[400px] flex-shrink-0">
                <el-image :src="product.image" fit="contain" :preview-src-list="[product.image]" class="w-full h-[400px] border rounded-lg" />
            </div>
 
            <!-- 右侧商品信息 -->
            <div class="flex-1">
                <h1 class="text-2xl font-medium mb-4">{{ product.name }}</h1>
 
                <!-- 订货信息 -->
                <div class="bg-gray-50 p-4 rounded-lg mb-4">
                    <div class="text-gray-500 mb-2">订货编码:{{ product.applicationCode }}</div>
                    <div class="flex items-center gap-2">
                        <span class="text-gray-500">能效等级:</span>
                        <div class="flex items-center relative">
                            <img :src="EecLevelEnum[productDataRef.EnergyEfficiencyClass]?.icon" class="h-8" />
                            <!-- <span class="text-white relative right-[42px] top-[-1px]">1</span> -->
                            <!-- <span class="text-white absolute left-[16px] bottom-[10px] text-small">{{ EecLevelEnum[productDataRef.EnergyEfficiencyClass]?.name }}</span> -->
                        </div>
                    </div>
                </div>
 
                <!-- 价格区域 -->
                <div class="mb-6">
                    <div class="flex items-baseline gap-2">
                        <span class="text-gray-500">价格:</span>
                        <span class="text-2xl font-bold text-red-500">面议</span>
                    </div>
                </div>
 
                <!-- 服务承诺 -->
                <div class="border-t border-b py-4 mb-6">
                    <div class="flex items-center gap-6">
                        <div class="flex items-center gap-2">
                            <el-icon class="text-green-500"><Check /></el-icon>
                            <span>正品保证</span>
                        </div>
                        <div class="flex items-center gap-2">
                            <el-icon class="text-green-500"><Check /></el-icon>
                            <span>极速发货</span>
                        </div>
                        <div class="flex items-center gap-2">
                            <el-icon class="text-green-500"><Check /></el-icon>
                            <span>售后无忧</span>
                        </div>
                    </div>
                </div>
 
                <!-- 购买按钮 -->
                <div class="flex gap-4">
                    <div class="flex items-center mb-4">
                        <el-input-number class="!w-[100px]" v-model="product.quantity" :min="1" :max="99" size="large" controls-position="right">
                            <template #decrease-icon>
                                <el-icon>
                                    <Minus />
                                </el-icon>
                            </template>
                            <template #increase-icon>
                                <el-icon>
                                    <Plus />
                                </el-icon>
                            </template>
                        </el-input-number>
                    </div>
                    <el-button size="large" @click="handleAddToCart">加入购物车</el-button>
                    <el-button type="primary" size="large" @click="handleBuyNow">立即购买</el-button>
                </div>
            </div>
        </div>
 
        <!-- 商品详情 -->
        <div class="mt-8">
            <el-tabs v-model="activeTab">
                <el-tab-pane label="商品介绍" name="intro">
                    <div class="p-6">
                        <h3 class="text-lg font-medium mb-4">产品参数</h3>
                        <el-descriptions :column="2" border>
                            <el-descriptions-item label="品牌">{{ product.brand }}</el-descriptions-item>
                            <el-descriptions-item label="型号">{{ product.model }}</el-descriptions-item>
                            <el-descriptions-item label="功率">{{ product.power }}</el-descriptions-item>
                            <el-descriptions-item label="电压">{{ product.voltage }}</el-descriptions-item>
                            <el-descriptions-item label="转速">{{ product.speed }}</el-descriptions-item>
                            <el-descriptions-item label="防护等级">{{ product.protection }}</el-descriptions-item>
                        </el-descriptions>
 
                        <div class="mt-8">
                            <h3 class="text-lg font-medium mb-4">产品详情</h3>
                            <div class="space-y-4">
                                <img v-for="(img, index) in product.detailImages" :key="index" :src="img" class="w-full" alt="产品详情图" />
                            </div>
                        </div>
                    </div>
                </el-tab-pane>
                <el-tab-pane label="性能曲线" name="PerformanceCurve">
                    <div style="width: 1200px; height: 750px" v-show="isPumpDetail">
                        <LXBChart ref="lxbChartCtrl"></LXBChart>
                    </div>
                    <img width="1200" height="auto" :src="product.Chart" v-if="isFan" />
                    <el-empty description="暂无性能曲线信息" v-show="!isPumpDetail && !isFan" />
                </el-tab-pane>
                <el-tab-pane label="变速曲线" name="params">
                    <!-- <div style="width: 1200px; height: 750px"></div> -->
                    <div style="width: 1200px; height: 750px" v-show="isPumpDetail">
                        <MultiSpeedChart ref="multiSpeedChartCtrl"></MultiSpeedChart>
                    </div>
                    <el-empty description="暂无变速曲线信息" v-show="!isPumpDetail" />
                </el-tab-pane>
                <el-tab-pane label="切割曲线" name="CutCurve">
                    <el-empty description="暂无切割曲线信息" />
                </el-tab-pane>
                <el-tab-pane label="规格参数" name="SpecificParam">
                    <div class="p-6">
                        <prop ref="propCtrl" v-show="isPumpDetail"></prop>
                    </div>
                    <el-empty description="暂无变速曲线信息" v-show="!isPumpDetail" />
                </el-tab-pane>
                <el-tab-pane label="选型报告" name="SelectReport">
                    <img width="1200" height="auto" :src="product.SelectReport" v-if="isFan || isPumpDetail" />
                    <el-empty description="暂无报告" v-show="!isPumpDetail && !isFan" />
                </el-tab-pane>
                <el-tab-pane label="测试报告" name="certificate">
                    <div class="p-6 flex justify-center">
                        <img :src="product.certificatePath" alt="节能证书" class="max-w-full" />
                    </div>
                </el-tab-pane>
                <el-tab-pane label="包装售后" name="service">
                    <div class="p-6">
                        <h3 class="text-lg font-medium mb-4">包装清单</h3>
                        <p class="text-gray-600">{{ product.package }}</p>
 
                        <h3 class="text-lg font-medium mt-6 mb-4">售后服务</h3>
                        <div class="text-gray-600">
                            <p>1. 本产品全国联保,享受三包服务</p>
                            <p>2. 质保期:12个月</p>
                            <p>3. 对于质量问题,提供免费维修服务</p>
                        </div>
                    </div>
                </el-tab-pane>
            </el-tabs>
        </div>
    </div>
 
    <!-- 购买确认对话框 -->
    <el-dialog v-model="showBuyDialog" title="确认订单" width="500px">
        <div class="p-4">
            <div class="flex items-center gap-4 mb-6">
                <el-image :src="product.image" class="w-20 h-20" />
                <div>
                    <div class="font-medium">{{ product.name }}</div>
                    <div class="text-red-500 mt-2">¥{{ product.price }}</div>
                </div>
            </div>
 
            <el-form :model="orderForm" label-width="100px">
                <el-form-item label="收货人">
                    <el-input v-model="orderForm.name" placeholder="请输入收货人姓名" />
                </el-form-item>
                <el-form-item label="联系电话">
                    <el-input v-model="orderForm.phone" placeholder="请输入联系电话" />
                </el-form-item>
                <el-form-item label="收货地址">
                    <el-input v-model="orderForm.address" type="textarea" placeholder="请输入详细地址" />
                </el-form-item>
            </el-form>
        </div>
        <template #footer>
            <div class="flex justify-between items-center">
                <div class="text-lg">
                    实付款:<span class="text-red-500 font-medium">¥{{ product.price }}</span>
                </div>
                <div class="flex gap-2">
                    <el-button @click="showBuyDialog = false">取消</el-button>
                    <el-button type="primary" @click="confirmOrder">提交订单</el-button>
                </div>
            </div>
        </template>
    </el-dialog>
</template>
 
<script setup lang="ts">
import EecLevel1 from '@/assets/icons/energy1.png';
import EecLevel2 from '@/assets/icons/energy2.png';
import { SERVE_URL } from '@/constants';
import { Check, TrendCharts } from '@element-plus/icons-vue';
import { ElMessage } from 'element-plus';
import { onMounted, ref, watch, onUnmounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import axios from 'axios';
import pumpDetailInfo from './mock/DetailsInfo';
import pumpDetailInfo_WQ from './mock/DetailsInfo_WQ';
import LXBChart from '@/components/Chart/LXBChart.vue';
import MultiSpeedChart from '@/components/Chart/MultiSpeedChart.vue';
import prop from './components/prop.vue';
import { useCartStore } from '@/stores/useCartStore';
 
const route = useRoute();
const router = useRouter();
 
const lxbChartCtrl = ref();
const multiSpeedChartCtrl = ref();
const propCtrl = ref();
const activeTab = ref('intro');
const showBuyDialog = ref(false);
 
const isPumpDetail = ref(false);
const isFan = ref(false);
const orderForm = ref({
    name: '',
    phone: '',
    address: '',
});
 
// 从localStorage获取产品信息
const product = ref({
    id: '',
    name: '',
    applicationCode: '',
    quantity: 1,
    price: '',
    image: '',
    brand: '',
    model: '',
    power: '',
    voltage: '',
    speed: '',
    protection: '',
    eecLevelIcon: EecLevel1,
    package: '电机 × 1, 说明书 × 1, 合格证 × 1',
    certificatePath: '',
    specifications: {
        产品型号: '',
        额定功率: '',
        额定电压: '',
        防护等级: '',
        绝缘等级: 'F级',
        效率等级: '一级能效',
        重量: '约12kg',
    },
    detailImages: [],
});
 
const handleBuyNow = () => {
    // 创建订单商品信息
    const orderItem = {
        addID: product.value.id,
        addTime: new Date().toLocaleString(),
        name: product.value.name,
        price: Number(product.value.price),
        quantity: product.value.quantity,
        image: product.value.image,
        selected: true  // 默认选中
    };
 
    // 将商品添加到购物车并设置为选中状态
    const cartStore = useCartStore();
    
    // 清除购物车中其他商品的选中状态
    cartStore.items.forEach(item => {
        cartStore.updateItemSelected(item.addID, false);
    });
    
    // 添加当前商品到购物车并选中
    cartStore.addToCart(orderItem);
    cartStore.updateItemSelected(orderItem.addID, true);
 
    // 跳转到订单页面
    router.push('/order-info');
};
 
// 创建飞入动画元素
const createFlyingElement = (productImg, cart) => {
  const imgClone = productImg.cloneNode(true) as HTMLElement;
  const startRect = productImg.getBoundingClientRect();
  const endRect = cart.getBoundingClientRect();
 
  // 设置初始样式
  Object.assign(imgClone.style, {
    position: 'fixed',
    width: `${startRect.width}px`, 
    height: `${startRect.height}px`,
    left: `${startRect.left}px`,
    top: `${startRect.top}px`,
    zIndex: '1000',
    transition: 'all 0.5s cubic-bezier(0.4, 0, 0.2, 1)',
    borderRadius: '50%',
    opacity: '0.8'
  });
 
  return {imgClone, endRect};
};
 
// 执行飞入动画
const animateToCart = (imgClone, endRect) => {
  Object.assign(imgClone.style, {
    width: '30px',
    height: '30px', 
    left: `${endRect.left + endRect.width / 2 - 15}px`,
    top: `${endRect.top + endRect.height / 2 - 15}px`,
    opacity: '0'
  });
};
 
// 添加商品到购物车
const addItemToCart = () => {
  const cartStore = useCartStore();
  const newCartItem = {
    addID: product.value.id,
    addTime: new Date().toLocaleString(),
    name: product.value.name,
    price: Number(product.value.price),
    quantity: product.value.quantity,
    image: product.value.image,
    selected: false,
    companyName: product.value.brand,
    model: product.value.model,
  };
 
  cartStore.addToCart(newCartItem);
  ElMessage.success('已添加到购物车');
};
 
const handleAddToCart = () => {
  const productImg = document.querySelector('.el-image__inner');
  const cart = document.querySelector('.cart-badge');
  
  if (!productImg || !cart) return;
 
  const {imgClone, endRect} = createFlyingElement(productImg as HTMLElement, cart);
  document.body.appendChild(imgClone);
 
  // 触发动画
  setTimeout(() => {
    animateToCart(imgClone, endRect);
 
    // 动画结束后处理
    setTimeout(() => {
      document.body.removeChild(imgClone);
      addItemToCart();
    }, 500);
  }, 0);
};
 
const handleViewCurve = () => {
    window.open('http://www.xpump.net/V4/#/CN/Target/DOOCH/Pump/Index/C69S4/8978', '_blank');
};
 
const confirmOrder = () => {
    if (!orderForm.value.name || !orderForm.value.phone || !orderForm.value.address) {
        ElMessage.warning('请填写完整的收货信息');
        return;
    }
    // 保存订单信息到localStorage
    const orderInfo = {
        orderNo: 'DD' + Date.now(),
        totalAmount: product.value.price,
        createTime: new Date().toLocaleString(),
        product: product.value,
        address: orderForm.value,
    };
    localStorage.setItem('currentOrder', JSON.stringify(orderInfo));
 
    ElMessage.success('订单提交成功');
    showBuyDialog.value = false;
    // 跳转到支付页面
    router.push('/payment');
};
const EecLevelEnum = {
    1: { name: '一级能效', icon: EecLevel1 },
    2: { name: '二级能效', icon: EecLevel2 },
};
 
const productDataRef = ref({});
onMounted(() => {
    // 从localStorage获取产品信息
    const savedProduct = localStorage.getItem('currentProduct');
    if (savedProduct) {
        const productData = JSON.parse(savedProduct);
        productDataRef.value = productData;
 
        // 合并默认值和保存的产品数据
        product.value = {
            ...product.value,
            id: productData.Id,
            name: productData.ModelType,
            applicationCode: productData.RecordNumber,
            price: productData.Price,
            image: `${SERVE_URL}${productData.PhysicalPicturePath}`,
            certificatePath: `${SERVE_URL}${productData.CertificatePath}`,
            brand: productData.CompanyName,
            model: productData.Model,
            power: '详询厂家',
            voltage: '详询厂家',
            speed: '详询厂家',
            protection: '详询厂家',
            detailImages: [`${SERVE_URL}${productData.PhysicalPicturePath}`],
            specifications: {
                产品型号: productData.Model,
                生产企业: productData.CompanyName,
                备案编号: productData.RecordNumber,
                备案时间: productData.RecordTime,
                能效等级: `${productData.EnergyEfficiencyClass}级`,
            },
        };
        isPumpDetail.value = productData.Id.includes('Pupm') ? true : false;
        if (product.value.model.includes('DSWQ') && isPumpDetail.value) {
            product.value.SelectReport = 'static/EecProductData/image/1/DSWQ_SelectReport.png';
        }
        if (product.value.model.substring(0, 3).includes('DRL') && isPumpDetail.value) {
            product.value.SelectReport = 'static/EecProductData/image/1/DRL_SelectReport.png';
        }
 
        isFan.value = productData.Id.includes('FJ') ? true : false;
        if (isFan.value) {
            product.value.Chart = 'static/EecProductData/image/3/fan_chart.png';
            product.value.SelectReport = 'static/EecProductData/image/3/SelectReport.png';
        }
    }
    initDetailData();
});
const initDetailData = () => {
    let m_userUnitSetting = {
        NPSH: 0,
        isAdjustCoordUnitByUserSetting: false,
    };
    let pumpInfoData = pumpDetailInfo;
    if (product.value.model.includes('DSWQ')) {
        pumpInfoData = pumpDetailInfo_WQ;
    }
    let pumpBaseInfo = {
        CorpID: 69,
        SeriesID: 'C69S4',
        PumpID: 8978,
        SubID: 0,
        ChartType: 3,
        PumpStyle: 0,
        PumpName4File: 'DRL1-18S',
        CorpName: '中韩杜科',
        PumpName: 'DRL1-18S',
        SeriesName: 'DRL',
        CatalogName: '立式多级泵',
        EecStauts: 0,
        EecGrade: 0,
        DefaultMotorPower: 0,
        MaxD2: 75,
        WrkD2: 75,
        MinD2: 75,
        Ratedn: 2900,
        WrkSpeed: 2900,
        FirePumpType: 0,
        DriveType: 0,
        RatedParas: {
            H: '100.5',
            Q: '1',
            E: '41',
            P: '0.67',
            NPSHr: null,
        },
    };
    var cb_dict = {
        //设置曲线修改回调函数
        setChangeWrkCurveCb: (curve) => {
            multiSpeedChartCtrl.value.setWrkCurveInfo(curve);
        },
    };
    if (!isPumpDetail.value) return;
    lxbChartCtrl.value.initPumpInfoData(0, pumpInfoData, cb_dict, m_userUnitSetting);
    multiSpeedChartCtrl.value.initPumpInfoData(0, pumpInfoData, () => {}, m_userUnitSetting);
    //初始化属性控件
    propCtrl.value.initialData(0, pumpBaseInfo, pumpInfoData.PartFullInfo, pumpInfoData.SettingInfo);
};
</script>
 
<style scoped>
:deep(.el-tabs__nav-wrap::after) {
    height: 1px;
}
 
:deep(.el-descriptions__label) {
    width: 120px;
    font-weight: normal;
}
</style>