index.js
1.44 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
import actions from './actions';
import mutations from './mutations';
import { get } from 'lodash';
export default function() {
return {
namespaced: true,
state: {
products: {
byId: {},
},
currentId: null,
/**
* 用户在商品详情页选择的交易信息
* productId: 商品id
* product: 商品详情
* sizeId: 尺寸id
* size: 尺寸信息
* tradeTypeId: 交易类型id
* tradeType: 交易类型
*/
selectedProductInfo: {
productId: null,
product: {},
sizeId: null,
storageId: null,
size: {},
tradeTypeId: null,
tradeType: {},
},
},
mutations,
actions,
getters: {
productDetail(state) {
return state.products.byId[state.currentId] || {};
},
imageList(state, getters) {
return get(getters.productDetail, 'goods_list[0].image_list', []);
},
resource(state, getters) {
return get(getters.productDetail, 'resource', {});
},
activity(state, getters) {
return get(getters.productDetail, 'activity', []);
},
recommend(state, getters) {
const list = get(getters.productDetail, 'recommend', []);
if (list && list.length !== 0) {
return list;
}
return null;
},
selectedSize(state) {
return state.selectedProductInfo.size;
}
}
};
}