AllLoveGo.vue
6.58 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
<template>
<div class="allLoveGo">
<div class="likeGO"><b>大家都爱去</b></div>
<van-list v-model="loading" :finished="Finished" finished-text="没有更多了" @load="onLoad">
<ul class="likeList">
<li v-for="(n, i) in likeList" :key="i">
<div class="top" @click="gostoryDetail(n.id)">
<span>故事</span>
<div class="position">
<van-icon name="location" />
<b>{{ n.city }}</b>
</div>
<img :src="n.coverUrl" alt="" />
</div>
<div class="bottom">
<h3>{{ n.title }}</h3>
<div>
<img :src="n.faceUrl ? n.faceUrl : require('../assets/boy.png')" alt="" />
<span class="name">{{ n.name }}</span>
<div :class="n.likeId > 0 ? 'zan active' : 'zan'" @click="zanbtn(n.likeId, n.id, i)">
<van-icon name="good-job-o" />
<span>{{ n.likeCount }}</span>
</div>
</div>
</div>
</li>
<!-- <p v-if="likeList.length === likeCount" class="noMove">没有更多了</p> -->
<van-empty
class="custom-image"
image="https://img.yzcdn.cn/vant/custom-empty-image.png"
description="暂无推荐故事"
v-if="likeList.length == 0"
/>
</ul>
</van-list>
</div>
</template>
<script>
export default {
data() {
return {
likeList: [],
likePage: 1,
likeCount: '',
userInfo: '',
loading: false,
Finished: false,
}
},
// mounted() {
// window.addEventListener("scroll", this.handleScroll);
// },
// beforeDestroy() {
// window.removeEventListener("scroll",this.handleScroll)
// },
created() {
var userInfo = localStorage.getItem('userInfo')
if (userInfo) {
this.userInfo = JSON.parse(userInfo)
}
this.GetStoryList(1)
},
methods: {
onLoad() {
var that = this
setTimeout(() => {
that.likePage++
that.GetStoryList(that.likePage)
}, 1000)
},
zanbtn(id, nid, index) {
if (id > 0) {
this.DeleteStoryLike(id, index)
} else {
this.AddStoryLike(nid, index)
}
},
AddStoryLike(id, index) {
var that = this
this.http
.AddStoryLike({
type: 1,
storyId: id,
userId: this.userInfo ? this.userInfo.centerNo : 0,
})
.then(function(res) {
if (res.status == 1) {
setTimeout(function() {
that.likeList = []
that.GetStoryList(1)
}, 1000)
}
})
},
DeleteStoryLike(id, index) {
var that = this
this.http
.DeleteStoryLike({
type: 1,
id: id,
})
.then(function(res) {
if (res.status == 1) {
setTimeout(function() {
that.likeList = []
that.GetStoryList(1)
}, 1000)
}
})
},
gostoryDetail(id) {
this.$router.push({ path: '/StoryDetail', query: { id: id } })
},
handleScroll() {
var that = this //变量scrollTop是滚动条滚动时,距离顶部的距离
//window.onscroll = function(){
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop //变量windowHeight是可视区的高度
var windowHeight = document.documentElement.clientHeight || document.body.clientHeight //变量scrollHeight是滚动条的总高度
var scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight //滚动条到底部的条件
if (scrollTop + windowHeight == scrollHeight) {
if (that.likeList.length < that.likeCount) {
likePage++
that.GetStoryList(likePage)
} //写后台加载数据的函数 //console.log("距顶部"+scrollTop+"可视区高度"+windowHeight+"滚动条总高度"+scrollHeight);
} // }
},
GetStoryList(page) {
var that = this
this.http
.GetStoryList({
pageIndex: page,
pageSize: 6,
userId: this.userInfo ? this.userInfo.centerNo : 0,
cs: this.projectCity,
})
.then(function(res) {
if (res.status == 1) {
if (res.data.items.length > 0) {
that.likeCount = res.data.count
that.likeList = that.likeList.concat(res.data.items)
}
that.loading = false
if (res.data.items.length < 10) {
that.Finished = true
}
}
})
},
},
}
</script>
<style lang="stylus" scoped>
.allLoveGo{
.likeGO{
color #202228
font-size 2rem
margin-bottom 15px
b{
position relative
}
b::after{
content ''
display inline-block
height 3px
width 100%
background-image linear-gradient(to right,#3FCC95,#ffffff)
position absolute
left 0
bottom -5px
}
}
.likeList{
overflow hidden
li{
float left
width 50%
box-sizing border-box
margin-bottom 10px
.top{
position relative
img{
width 100%
height 168px
object-fit cover
border-radius 10px
}
span{
position absolute
background-image linear-gradient(#5EFFC1,#10E693)
left 10px
top 10px
z-index 100
padding 3px 5px
border-radius 3px
}
.position{
position absolute
bottom 10px
left 10px
i{
color #06CB67
vertical-align middle
font-size 1.8rem
}
b{
display inline-block
vertical-align middle
color white
font-size 1.8rem
}
}
}
.bottom{
background-color white
border-radius 0 0 5px 5px
h3{
word-break: break-all;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
margin 0
font-size 1.6rem
}
div{
position relative
padding 5px 0
img{
width 20px
height 20px
border-radius 50%
display inline-block
vertical-align middle
margin-right 5px
}
span.name{
display inline-block
vertical-align middle
color #7E7F81
font-size 1.2rem
}
div.zan{
position absolute
right 10px
bottom 3px
font-size 1.2rem
color #7E7F81
i{
font-size 1.4rem
vertical-align top
}
span{
display inline-block
vertical-align top
}
}
.zan.active{
i{
color #0080FF
}
}
}
}
}
li:nth-child(2n){
padding-left 10px
}
li:nth-child(2n+1){
padding-right 10px
}
}
}
</style>