deming/pageB/comment/index.vue

123 lines
2.9 KiB
Vue
Raw Normal View History

2020-07-24 11:48:57 +00:00
<template>
2020-07-27 09:59:47 +00:00
<scroll-view scroll-y class="comment" @scrolltolower="loadMore">
2020-07-24 11:48:57 +00:00
<view class="label-list">
2020-07-25 07:17:52 +00:00
<view v-for="(label, index) in evaluateSpec" :key="index" :class="{'active': current == index}" @click="current=index">{{ index + '(' + label + '}' }}</view>
2020-07-24 11:48:57 +00:00
</view>
<view class="comment-container">
<view v-for="(item, index) in evalueList" :key="index" class="itme">
<comment :reply="true" :content="item"></comment>
</view>
<u-empty text="暂无评论" mode="list" v-if="!evalueList.length" margin-top="120" color="#333"></u-empty>
</view>
2020-07-27 09:59:47 +00:00
<!-- 加载更多 -->
<u-loadmore :status="loadStatus" bgColor="#EEEBEE" margin-top="20" margin-bottom="20" v-if="evalueList.length >= 12"></u-loadmore>
</scroll-view>
2020-07-24 11:48:57 +00:00
</template>
<script>
import comment from "@/components/comment/index";
export default {
data() {
return {
2020-07-25 07:17:52 +00:00
id: Number,
current: '全部',
2020-07-24 11:48:57 +00:00
page: 0,
evalueList: [],
2020-07-25 07:17:52 +00:00
evaluateSpec: {},
2020-07-27 09:59:47 +00:00
loadStatus: 'loadmore',
timer: true,
2020-07-24 11:48:57 +00:00
}
},
components: {
comment
},
onLoad(option) {
2020-07-25 07:17:52 +00:00
this.id = option.id;
// this.getAllEvalue();
this.getEvaluateSpec();
},
watch: {
current(value) {
2020-07-27 09:59:47 +00:00
this.page = 0;
this.getAllEvalue({ type: value });
2020-07-25 07:17:52 +00:00
}
2020-07-24 11:48:57 +00:00
},
methods: {
2020-07-27 09:59:47 +00:00
loadMore() {
if(this.evalueList.length < 12) return false;
if(!this.timer) return false;
this.loadStatus = "loading";
this.page++;
this.getAllEvalue({ type: this.current, load: 'more' }).then(length => {
if(length == 0) {
this.page--;
this.loadStatus = 'nomore';
} else {
this.loadStatus = 'loading';
}
}).catch(() => {
this.loadStatus = "nomore";
this.page--;
})
},
2020-07-25 07:17:52 +00:00
getEvaluateSpec() {
this.$u.api.getEvaluateSpec({
2020-07-27 09:59:47 +00:00
id: this.id,
2020-07-24 11:48:57 +00:00
}).then(res => {
2020-07-25 07:17:52 +00:00
if(res.errCode == 0) {
this.evaluateSpec = res.data;
this.getAllEvalue();
}
})
},
2020-07-27 09:59:47 +00:00
async getAllEvalue({ type, load } = {}) {
2020-07-25 07:17:52 +00:00
let params = {
goods_id: this.id,
page: this.page,
}
if(type) Object.assign(params, { type: type });
2020-07-27 09:59:47 +00:00
const res = await this.$u.api.getAllEvalue(params);
if (res.errCode == 0) {
if(load) this.evalueList.push(...res.data);
else this.evalueList = res.data;
} else {
this.evalueList = [];
}
return res.data.length;
2020-07-24 11:48:57 +00:00
}
}
};
</script>
<style lang="scss" scoped>
.comment {
height: calc(100vh - var(--window-top));
background-color: #EEEBEE;
padding-bottom: 30rpx;
.label-list {
padding: 30rpx;
background-color: #ffffff;
margin-bottom: 14rpx;
display: flex;
flex-wrap: wrap;
> view {
box-sizing: content-box;
padding: 16rpx 20rpx;
border-radius: 30rpx;
margin: 0 20rpx 20rpx 0;
background: rgba(236,236,236,1);
font-size: 26rpx;
color: rgba(153,153,153,1);
}
.active {
background: rgba(255,120,15,1);
color: #ffffff;
}
}
.comment-container {
.itme {
padding: 30rpx;
background-color: #ffffff;
margin-bottom: 10rpx;
}
}
}
</style>