index.js
2.43 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import urlAlias from '../url';
import request from '../request';
const {
category,
shopList,
search,
} = urlAlias;
let initData = {"name":"志平防蓝光-防辐射电脑网课眼镜","id":"9","imgurl":"",
"price":0,"trade_num":"102","rsSon":{"pic":"9_FDB33D.jpg","model_pic":null,"in_price":"6000","sku_value":"80_83",
"discount":"45","kc":"0","sku_name":"1.56非球面防蓝光_黑透+蓝纹","Max_Price":158,"Min_Price":99}}
var initArr = [1,2,3,4,5,6,7,8]
let list = []
initArr.forEach(function (value) {
list.push(initData)
});
//初始化数据是为了显示默认骨架
const state = {
categoryList: [],
list: list
};
const mutations = {
LIST: (state, list) => {
state.list = list;
},
CATEGORY: (state, categoryList) => {
state.categoryList = categoryList;
}
};
const actions = {
category({
commit
}, param) {
return new Promise((resolve) => request({
url: category,
success: (res) => {
let data = res.data.data;
for (let i = 0; i <= data.length; i++) {
if (data[i] && data[i].type !== 'filter') {
data[i].type = 'hierarchy';
}
}
data.unshift({
type: "hierarchy",
name: "全部",
value: "all",
isNoPull: true,
});
commit('CATEGORY', data);
resolve(data)
console.log('3333')
},
fail: (res) => {
console.log("fail status === > ", res);
}
}))
},
list({
commit
}, param) {
return new Promise((resolve) => request({
url: shopList,
success: (res) => {
commit('LIST', res.data.data)
resolve(res.data)
console.log('3333')
},
fail: (res) => {
console.log("fail status === > ", res);
},
complete: (res) => {
state.isLoading = false;
},
}))
},
search({
commit
}, {
params,
keyword
}) {
const uid = uni.getStorageSync('uid');
return new Promise((resolve) => request({
url: search,
data: {
params: JSON.stringify(params),
uid,
way: 1,
keyword,
},
success: (res) => {
commit('LIST', res.data.data);
resolve(res.data)
},
fail: (res) => {
console.log("fail status === > ", res);
}
}))
},
};
export default {
namespaced: true,
state,
mutations,
actions,
};