operation-bar.vue
3.21 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
<template>
<div>
<ul class="item-action">
<li><a v-brand-href="brand && brand.brand_domain"><i class="icon icon-store"></i><span
class="action-text">{{brand && brand.brand_name
}}</span></a></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-share2" @click="share"></i><span class="action-text">分享</span></li>
</ul>
</div>
</template>
<style>
.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>
<script>
import yoho from 'yoho';
import tip from 'common/tip';
export default {
name: 'operation-bar',
props: {
brand: {
type: Object,
return() {
return {};
}
},
entity: {
type: Object,
return() {
return {};
}
},
shareTitle: String,
shareImg: String
},
data() {
return {};
},
methods: {
share() {
yoho.goShare({
title: this.shareTitle || '',
des: '我在BLK发现了一个不错的商品,快来看看吧!',
img: location.protocol + this.shareImg,
url: location.href
});
},
toggleFavorite: function() {
$.post('/product/favorite.json', {
operation: this.entity.is_collect === 'Y' ? 'remove' : 'add',
id: this.entity.product_id
}).then((result)=> {
if (result.code === 200) {
tip(this.entity.is_collect === 'Y' ? '取消收藏成功' : '收藏成功');
this.entity.is_collect = this.entity.is_collect === 'Y' ? 'N' : 'Y';
yoho.store.set('productReload', true);
} else if (result.code === 401) {
yoho.goLogin('', () => {
this.toggleFavorite();
});
}
});
}
}
};
</script>