detail.vue
13.5 KB
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
<!--
* @Date: 2024-09-29 14:26:41
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-10-24 12:31:24
* @FilePath: /hager/src/views/product/detail.vue
* @Description: 文件描述
-->
<template>
<div class="product-detail">
<hager-box>
<div style="margin-top: 1.5rem;">
<el-breadcrumb separator="/">
<el-breadcrumb-item v-if="!is_xs">所有产品</el-breadcrumb-item>
<el-breadcrumb-item>{{ info.parent_name }}</el-breadcrumb-item>
<el-breadcrumb-item>{{ info.category_name }}</el-breadcrumb-item>
<el-breadcrumb-item>{{ info.product_name }}</el-breadcrumb-item>
</el-breadcrumb>
</div>
</hager-box>
<hager-box class="box-n">
<el-row v-if="!is_xs" :gutter="10" style="margin-bottom: 3rem;">
<el-col :span="8">
<hager-carousel :images="info_images"></hager-carousel>
</el-col>
<el-col :span="16">
<div class="product-detail-info">
<div class="product-title" style="">{{ info.product_name }}</div>
<div class="product-sub" style="margin: 1rem 0 2rem;" v-html="info.post_excerpt"></div>
</div>
</el-col>
</el-row>
<div v-else>
<div class="product-detail-info">
<div class="product-title" style="">{{ info.product_name }}</div>
<div class="product-sub" style="margin: 1rem 0 2rem;" v-html="info.post_excerpt"></div>
</div>
<div v-for="(item, index) in info_images" :key="index" class="product-item-img">
<el-image style="height: 14rem;" :src="item" fit="cover"></el-image>
</div>
</div>
</hager-box>
<hager-box class="box-2n">
<hager-h1 title="产品优势" sub="Product advantages"></hager-h1>
<div :class="['product-advantage', is_xs ? 'xs' : '']">
<div :class="['item', is_xs ? 'xs' : '']" v-for="(item, index) in product_advantages" :key="index">
<el-row :gutter="0" v-for="(x, idx) in item" :key="idx">
<el-col :span="24">{{ x }}</el-col>
</el-row>
</div>
</div>
</hager-box>
<hager-box class="box-n">
<hager-h1 title="产品资料" sub="Product Information"></hager-h1>
<div class="product-info">
<div class="info-control">
<el-row :gutter="0">
<el-col :span="is_xs ? 24 : 19">
<div :class="['control-left', is_xs ? 'xs' : '']">
<div v-if="product_sample" :class="['button', is_xs ? 'xs' : '', is_active === product_sample.id ? 'active' : '']" @click="onClick(product_sample)">产品样本</div>
<div v-if="technical_parameter" :class="['button', is_xs ? 'xs' : '', is_active === technical_parameter.id ? 'active' : '']" @click="onClick(technical_parameter)">技术参数</div>
<div v-if="product_manual" :class="['button', is_xs ? 'xs' : '', is_active === product_manual.id ? 'active' : '']" @click="onClick(product_manual)">产品说明书</div>
<div v-if="installation_tutorial" :class="['button', is_xs ? 'xs' : '', is_active === installation_tutorial.id ? 'active' : '']" @click="onClick(installation_tutorial)">安装教程</div>
</div>
</el-col>
<el-col v-if="!is_xs" :span="5">
<div>
<div @click="goToDownload" :class="['button', is_download_checked ? 'active' : '']">发送到邮箱</div>
</div>
</el-col>
</el-row>
</div>
<div>
<div class="mini-download-wrapper" v-if="is_xs">
<div>
<span @click="checkAll">全选</span>
<span v-if="checked_sum">已选 {{ checked_sum }}</span>
</div>
<div @click="goToDownload" :class="['button', is_download_checked ? 'active' : '']">发送到邮箱</div>
</div>
<div class="info-list" v-for="(item, index) in download_list" :key="index">
<el-row :gutter="0">
<el-col :span="18">
<div class="info-list-title">
<el-row :gutter="0">
<el-col :span="is_xs ? 4 : 2">
<i v-if="item.checked" @click="checkItem(item)" class="el-icon-folder-checked download-checked"></i>
<i v-else @click="checkItem(item)" class="el-icon-folder download-unchecked"></i>
</el-col>
<el-col :span="is_xs ? 20 : 22">
<div class="info-list-title-content">
<div>
<i class="el-icon-document" style="font-size: 1.35rem;"></i>
{{ item.name }}
</div>
<div>
{{ item.size }}
</div>
</div>
</el-col>
</el-row>
<!-- <i v-if="item.checked" @click="checkItem(item)" class="el-icon-folder-checked download-checked"></i>
<i v-else @click="checkItem(item)" class="el-icon-folder download-unchecked"></i>
<i class="el-icon-document" style="font-size: 1.25rem; margin-left: 1rem;"></i>
<p><span>{{ item.name }}</span><span>{{ item.size }}</span></p> -->
</div>
</el-col>
<el-col :span="6">
<div class="info-list-control">
<div @click="preview(item)">预览</div>
<div @click="sendEmail" class="icon-wrapper">
<img style="height: 1rem; width: auto;" src="https://cdn.ipadbiz.cn/hager/icon/%E9%82%AE%E4%BB%B6@2x.png">
</div>
</div>
</el-col>
</el-row>
</div>
</div>
</div>
</hager-box>
</div>
</template>
<script>
import mixin from 'common/mixin';
import hagerBox from '@/components/common/hagerBox';
import hagerCarousel from '@/components/hagerCarousel';
import hagerH1 from '@/components/common/hagerH1.vue';
import { MessageBox, Message } from 'element-ui';
import { getProductInfoAPI } from "@/api/hager.js";
export default {
components: { hagerBox, hagerCarousel, hagerH1 },
mixins: [mixin.init],
data () {
return {
is_active: '',
download_list: [],
images: [],
info: {},
info_images: [],
product_advantages: [],
product_sample: '',
technical_parameter: '',
product_manual: '',
installation_tutorial: '',
}
},
computed: {
is_download_checked () {
return this.download_list.filter(item => item.checked).length > 0;
},
checked_sum () {
return this.download_list.filter(item => item.checked).length;
},
},
async mounted () {
this.getInfo();
},
watch: {
// 监听路由参数变化时,更新输入框的值
async '$route.query.id' (val, old) {
if (old !== val) {
this.getInfo();
}
}
},
methods: {
async getInfo () {
const { code, data } = await getProductInfoAPI( { id: this.$route.query.id });
if (code) {
this.info = data;
if (this.info.file?.img) {
this.info_images = this.info.file.img.map(item => item.value);
}
//
this.product_advantages = this.splitIntoEqualChunks(this.info.product_advantages);
//
this.product_sample = this.info.file?.yangben?.map(item => ({ ...item, checked: false }));// 产品样本
this.technical_parameter = this.info.file?.canshu?.map(item => ({ ...item, checked: false })); // 技术参数
this.product_manual = this.info.file?.shuomingshu?.map(item => ({ ...item, checked: false })); // 产品说明书
this.installation_tutorial = this.info.file?.jiaocheng?.map(item => ({ ...item, checked: false })); // 安装教程
let arr = [this.product_sample, this.technical_parameter, this.product_manual, this.installation_tutorial]
for (let index = 0; index < arr.length; index++) {
const element = arr[index];
if (element) {
this.download_list = element;
console.warn(this.download_list);
this.is_active = this.download_list.id;
return;
}
}
}
},
onClick (item) {
this.is_active = item.id;
this.download_list = item;
this.download_list.forEach(item => item.checked = false);
},
goToDownload () {
if (this.is_download_checked) {
// 发送邮箱接口
Message({
type: 'success',
message: '发送成功'
});
}
},
checkAll () {
this.download_list.forEach(item => item.checked = true);
},
sendEmail () {
// 发送邮箱接口
Message({
type: 'success',
message: '发送成功'
});
},
preview (item) {
window.open(item.value, '_blank');
},
splitArrayIntoChunks(list) {
const productAdvantages = list;
const chunkSize = 5;
const result = [];
for (let i = 0; i < productAdvantages.length; i += chunkSize) {
// 使用 slice 方法按每组 5 个元素分割
const chunk = productAdvantages.slice(i, i + chunkSize);
result.push(chunk);
}
return result;
},
splitIntoEqualChunks(list) {
const middle = Math.ceil(list.length / 2); // 计算数组的一半,向上取整
const result = [];
// 第一个子数组是从 0 到 middle 的部分
result[0] = list.slice(0, middle);
// 第二个子数组是从 middle 到末尾的部分
result[1] = list.slice(middle);
return result;
},
checkItem (item) {
item.checked = !item.checked;
// this.$forceUpdate();
},
}
}
</script>
<style lang="less" scoped>
.product-detail {
.box-n {
background-color: #fff;
padding: 2rem 0;
}
.box-2n {
background-color: #f1f1f1;
padding: 2rem 0;
}
.product-detail-info {
.product-title {
font-size: 2rem;
font-weight: bold;
color: @secondary-color;
}
.product-sub {
// margin: 1rem 0 2rem;
// color: @text-color;
}
.product-info-list {
padding: 0 1rem;
li {
line-height: 2;
font-size: 0.9rem;
}
}
}
.product-advantage {
margin-top: 1rem;
display: flex;
flex-wrap: wrap;
// gap: 3rem;
.item {
width: calc(50% - 3rem);
box-sizing: border-box;
margin-right: 3rem;
margin-bottom: 1rem;
padding-top: 1rem;
background-color: #f0f0f0;
border-top: 4px solid @primary-color;
line-height: 2;
&.xs {
padding-bottom: 1rem;
width: 100%;
}
}
&.xs {
display: block;
}
}
.product-info {
.info-control {
// display: flex;
border-bottom: 4px solid @primary-color;
padding-bottom: 1rem;
margin-top: 2rem;
.control-left {
display: flex;
// flex: 1 0 0;
&.xs {
display: flex;
flex-wrap: nowrap; /* 禁止换行 */
overflow-x: auto; /* 启用横向滚动 */
-webkit-overflow-scrolling: touch; /* 使滚动更平滑,适用于移动端 */
}
}
.button {
background-color: #f3f3f3;
padding: 1rem 2.2rem;
border-radius: 5px;
margin-right: 1rem;
text-align: center;
&:hover {
cursor: pointer;
}
&.active {
background-color: @primary-color;
color: #fff;
}
&.xs {
flex: 0 0 auto; /* 子元素保持固定大小 */
width: 5rem; /* 可以根据需要设置宽度 */
margin-right: 10px; /* 子元素之间的间距 */
}
}
}
.info-list {
// display: flex;
// justify-content: space-between;
// align-items: center;
padding-top: 2rem;
color: #6b6b6b;
.info-list-title {
// display: flex;
// align-items: center;
}
.info-list-title-content {
display: flex;
justify-content: space-between;
align-items: center;
}
.info-list-control {
display: flex;
justify-content: flex-end;
align-items: center;
color: @primary-color;
div {
margin-right: 1rem;
&:hover {
cursor: pointer;
color: @primary-color;
text-decoration: underline;
}
}
.icon-wrapper {
display: flex;
justify-content: center; /* 水平居中 */
align-items: center; /* 垂直居中 */
img {
max-width: 100%; /* 确保图片不会超出容器 */
height: auto; /* 保持图片的宽高比 */
}
}
}
.download-checked {
font-size: 1.5rem;
color: @primary-color;
&:hover {
cursor: pointer;
}
}
.download-unchecked {
font-size: 1.5rem;
&:hover {
cursor: pointer;
}
}
}
.mini-download-wrapper {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 1rem;
.button {
background-color: #f3f3f3;
padding: 0.85rem 1rem;
border-radius: 5px;
text-align: center;
&.active {
background-color: @primary-color;
color: #fff;
}
}
}
}
.product-item-img {
height: auto;
padding: 1.5rem;
text-align: center;
color: #333;
border-radius: 8px;
background-color: #FFF;
margin-bottom: 1rem;
border: 1px solid #ebebeb;
}
}
</style>