shop-fav.vue
2.98 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
<template>
<div class="shop-fav">
<ul class="item-action">
<li><a-link :href="brandHref"><i class="icon icon-store"></i><span
class="action-text">{{entity.brand_info && entity.brand_info.brand_name
}}</span></a-link></li>
<li><i class="icon"
:class="{'icon-focus': entity.is_collect !== 'Y', 'icon-focused': entity.is_collect === 'Y'}"
@click="toggleFavorite"></i><span
class="action-text">收藏
</span></li>
<li><i class="icon icon-share1" @click="share"></i><span class="action-text">分享</span></li>
</ul>
</div>
</template>
<script>
import {PRODUCT_FAVORITE} from 'store/product/types';
export default {
name: 'operation-bar',
props: {
entity: {
type: Object,
return() {
return {};
}
}
},
computed: {
brandHref() {
return this.entity.brand_info && `/product/shop/${this.entity.brand_info.brand_domain}`;
}
},
methods: {
share() {
this.$yoho.goShare({
title: this.shareTitle || '',
des: '我在BLK发现了一个不错的商品,快来看看吧!',
img: location.protocol + this.shareImg,
url: location.href
});
},
toggleFavorite: function() {
this.$store.dispatch(PRODUCT_FAVORITE, {
product_id: this.entity.product_id,
is_collect: this.entity.is_collect
}).then(res => {
if (res.code === 200) {
this.$message.success(this.entity.is_collect === 'Y' ? '取消收藏成功' : '收藏成功');
} else if (res.code === 401) {
this.$message.warning('请登录');
this.$yoho.goLogin('', () => {
this.toggleFavorite();
});
}
});
}
}
};
</script>
<style lang="scss">
.shop-fav {
padding-top: 25px;
padding-bottom: 25px;
.item-action {
height: 103px;
font-size: 0;
text-align: center;
li {
position: relative;
display: inline-block;
margin-top: 70px;
text-align: center;
font-size: 22px;
width: 250px;
&:first-child {
float: left;
width: 210px;
}
&:last-child {
float: right;
width: 210px;
}
}
li .action-text {
display: inline-block;
max-width: 200px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
li .icon {
position: absolute;
margin-left: -20px;
top: -50px;
left: 50%;
font-size: 36px;
}
}
}
</style>