Authored by bevishuang

优化我的收藏

<template>
<LayoutApp :show-back="true" :title="title">
<Scroll :scrollEvents="['scroll']" :options="scrollOptions" @scroll="scroll"
<Scroll :scroll-events="['scroll-end','scroll']"
@scroll-end="fetchList"
v-if="favoriteProductList.list.length"
@pulling-up="onPullingUp">
>
<ProductList :list="favoriteProductList.list"></ProductList>
</Scroll>
<!-- <empty-list v-show="!isShowEmpty" /> -->
... ... @@ -42,20 +43,23 @@ export default {
this.fetchFavoriteList();
},
methods: {
...mapActions(['fetchFavoriteList','isShowEmpty']),
...mapActions(['fetchFavoriteList','isMore']),
async onPullingUp() {
await this.fetchFavoriteList();
async fetchList() {
if(isMore){
await this.fetchFavoriteList();
}
},
scroll({ y }) {
const height = this.$refs.banner.$el.offsetHeight + this.$refs.header.offsetHeight;
// scroll({ y }) {
// const height = this.$refs.banner.$el.offsetHeight + this.$refs.header.offsetHeight;
if (-y >= height) {
this.fixed = true;
} else {
this.fixed = false;
}
}
// if (-y >= height) {
// this.fixed = true;
// } else {
// this.fixed = false;
// }
// }
},
computed: {
... ...
import { get, set } from 'lodash';
import { getImgUrl } from '../../common/utils';
import Vue from 'vue';
const uid = '500031170';
// const uid = '500031170';
export default function() {
return {
... ... @@ -13,17 +13,23 @@ export default function() {
favoriteProductList: {
list:[]
},
isShowEmpty: false,
isMore: true,
},
mutations: {
addList(state, { data }) {
console.log(data)
if(data && data.product_list){
// data.product_list.
let { page, product_list = [] } = data;
let { page, product_list = [], pageTotal } = data;
let isShowEmpty = page === 1 && product_list === 0;
// console.log("isShowEmpty:"+isShowEmpty)
// state.isShowEmpty = isShowEmpty
if(pageTotal > page){
state.isMore = true;
}
state.pageTotal = pageTotal;
state.page = page + 1;
let list = state.favoriteProductList.list.concat(product_list);
Vue.set(state.favoriteProductList, "list", list);
}else {
... ... @@ -38,16 +44,21 @@ export default function() {
},
actions: {
async fetchFavoriteList({ commit }) {
const result = await this.$api.get('/api/ufo/home/favoriteProduct', {uid});
if (result.code === 200) {
let data =result.data;
commit('addList', { data:data });
}else {
// console.log("error=//=isShowEmpty:")
commit('errorData');
}
return result.data || [];
async fetchFavoriteList({ commit, state }) {
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 });
}else {
// console.log("error=//=isShowEmpty:")
commit('errorData');
}
return result.data || [];
// }else {
// return [];
// }
},
},
};
... ...
... ... @@ -84,6 +84,7 @@ module.exports = {
ufo: true,
api: 'ufo.user.favoriteList',
params: {},
auth: true,
},
'/api/ufo/channel/channelList': {
ufo: true,
... ...