goodsList.js
2.94 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
import wx from '../../utils/wx';
import Yas from '../../common/yas';
import listModel from '../../models/product/list';
let yas;
const app = getApp();
Page({
data: {
order: '',
gender: '',
// 原始参数
orgOps: {},
page: 1,
limit: 20,
totalPage: 1,
allLoaded: false,
productList: [],
totalZero: false,
windowHeight: 0
},
onLoad: function(options) {
Object.keys(options).map(key => {
options[key] = decodeURIComponent(options[key] || '');
});
wx.setNavigationBarTitle({
title: options.title || ''
});
delete options.title;
this.data.orgOps = options;
this._productList();
yas = new Yas();
yas.pageOpenReport();
},
onReady: function() {
wx.getSystemInfo().then(({windowHeight}) => {
this.setData({
windowHeight
});
});
},
onPageScroll: function({scrollTop}) {
if (scrollTop > this.data.windowHeight * 2 !== this.data.showBackTop) {
this.setData({
showBackTop: scrollTop > this.data.windowHeight * 2
});
}
},
backTop: function() {
wx.pageScrollTo({
scrollTop: 0
});
},
onReachBottom: function() {
this._productList();
},
// 筛选变更
filterChange: function(e) {
let {curSort, gender} = e.detail;
this.data.order = curSort;
this.data.gender = gender;
this.data.addFilter = true;
this._resetPage();
this.setData({
productList: []
});
this._productList();
},
_resetPage: function() {
this.data.page = 1;
this.data.totalPage = 1;
this.data.allLoaded = false;
},
// 商品列表
_productList: function(params = {}) {
if (this.data.allLoaded) {
return;
}
this.setData({
loading: true
});
Object.assign(params, this.data.orgOps, {
page: this.data.page,
limit: this.data.limit
});
if (this.data.addFilter) {
params.order = this.data.order;
params.gender = this.data.gender;
}
params.shop_id = app.getShopId();
listModel.categoryProductList(params).then(res => {
if (res.code === 200) {
const keyAdapter = {
skn: 'product_skn',
salesPrice: 'sales_price',
marketPrice: 'market_price',
productName: 'product_name',
defaultImages: 'default_images'
};
let list = [];
(res.data.product_list || []).forEach(product => {
let item = {};
Object.keys(keyAdapter).forEach(key => {
item[key] = product[keyAdapter[key]];
});
list.push(item);
});
this.data.page += 1;
this.data.totalPage = res.data && res.data.page_total || 1;
this.setData({
loading: false,
allLoaded: this.data.page > this.data.totalPage,
productList: this.data.productList.concat(list),
totalZero: this.data.productList.concat(list).length === 0
});
}
}).catch(() => {});
}
});