|
|
import {get} from 'lodash';
|
|
|
import Vue from 'vue';
|
|
|
|
|
|
export default function() {
|
|
|
return {
|
...
|
...
|
@@ -19,7 +18,7 @@ export default function() { |
|
|
},
|
|
|
searchParams: {
|
|
|
type: 0, // type:0,推荐;1,热销;2,即将发售; 3,品类; 4,品牌;5,系列;6,搜索 7, 收藏
|
|
|
order: null, // 指定排序
|
|
|
order: 'sale_desc', // 指定排序
|
|
|
productPool: null, // 商品池id
|
|
|
sort: null, // 品类id
|
|
|
brand: null, // 品牌id
|
...
|
...
|
@@ -43,25 +42,83 @@ export default function() { |
|
|
},
|
|
|
mutations: {
|
|
|
addProductList(state, {data}) {
|
|
|
Vue.set(state.productList, 'list', state.productList.list.concat(data.product_list));
|
|
|
Vue.set(state.productList, 'page', data.page);
|
|
|
let {productList} = state;
|
|
|
|
|
|
if (typeof data === 'object' && Object.keys(data).length) {
|
|
|
for (let key in data) {
|
|
|
if (key === 'product_list') {
|
|
|
productList.list = data.page > 1 ? productList.list.concat(data.product_list) : data.product_list;
|
|
|
} else {
|
|
|
productList[key] = data[key];
|
|
|
}
|
|
|
}
|
|
|
state.productList = productList;
|
|
|
}
|
|
|
},
|
|
|
setSearchParams(state, {params}) {
|
|
|
state.searchParams = Object.assign(state.searchParams, params);
|
|
|
},
|
|
|
addFilterData(state, {filter}) {
|
|
|
state.filterData = filter;
|
|
|
}
|
|
|
},
|
|
|
actions: {
|
|
|
async fetchProductList({commit, state}) {
|
|
|
let page = state.productList.page;
|
|
|
let size = state.productList.page_size;
|
|
|
const result = await this.$api.get('/api/ufo/list/productList', {
|
|
|
page: page + 1,
|
|
|
size: size
|
|
|
fetchProductList: async function({commit, state}, params) {
|
|
|
let searchParams = state.searchParams;
|
|
|
let list = state.productList;
|
|
|
let pageSize = list.page_size;
|
|
|
let isReset = false;
|
|
|
|
|
|
if (params && params.isReset) {
|
|
|
isReset = true;
|
|
|
delete params.isReset;
|
|
|
}
|
|
|
if (params && Object.keys(params).length) {
|
|
|
searchParams = Object.assign(searchParams, params);
|
|
|
commit('setSearchParams', {params: searchParams});
|
|
|
}
|
|
|
|
|
|
if (!isReset && (list.endReached || (!list.endReached && list.page_total === 1))) {
|
|
|
return;
|
|
|
}
|
|
|
let page = isReset ? 1 : (list.page + 1);
|
|
|
|
|
|
for (let key in searchParams) {
|
|
|
if (!searchParams[key]) {
|
|
|
delete searchParams[key];
|
|
|
}
|
|
|
}
|
|
|
let result = await this.$api.get('/api/ufo/list/productList', {
|
|
|
...searchParams,
|
|
|
page,
|
|
|
pageSize
|
|
|
});
|
|
|
|
|
|
if (result.code === 200) {
|
|
|
commit('addProductList', {data: result.data});
|
|
|
let {data} = result;
|
|
|
|
|
|
data.endReached = (data.page === data.page_total) && (data.page_size !== 1);
|
|
|
commit('addProductList', {data});
|
|
|
}
|
|
|
|
|
|
return result.data ? result.data.length : 0;
|
|
|
},
|
|
|
},
|
|
|
fetchFilterData: async function({commit, state}) {
|
|
|
let searchParams = state.searchParams;
|
|
|
|
|
|
for (let key in searchParams) {
|
|
|
if (!searchParams[key]) {
|
|
|
delete searchParams[key];
|
|
|
}
|
|
|
}
|
|
|
let result = await this.$api.get('/api/ufo/list/filterData', {...searchParams});
|
|
|
|
|
|
if (result.code === 200) {
|
|
|
let {data} = result;
|
|
|
|
|
|
commit('addFilterData', {filter: data.filter});
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
} |
...
|
...
|
|