collectCarSearch.js
6.12 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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
const WXRequest = require('../../utils/wxrequest.js');
Page({
data: {
inputVal: '',
searchTypes: [{
label: '申请单号',
value: 'sqbh'
},{
label: '车架号',
value: 'standno'
},{
label: '设备号',
value: 'sn'
},{
label: '姓名',
value: 'name'
}],
placeholders: [
'请输入完整的申请单号',
'请输入车架号后六位',
'请输入设备SN',
'请输入客户姓名'
],
searchTypesIndex: 0,
list: [],
scrollTop: 0,
scrollHeight: 300,
page: 1,
maxPage: 0,
ing: false,
initSearch: false,
userStatus: ''
},
onLoad() {
var that = this;
wx.getSystemInfo({
success: function(res) {
that.setData({
scrollHeight: res.windowHeight-50
})
}
});
that.setData({
userStatus: wx.getStorageSync('userStatus')
});
that.loadData(true);
},
clearInput: function () {
this.setData({
inputVal: ""
});
},
inputTyping: function (e) {
this.setData({
inputVal: e.detail.value
});
},
searchConfirm(e){
this.setData({
ing: false,
page: 1,
scrollTop: 0
});
this.loadData();
},
loadData(isInit, isPullDown){
var that = this;
if(!isInit && !that.validate()) return;
that.setData({
ing: true
});
let params = {};
if(isInit){
params = {
pageSize: 50,
currentPage: 1
}
that.setData({
page: 5
})
}else{
params = {
pageSize: 10,
currentPage: that.data.page
}
params[that.data.searchTypes[that.data.searchTypesIndex].value] = that.data.inputVal;
}
if(that.data.userStatus === 0){
WXRequest.get('vehiclecollection/getList',params).then((res)=>{
if(!that.data.ing) return;
const _list = res.data;
const maxPage = Math.ceil(res.recordsTotal/10);console.log(maxPage)
if(_list){
/*_list.forEach((item)=>{
const deviceObj = {}
item.device&&item.device.forEach((deviceItem)=>{
if(!deviceObj[deviceItem.type]){
deviceObj[deviceItem.type] = [];
}
deviceObj[deviceItem.type].push(deviceItem.sn);
});
item.deviceList = [];
for(let type in deviceObj){
item.deviceList.push({
type,
sns: deviceObj[type]
});
}
});*/
that.setData({
list: that.data.page===1?_list:that.data.list.concat(_list),
ing: false,
maxPage,
initSearch: true
});
}else{
that.setData({
list: [],
ing: false,
maxPage
});
}
if(isPullDown){
wx.hideNavigationBarLoading() //完成停止加载
wx.stopPullDownRefresh();
}
});
}else if(that.data.userStatus === 1){
WXRequest.get('vehiclecollection/getListNoRole',params).then((res)=>{
if(!that.data.ing) return;
const _list = res.data;
const maxPage = Math.ceil(res.recordsTotal/10);console.log(maxPage)
if(_list){
/*_list.forEach((item)=>{
const deviceObj = {}
item.device&&item.device.forEach((deviceItem)=>{
if(!deviceObj[deviceItem.type]){
deviceObj[deviceItem.type] = [];
}
deviceObj[deviceItem.type].push(deviceItem.sn);
});
item.deviceList = [];
for(let type in deviceObj){
item.deviceList.push({
type,
sns: deviceObj[type]
});
}
});*/
that.setData({
list: that.data.page===1?_list:that.data.list.concat(_list),
ing: false,
maxPage,
initSearch: true
});
}else{
that.setData({
list: [],
ing: false,
maxPage
});
}
if(isPullDown){
wx.hideNavigationBarLoading() //完成停止加载
wx.stopPullDownRefresh();
}
});
}
},
searchTypeChange(e){
this.setData({
searchTypesIndex: e.detail.value
});
if(!this.data.inputVal) return;
this.setData({
ing: false,
page: 1,
scrollTop: 0
});
this.loadData()
},
bindDownLoad(){
if(this.data.ing) return;
const nextPage = this.data.page+1;
if(nextPage>this.data.maxPage) return;
this.setData({
page: nextPage
});
this.loadData();
},
bindScroll(){
},
validate(){
const type = this.data.searchTypes[this.data.searchTypesIndex].value;
const inputVal = this.data.inputVal;
if(type === 'name'){//姓名
if(inputVal.length<2){
wx.showModal({
content: '请输入正确的姓名,至少2位数',
showCancel: false
});
return false;
}
}else if(inputVal.length<6){
wx.showModal({
content: '请输入至少6位数',
showCancel: false
});
return false;
}
return true;
},
redirectDetail(e){
if(this.data.userStatus !== 0) return;
if(e.target.dataset.type === 'user'){
const dataset = e.target.dataset;
wx.navigateTo({
url: `../../pages/collectCarLog/collectCarLog?id=${dataset.id}&nickname=${dataset.nickname}&avatarurl=${dataset.avatarurl}`
});
}else{
const dataset = e.currentTarget.dataset;
wx.navigateTo({
url: `../../pages/collectCarDetail/collectCarDetail?vehicleid=${dataset.vehicleid}&name=${dataset.name}&standno=${dataset.standno}&wiredSn=${dataset.wiredsn}&wiredlessSn=${dataset.wiredlesssn}&sqbh=${dataset.sqbh}`
});
}
},
redirectUserDetail(e){
const dataset = e.currentTarget.dataset;
//console.log(e.currentTarget)
},
onPullDownRefresh: function () {
this.setData({
ing: false,
page: 1,
scrollTop: 0,
list: []
});
this.loadData(true, true);
}
})