MyCollect.vue
3.88 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
<template>
<div id="MyCollect">
<van-swipe-cell v-for="(item, index) in CollectList" :key="index" :name="'collectItem' + index" :before-close="beforeClose">
<div class="collect_item" @click="handleCourse(item)">
<div class="course_img" :style="{ backgroundImage: 'url(' + item.img + ')' }"></div>
<div class="right">
<p class="course_name">{{ item.title }}</p>
<p class="course_price">
<span>¥ {{ item.price }}起</span><van-icon name="delete-o" @click.stop="deleteCollect(index)" />
</p>
</div>
</div>
<template #right>
<div class="delete_button">
<span>取消<br />收藏</span>
</div>
</template>
</van-swipe-cell>
</div>
</template>
<script>
export default {
data() {
return {
CollectList: [],
}
},
mounted() {
this.getMyCollect()
},
methods: {
getMyCollect() {
const userInfo = JSON.parse(localStorage.getItem('userInfo'))
this.yxAxios
.post(`${this.proxyUrl}/api/product/getMyCollect`, {
centerNo: userInfo.centerNo,
})
.then((res) => {
if (res.data.code == 200) {
this.CollectList = res.data.rows
} else {
this.$toast.fail(res.data.message)
}
})
},
// position 为关闭时点击的位置
beforeClose({ position, instance, name }) {
switch (position) {
case 'right':
this.$dialog
.confirm({
title: '确定取消收藏吗?',
})
.then(() => {
let index = name.replace('collectItem', '')
this.cancelCollect(index)
instance.close()
})
.catch(() => {
instance.close()
})
}
},
handleCourse(item) {
this.$router.push({ name: 'ServiceAbroadDetail', query: { courseId: item.productId, publicName: localStorage.getItem('publicName') } })
},
// 点击按钮取消收藏
deleteCollect(index) {
this.$dialog
.confirm({
title: '确定取消收藏吗?',
})
.then(() => {
this.cancelCollect(index)
})
},
// 取消收藏
cancelCollect(index) {
const userInfo = JSON.parse(localStorage.getItem('userInfo'))
this.yxAxios
.post(`${this.proxyUrl}//api/product/cancelCollect`, {
centerNo: userInfo.centerNo,
productId: this.CollectList[index].productId,
})
.then((res) => {
if (res.data.code == 200) {
this.$toast('取消收藏成功')
this.getMyCollect()
} else {
this.$toast.fail(res.data.message)
}
})
},
},
}
</script>
<style lang="scss">
#MyCollect {
.collect_item {
padding: 32px 36px;
&:not(:nth-of-type()) {
border-bottom: 1px solid #f0f0f0;
}
.course_img {
width: 150px;
height: 150px;
overflow: hidden;
background-size: cover;
border-radius: 12px;
display: inline-block;
vertical-align: top;
}
.right {
display: inline-flex;
flex-direction: column;
justify-content: space-between;
width: 500px;
height: 150px;
margin-left: 20px;
.course_name {
font-size: 28px;
}
.course_price {
display: flex;
justify-content: space-between;
font-size: 24px;
color: #999;
}
}
}
.delete_button {
width: 140px;
height: 100%;
background: #bbb;
position: relative;
span {
font-size: 28px;
color: #fff;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
}
}
</style>
<style lang="scss">
// 长辈版
.elder {
#MyCollect .collect_item .right .course_name,#MyCollect .collect_item .right .course_price{
font-size: 36px;
}
}
</style>