index.js
6.64 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import api from '../../common/api';
import { parseProductListData } from '../../utils/productListUtil';
Page({
data:{
tabs:[
{
id:0,
name: "默认",
isShowIcon: false,
data:{},
},
{
id: 1,
name: "新品",
isShowIcon: false,
data:{},
},
{
id: 2,
name: "人气",
isShowIcon: false,
data:{},
},
{
id: 3,
name: "价格",
isShowIcon: true,
iconUrl: "../../images/arrow_normal@2x.png",
iconType: 1,
data:{},
},
{
id: 4,
name: "筛选",
isShowIcon: true,
iconUrl: "../../images/sx-ic-h@2x.png",
iconType: 1,
data:{},
}
],
activeIndex: 0,
contentWidth: 0,
contentHeight: 0,
isRefresh: false,
filterParams: {},
},
onLoad: function (option) {
try{
if(option){
let categoryId = option.categoryId || '';
let firstProductSkn = option.firstProductSkn || '';
let sort = option.sort ? option.sort : '';
let subCategoryId = option.subCategoryId || '';
let title = option.title || '';
let gender = option.gender || '';
console.log("categoryId:"+categoryId+"==subCategoryId:"+subCategoryId+"==sort:"+sort+"==firstProductSkn:"+firstProductSkn);
this.data.categoryId = categoryId;
this.data.subCategoryId = subCategoryId;
this.data.sort = sort;
this.data.firstProductSkn = firstProductSkn;
this.data.title = title;
this.data.gender = gender;
tt.setNavigationBarTitle({
title: title
});
}
let systemInfo = tt.getSystemInfoSync();
let contentWidth = systemInfo.screenWidth;
// let contentWidth = screenWidth;
let contentHeight = systemInfo.windowHeight - 44;
this.setData({
contentWidth,
contentHeight,
})
}catch(e){
console.log(e.message)
}
let tab = this.data.tabs[0];
// let filterParams = this.data.filterParams;
this.fechProductList(tab,1);
// this.fechFilter();
},
onShow: function () {
if(this.data.isRefresh){
let filter = this.data.filter;
if(filter){
for(var i = 0; i < filter.length; i++){
let filterItem = filter[i];
let itemId = filterItem.filterId;
let selectedIdParam = filterItem.selectedIdParam;
if(selectedIdParam){
this.data.filterParams[itemId] = selectedIdParam;
}
}
let current = this.data.activeIndex
let tab = this.data.tabs[current];
this.fechProductList(tab,1);
}
}
},
onTabClick: function (e) {
//获取到点击当前Tab的信息
let tab = e.detail;
let currentIndex = tab.id
if(currentIndex === 4){
tt.navigateTo({
url: 'pages/productListFilter/filter?sort=116&subCategoryId=48&categoryId=5&firstProductSkn=51987592',
success (res) {
console.log(`${res}`);
},
fail (res) {
console.log("navigateTo调用失败");
}
});
}else {
let tabData = this.data.tabs[currentIndex].data;
let page = 1;
if(tabData && tabData.page){
page = tabData.page;
}
this.fechProductList(tab, page);
}
},
fechProductList: function (tab, currentPage) {
let filterParams = this.data.filterParams;
let id = tab.id;
let orderType = tab.iconType;
let iconUrl = tab.iconUrl;
let order = "";
//设置是否显示加载中
let thatTabs = this.data.tabs;
thatTabs[id].showLoadMoreView = true;
this.setData({
tabs: thatTabs,
});
if(id === 1){
order = "s_t_desc";
}else if(id === 2){
order = "h_v_desc";
}else if(id === 3){
if(orderType && orderType === 1){
order= "s_p_desc";
}else{
order= "s_p_asc";
}
}else {
order = "";
}
let that = this;
// that.data.tabs.activeIndex = id;
let sort = that.data.sort;
let categoryId = that.data.categoryId;
let subCategoryId = that.data.subCategoryId;
let firstProductSkn = that.data.firstProductSkn;
let title = that.data.title;
let gender = that.data.gender;
let param = {
method: "app.search.category",
firstProductSkn: firstProductSkn,
order,
gender,
limit: 60,
page: currentPage,
sort: sort,
categoryId,
subCategoryId,
title
}
let params = Object.assign(filterParams, param);
api.get({data: params})
.then(data => {
let listData = data.data;
let productList = listData.product_list;
// let tab = that.tabs[0]
// tab.data = data;
let tabs = that.data.tabs;
for (var index in productList) {
let skn = productList[index].product_skn;
let name = productList[index].product_name;
// console.log("name:"+name+"==skn:"+skn)
}
productList = parseProductListData(productList);
listData.product_list = productList;
tabs[id].showLoadMoreView = false;
let isRefresh = this.data.isRefresh;
if(isRefresh){
tabs[id].data = listData;
}else {
if(tabs[id].data && tabs[id].data.product_list){
tabs[id].data.page = listData.page;
tabs[id].data.product_list = tabs[id].data.product_list.concat(productList);
}else {
tabs[id].data = listData;
}
}
// tablist[id].iconType = orderType;
// tablist[id].iconUrl = iconUrl;
// console.log("id:"+id)
console.log('====================================');
console.log(tabs);
console.log('====================================');
that.setData({
tabs: tabs,
activeIndex: id,
});
});
},
onLoadMore: function () {
let current = this.data.activeIndex
let tab = this.data.tabs[current];
let page = tab.data.page + 1;
let totalPage = tab.data.page_total;
if(page < totalPage){
this.fechProductList(tab,page);
}
},
})