favorite.js
1.91 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
import { get, set } from 'lodash';
import { getImgUrl } from '../../common/utils';
import Vue from 'vue';
// const uid = '500031170';
export default function() {
return {
namespaced: true,
state: {
page: 1,
pageTotal: 0,
recId: '',
favoriteProductList: {
list:[]
},
isMore: false,
},
mutations: {
addList(state, { data }) {
console.log(data)
if(data && data.product_list){
// data.product_list.
let { page, product_list = [], page_total } = data;
// let isShowEmpty = page === 1 && product_list === 0;
// console.log("isShowEmpty:"+isShowEmpty)
// state.isShowEmpty = isShowEmpty
if(page_total > page){
console.log('======'+page_total+"///"+page)
state.isMore = true;
state.pageTotal = page_total;
state.page = page + 1;
console.log(state)
}else {
state.isMore = false;
}
let list = state.favoriteProductList.list.concat(product_list);
Vue.set(state.favoriteProductList, "list", list);
}else {
// state.isShowEmpty = true;
}
},
errorData(state){
// console.log("error==isShowEmpty:")
state.isShowEmpty = true;
}
},
actions: {
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 [];
// }
},
},
};
}