Authored by Tao

add news

... ... @@ -73,12 +73,39 @@ export default {
active: 0,
listBaseParams: {
isHome: true,
}
},
productList: {
showErrorPage: false,
isFetching: false,
error: null,
page: 0, // 当前页
page_size: 10, // 每页数量
page_total: 0, // 总共多少页
total: 0, // 总共多少条
endReached: false, // 到达底部
list: [], // 商品列表
isEmpty: false,
},
searchParams: {
type: 0, // type:0,推荐;1,热销;2,即将发售; 3,品类; 4,品牌;5,系列;6,搜索 7, 收藏
order: '', // 指定排序
productPool: null, // 商品池id
sort: null, // 品类id
brand: null, // 品牌id
series: null, // 系列id
gender: null, // 性别
size: null, // 尺码id
isSoonSale: null, // 是否是即将售卖
query: null, // 搜索词
limit: null, // 每页记录数
page: null, // 当前页号
coupon_token: null, // 优惠券token
},
};
},
computed: {
...mapState(['channelList']),
...mapStateList(['productList']),
navList() {
return get(find(this.channelList.list, ['template_name', 'guessLike']), 'data') || [];
}
... ... @@ -128,17 +155,67 @@ export default {
let str = get(get(this.navList, `[${index}].url`, '').split('?'), '[1]', '');
this.params = Object.assign({}, queryString.parse(str), this.listBaseParams);
this.fetchProductList(this.params);
this.fetchList(this.params);
},
async onPullingUp() {
if (this.params) {
this.params.isReset = false
await this.fetchProductList(this.params);
await this.fetchList();
},
// 查询商品列表
fetchList: async function(params) {
let searchParams = this.searchParams;
let list = this.productList;
let pageSize = list.page_size;
let isReset = false;
if (params && params.isReset) {
isReset = true;
delete params.isReset;
}
if (!isReset && (list.endReached || (!list.endReached && list.page_total === 1))) {
return;
}
if (typeof params === 'object' && Object.keys(params)) {
searchParams = Object.assign({...searchParams}, params);
this.searchParams = searchParams;
}
let page = isReset ? 1 : (list.page + 1);
for (let key in searchParams) {
if (!searchParams[key]) {
delete searchParams[key];
}
}
let result = await this.fetchProductList({
...searchParams,
page,
pageSize
});
let {data} = result;
if (result.code === 200) {
data.endReached = (data.page === data.page_total) && (data.page_size !== 1);
}
if (typeof data === 'object' && Object.keys(data).length) {
for (let key in data) {
if (key === 'product_list') {
list.list = data.page > 1 ? list.list.concat(data.product_list) : data.product_list;
} else {
list[key] = data[key];
}
}
this.productList = list;
}
},
onPullingDown() {
this.params.isReset = true
this.fetchProductList(this.params);
this.params.isReset = true;
this.fetchList(this.params);
},
},
components: {
... ...