|
@@ -2,22 +2,23 @@ import wx from '../../../utils/wx'; |
|
@@ -2,22 +2,23 @@ import wx from '../../../utils/wx'; |
2
|
import Yas from '../../../common/yas';
|
2
|
import Yas from '../../../common/yas';
|
3
|
import listModel from '../../../models/product/list';
|
3
|
import listModel from '../../../models/product/list';
|
4
|
|
4
|
|
5
|
-const {windowHeight} = getApp().getSystemInfo();
|
|
|
6
|
let yas;
|
5
|
let yas;
|
7
|
const app = getApp();
|
6
|
const app = getApp();
|
|
|
7
|
+const {windowHeight} = getApp().getSystemInfo();
|
8
|
|
8
|
|
9
|
Page({
|
9
|
Page({
|
10
|
data: {
|
10
|
data: {
|
11
|
order: '',
|
11
|
order: '',
|
12
|
gender: '',
|
12
|
gender: '',
|
13
|
- searched: false,
|
|
|
14
|
- productList: [],
|
|
|
15
|
- showLoading: false,
|
|
|
16
|
- showNoMore: false,
|
|
|
17
|
- currentPage: 0,
|
13
|
+
|
|
|
14
|
+ // 原始参数
|
|
|
15
|
+ orgOps: {},
|
|
|
16
|
+
|
|
|
17
|
+ page: 1,
|
|
|
18
|
+ limit: 20,
|
18
|
totalPage: 1,
|
19
|
totalPage: 1,
|
19
|
- urlParams: {},
|
|
|
20
|
- showBackTop: false,
|
20
|
+ allLoaded: false,
|
|
|
21
|
+ productList: [],
|
21
|
noResult: false,
|
22
|
noResult: false,
|
22
|
windowHeight
|
23
|
windowHeight
|
23
|
},
|
24
|
},
|
|
@@ -31,12 +32,7 @@ Page({ |
|
@@ -31,12 +32,7 @@ Page({ |
31
|
});
|
32
|
});
|
32
|
delete options.title;
|
33
|
delete options.title;
|
33
|
|
34
|
|
34
|
- options.shop_id = app.getShopId();
|
|
|
35
|
-
|
|
|
36
|
- this.setData({
|
|
|
37
|
- urlParams: options
|
|
|
38
|
- });
|
|
|
39
|
- this.productList(options);
|
35
|
+ this._productList();
|
40
|
|
36
|
|
41
|
yas = new Yas();
|
37
|
yas = new Yas();
|
42
|
yas.pageOpenReport();
|
38
|
yas.pageOpenReport();
|
|
@@ -54,38 +50,42 @@ Page({ |
|
@@ -54,38 +50,42 @@ Page({ |
54
|
});
|
50
|
});
|
55
|
},
|
51
|
},
|
56
|
onReachBottom: function() {
|
52
|
onReachBottom: function() {
|
57
|
- this.productList(this.data.urlParams);
|
53
|
+ this._productList();
|
58
|
},
|
54
|
},
|
59
|
- setBrandTitle: function(brandId) {
|
|
|
60
|
- listModel.brandIntro(brandId).then(res => {
|
|
|
61
|
- if (res.code === 200) {
|
|
|
62
|
- wx.setNavigationBarTitle({
|
|
|
63
|
- title: res.data.brand_name
|
|
|
64
|
- });
|
|
|
65
|
- }
|
|
|
66
|
- })
|
|
|
67
|
- .catch(() => {
|
|
|
68
|
- wx.setNavigationBarTitle({
|
|
|
69
|
- title: '商品列表'
|
|
|
70
|
- });
|
|
|
71
|
- });
|
55
|
+
|
|
|
56
|
+ // 筛选变更
|
|
|
57
|
+ filterChange: function(e) {
|
|
|
58
|
+ let {curSort, gender} = e.detail;
|
|
|
59
|
+
|
|
|
60
|
+ this.data.order = curSort;
|
|
|
61
|
+ this.data.gender = gender;
|
|
|
62
|
+
|
|
|
63
|
+ this._resetPage();
|
|
|
64
|
+ this.data.productList = [];
|
|
|
65
|
+ this._productList();
|
72
|
},
|
66
|
},
|
73
|
- productList: function(params = {}) {
|
|
|
74
|
- params.page = this.data.currentPage + 1;
|
|
|
75
|
|
67
|
|
76
|
- if (params.page > this.data.totalPage) {
|
|
|
77
|
- return;
|
|
|
78
|
- }
|
68
|
+ _resetPage: function() {
|
|
|
69
|
+ this.data.page = 1;
|
|
|
70
|
+ this.data.totalPage = 1;
|
|
|
71
|
+ this.data.allLoaded = false;
|
|
|
72
|
+ },
|
79
|
|
73
|
|
80
|
- if (this.data.isLoading) {
|
74
|
+ // 商品列表
|
|
|
75
|
+ _productList: function(params = {}) {
|
|
|
76
|
+ if (this.data.allLoaded) {
|
81
|
return;
|
77
|
return;
|
82
|
}
|
78
|
}
|
83
|
|
79
|
|
84
|
- this.data.isLoading = true;
|
|
|
85
|
- wx.showLoading({title: '加载中'});
|
80
|
+ this.setData({
|
|
|
81
|
+ showLoading: true
|
|
|
82
|
+ });
|
|
|
83
|
+
|
|
|
84
|
+ params.page = this.data.page;
|
|
|
85
|
+ params.limit = this.data.limit;
|
86
|
params.order = this.data.order;
|
86
|
params.order = this.data.order;
|
87
|
params.gender = this.data.gender;
|
87
|
params.gender = this.data.gender;
|
88
|
- params.limit = 20;
|
88
|
+ params.shop_id = app.getShopId();
|
89
|
listModel.productList(params).then(res => {
|
89
|
listModel.productList(params).then(res => {
|
90
|
if (res.code === 200) {
|
90
|
if (res.code === 200) {
|
91
|
const keyAdapter = {
|
91
|
const keyAdapter = {
|
|
@@ -106,35 +106,15 @@ Page({ |
|
@@ -106,35 +106,15 @@ Page({ |
106
|
list.push(item);
|
106
|
list.push(item);
|
107
|
});
|
107
|
});
|
108
|
|
108
|
|
109
|
- this.data.isLoading = false;
|
|
|
110
|
- wx.hideLoading();
|
109
|
+ this.data.page += 1;
|
|
|
110
|
+ this.data.totalPage = res.data && res.data.page_total || 1;
|
|
|
111
|
+
|
111
|
this.setData({
|
112
|
this.setData({
|
112
|
showLoading: false,
|
113
|
showLoading: false,
|
113
|
- productList: this.data.productList.concat(list),
|
|
|
114
|
- currentPage: params.page,
|
|
|
115
|
- totalPage: res.data.page_total,
|
|
|
116
|
- showNoMore: params.page === res.data.page_total,
|
|
|
117
|
- noResult: !this.data.productList.concat(list).length
|
|
|
118
|
- });
|
|
|
119
|
-
|
|
|
120
|
- if (params.resetScroll) {
|
|
|
121
|
- wx.pageScrollTo({
|
|
|
122
|
- scrollTop: 0,
|
|
|
123
|
- duration: 10
|
114
|
+ allLoaded: this.data.page > this.data.totalPage || params.limit > list.length,
|
|
|
115
|
+ productList: this.data.productList.concat(list)
|
124
|
});
|
116
|
});
|
125
|
}
|
117
|
}
|
126
|
- }
|
|
|
127
|
- });
|
|
|
128
|
- },
|
|
|
129
|
- sortChange: function(e) {
|
|
|
130
|
- let {curSort, gender} = e.detail;
|
|
|
131
|
-
|
|
|
132
|
- this.data.gender = gender;
|
|
|
133
|
- this.data.order = curSort;
|
|
|
134
|
- this.data.currentPage = 0;
|
|
|
135
|
- this.data.totalPage = 1;
|
|
|
136
|
-
|
|
|
137
|
- this.data.productList = [];
|
|
|
138
|
- this.productList(Object.assign({resetScroll: true}, this.data.urlParams));
|
118
|
+ }).catch(() => {});
|
139
|
}
|
119
|
}
|
140
|
}); |
120
|
}); |