Authored by bevishuang

优化我的收藏

... ... @@ -90,6 +90,7 @@ export default {
if(key){
query[key] = item.link;
}
query.title = item.name;
// console.log('===category=='+key);
this.$router.push({
... ...
<template>
<LayoutApp :show-back="true" :title="title">
<Scroll :scroll-events="['scroll-end','scroll']"
<Scroll
ref="scrolllist"
:scroll-events="['scroll-end','scroll']"
@scroll-end="fetchList(isMore)"
v-if="favoriteProductList.list.length"
class="fav-scroll-bg"
>
<ProductList :list="favoriteProductList.list"></ProductList>
</Scroll>
... ... @@ -29,6 +32,23 @@ export default {
},
data() {
return {
scrollToY: -200,
scrollToTime: 700,
scrollToEasing: 'bounce',
scrollToEasingOptions: [
{
text: 'bounce',
value: 'bounce'
},
{
text: 'swipe',
value: 'swipe'
},
{
text: 'swipeBounce',
value: 'swipeBounce'
}
],
title: '我的收藏',
scrollOptions: {
bounce: {
... ... @@ -39,15 +59,39 @@ export default {
fixed: false
};
},
mounted() {
this.fetchFavoriteList();
// mounted() {
// this.fetchFavoriteList();
// },
activated(){
console.log('favorite====activated')
let params = {
isReset: true,
};
this.fetchFavoriteList({isReset: true});
// this.scrollToTop();
},
methods: {
...mapActions(['fetchFavoriteList']),
scrollToTop() {
// let height = this.$refs.scroll.scrollHeight
console.log(this.$refs)
console.log(this.$refs.scrolllist)
this.$refs.scroll.scrollTo(
0,
this.scrollToY,
this.scrollToTime,
ease[this.scrollToEasing]
)
},
async fetchList(isMore) {
if(this.isMore){
await this.fetchFavoriteList();
let params = {
isReset: false,
};
await this.fetchFavoriteList({isReset: false});
}
},
... ... @@ -69,4 +113,7 @@ export default {
</script>
<style scoped>
.fav-scroll-bg {
background-color: #f5f5f5;
}
</style>
... ...
... ... @@ -16,7 +16,7 @@ export default function() {
isMore: false,
},
mutations: {
addList(state, { data }) {
addList(state, { data, isReset }) {
console.log(data)
if(data && data.product_list){
// data.product_list.
... ... @@ -33,10 +33,15 @@ export default function() {
}else {
state.isMore = false;
}
let list = state.favoriteProductList.list.concat(product_list);
Vue.set(state.favoriteProductList, "list", list);
if(isReset) {
state.favoriteProductList.list = product_list
}else {
let list = state.favoriteProductList.list.concat(product_list);
Vue.set(state.favoriteProductList, "list", list);
}
}else {
// state.isShowEmpty = true;
}
... ... @@ -49,13 +54,23 @@ export default function() {
},
actions: {
async fetchFavoriteList({ commit, state }) {
let page = state.page;
async fetchFavoriteList({ commit, state }, {isReset}={} ) {
console.log('...params')
// console.log(...params)
// let { isReset } = params;
console.log('===:'+isReset)
let page = 1
if(isReset){
page = 1
}else {
page = state.page;
}
// let page = state.page;
let limit = 20;
const result = await this.$api.get('/api/ufo/home/favoriteProduct', {page, limit});
if (result.code === 200) {
let data =result.data;
commit('addList', { data:data });
commit('addList', { data, isReset });
}else {
// console.log("error=//=isShowEmpty:")
commit('errorData');
... ...