grass-artilces.vue
3.06 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
<template>
<!--推荐搭配9宫格图片-->
<div class="articles-wrapper" v-if="articleList">
<div class="articles-container">
<p class="title">推荐搭配({{articleTotal}})</p>
<ul>
<li v-for="(item, index) in articleList"
@click="showAricleImages"
:data-id="item.articleId"
:data-index="item.imageindex"
:data-idx="index">
<img v-lazy="item.coverImage">
</li>
</ul>
</div>
</div>
</template>
<script>
import {createNamespacedHelpers} from 'vuex';
const {mapActions} = createNamespacedHelpers('product');
export default {
name: 'grassArtilces',
props: {
listdata: {
type: Object,
default: {}
},
productId: {
type: Number
}
},
data() {
return {
imgs: [],
initialIndex: 0,
articleTotal: 0
};
},
computed: {
articleList() { // 获取到listdata之后处理数据
if (this.listdata && this.listdata.list) {
this.imgs = this.listdata.imageList || [];
this.articleTotal = this.listdata.list.length || 0;
}
return this.listdata.list;
}
},
methods: {
...mapActions(['fetchGrassArticleImages']),
showAricleImages(e) { // 点击推荐小图展示文章内大图
this.initialIndex = parseInt(e.currentTarget.dataset.index, 10) || 0;
this.$createImagePreview({
imgs: this.imgs,
initialIndex: this.initialIndex,
loop: false,
speed: 500,
onChange: (i) => {
this.initialIndex = i;
}
}).show();
// yas
/**
* 图片点击时
* XY_GDS_DT_ARTICLE_C
* 1.PRD_SKN:商品SKN
* 2.ARTICLE:文章ID
* 3.I_INDEX:顺序号
*/
let articleId = e.currentTarget.dataset.id;
let index = e.currentTarget.dataset.idx;
let param = {
PRD_SKN: this.productId,
ARTICLE: articleId,
I_INDEX: +index + 1
};
this.$store.dispatch('reportYas', {
params: {
appop: 'XY_GDS_DT_ARTICLE_C',
param,
}
});
},
}
};
</script>
<style lang="scss" scoped>
.articles-wrapper {
position: relative;
width: 100%;
margin: 40px 0 0 0;
.articles-container {
position: relative;
padding: 0 40px;
overflow: hidden;
.title {
font-size: 36px;
line-height: 44px;
font-weight: 600;
}
ul {
position: relative;
width: 100%;
margin: 20px auto;
list-style: none;
padding: 0;
overflow: hidden;
li {
display: flex;
justify-content: center;
align-items: center;
float: left;
width: 222px;
height: 222px;
margin: 0 0 2px 0;
box-sizing: border-box;
border-radius: 8px;
overflow: hidden;
img {
width: 100%;
float: left;
margin: 0 auto;
}
}
li:nth-child(3n + 2) {
margin: 0 2px;
}
}
}
}
</style>