setting.js
10.7 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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
const requestapi = require("../restapi.js")
var app = getApp();
const hh = []
const mm = []
for (let i = 1; i <= 24; i++) {
let num = i
if (i < 10) num = `0${i}`
if (i == 24) num = '00'
hh.push(num)
}
for (let i = 0; i < 60; i++) {
let num = i
if (i < 10) num = `0${i}`
mm.push(num)
}
// 防抖
const debounce = (fun, wait) => {
let timer
return () => {
clearTimeout(timer)
timer = setTimeout(fun, wait)
}
}
Page({
/**
* 页面的初始数据
*/
data: {
pickerItem: [{
name: 'start',
value: [20, 0],
num:["21","00"]
},
{
name: 'end',
value: [7, 0],
num: ["08", "00"]
}
],
hh,
isNum: null,
letterHeight: 0,
height: 0,
mm,
day: '每天',
list: true,
date: true,
select: [{
value: '每天',
active: true,
week_day: '1,2,3,4,5,6,7'
},
{
value: '周一至周五',
active: false,
week_day: '1,2,3,4,5'
},
{
value: '周末',
active: false,
week_day: '6,7'
},
{
value: '自定义',
active: false,
week_day: ''
}
],
dateList: [{
value: '周一',
active: false,
week_day: '1'
},
{
value: '周二',
active: false,
week_day: '2'
},
{
value: '周三',
active: false,
week_day: '3'
},
{
value: '周四',
active: false,
week_day: '4'
},
{
value: '周五',
active: false,
week_day: '5'
},
{
value: '周六',
active: false,
week_day: '6'
},
{
value: '周日',
active: false,
week_day: '7'
}
],
cloudSecurityInfo:""
},
change(e) {
let value = e.detail.value
let index = e.currentTarget.dataset.index
this.setData({
[`pickerItem[${index}].value`]: value,
[`pickerItem[${index}].num`]: [this.data.hh[value[0]], this.data.mm[value[1]]]
})
//开始时间和结束时间不能相等
var pick = this.data.pickerItem;
if (pick[0].value[0] == pick[1].value[0] && pick[0].value[1] == pick[1].value[1]){
app.showMessage("开始时间和结束时间不能设置成一样的!");
}
console.log(this.data.pickerItem)
},
// 显示删除框
del() {
wx.showModal({
title: '温馨提示',
content: '确定删除此提醒吗?',
confirmColor: '#007AFF',
success: res => {
console.log(res)
if (res.confirm) {
var obj = this.data.cloudSecurityInfo;
//执行删除操作
requestapi.deleteCloudSecurity(obj.userId,obj.group,function(response){
console.log(response);
if (response.returnCode != "0"){
app.showMessage(response.message);
}else{
wx.navigateBack({
delta: 1,
})
}
})
}
}
})
},
// 显示防盗周期
showList() {
this.setData({
list: false,
select: this.setDay()
})
},
// 关闭防盗周期
closeList() {
this.setData({
list: true
})
},
// 选中周期
choose(e) {
let index = e.currentTarget.dataset.index
let value = e.currentTarget.dataset.value
let dateList = this.data.dateList
if (index == 3) {
let week = this.data.select[3].week_day !== '' ? this.data.select[3].week_day.split(',') : []
dateList.forEach(el => {
el.active = false
if (week.length > 1) {
week.forEach(e => {
if (el.week_day == e) {
el.active = true
}
})
} else if (week.length > 0) {
dateList[week - 1].active = true
}
})
this.setData({
date: false,
dateList: dateList
})
this.setListHeight()
} else {
dateList.forEach(e => e.active = false)
this.setData({
day: value,
dateList: dateList,
['select[3].week_day']: ''
})
}
this.setData({
select: this.setDay(),
list: true
})
},
// 自定义
chooseDay(e) {
let index = e.currentTarget.dataset.index
this.changeDay(index)
},
changeDay(index) {
this.setData({
[`dateList[${index}].active`]: !this.data.dateList[index].active,
isNum: index
})
},
// 自定义确定
confirm() {
let arr = []
let value = []
this.data.dateList.forEach(e => {
if (e.active) {
value.push(e.value)
arr.push(e.week_day)
}
})
if (arr.length > 0) {
let day = value.join('\t')
this.data.select.forEach(e => e.active = false)
this.setData({ select: this.data.select })
if (arr.length > 1) {
if (arr[0] == '1' && arr[arr.length - 1] == '5') {
day = '周一至周五'
this.setData({ [`select[1].active`]: true })
arr = ''
} else if (arr.length == 7) {
day = '每天'
this.setData({ [`select[0].active`]: true })
arr = ''
} else {
this.setData({ ['select[3].active']: true })
}
} else if (arr[0] == '6' && arr[1] == "7") {
day = "周末"
arr = ''
this.setData({ ['select[2].active']: true })
} else {
this.setData({ ['select[3].active']: true })
}
this.setData({
date: true,
day: day,
['select[3].week_day']: arr.length > 0 ? arr.join(',') : arr
})
} else {
wx.showToast({
title: '至少选中一项!',
icon: 'none'
})
}
},
// 自定义取消
cancel() {
this.data.dateList.forEach(e => {
e.active = false
})
this.setData({
date: true,
dateList: this.data.dateList,
select: this.setDay()
})
},
setDay() {
let arr = this.data.select
arr.forEach(e => {
e.active = false
if (e.value == this.data.day) {
e.active = true
} else if (this.data.day !== '每天' && this.data.day !== '周一至周五' && this.data.day !== "周末") {
arr[3].active = true
}
})
return arr
},
move(e) {
let y = e.touches[0].clientY
let num = parseInt((y - this.data.height) / this.data.letterHeight)
if (y > this.data.height && this.data.isNum != num && num < this.data.dateList.length) debounce(this.changeDay(num), 1000 / 60)
},
setListHeight() {
setTimeout(() => {
let query = wx.createSelectorQuery().in(this)
query.select(`#check-0`).boundingClientRect(res => {
this.setData({
height: res.top,
letterHeight: res.height
})
}).exec()
}, 600)
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
console.log(options);
let userId = options.userId
this.setData({
"cloudSecurityInfo.userId": userId
})
if (options.group) {
let startTime = options.startTime
let endTime = options.endTime
let group = options.group
let weekDayStr = options.weekDayStr
let mobile = options.mobile
this.setData({
"cloudSecurityInfo.startTime": startTime,
"cloudSecurityInfo.endTime": endTime,
"cloudSecurityInfo.group": group,
"cloudSecurityInfo.weekDayStr": weekDayStr,
"cloudSecurityInfo.mobile": mobile
})
this.updateInitTime(startTime, endTime)
this.updateInitWeek(weekDayStr)
}
},
//点击保存
saveSecurityInfo() {
this.saveTime();
},
//设置需要更新的时间
updateInitTime(startTime, endTime) {
//开始时间
let sta = startTime.split(":")
let en = endTime.split(":")
let staHour = sta[0]
if (staHour == "00") {
staHour = 24
} else {
staHour--
}
let staMin = sta[1]
//结束时间
let enHour = en[0]
if (enHour == "00") {
enHour = 24
} else {
enHour--
}
let enMin = en[1]
this.setData({
"pickerItem[0].value": [staHour, staMin],
"pickerItem[1].value": [enHour, enMin],
"pickerItem[0].num": [sta[0] + "", sta[1] + ""],
"pickerItem[1].num": [en[0] + "", en[1] + ""],
})
},
//设置星期
updateInitWeek(weekDayStr) {
let str = weekDayStr.length > 1 ? weekDayStr.split(',') : weekDayStr
let select = this.data.select
let day = new Set()
//将激活的星期全部取消
select.forEach(e => {
e.active = false
})
this.setData({
select: select
})
let bool = true
for (let i = 0; i < select.length; i++) {
if (select[i].week_day === weekDayStr) {
this.setData({
day: select[i].value,
[`select[${i}].active`]: true
})
bool = false
break
}
}
if(bool) {
for (let k = 0; k < this.data.dateList.length; k++) {
if (str.length > 1) {
str.forEach(el => {
if (this.data.dateList[k].week_day == el) {
day.add(this.data.dateList[k].value)
}
})
this.setData({
day: Array.from(day).join('\t'),
['select[3].week_day']: weekDayStr,
[`select[3].active`]: true
})
} else {
if (this.data.dateList[k].week_day == str) {
this.setData({
['select[3].week_day']: weekDayStr,
[`select[3].active`]: true,
day: this.data.dateList[k].value,
})
break
}
}
}
}
},
//保存开始结束时间信息
saveTime: function(){
console.log(this.data.pickerItem);
let startHour = this.data.pickerItem[0].num[0];
let startMin = this.data.pickerItem[0].num[1];
let endHour = this.data.pickerItem[1].num[0];
let endMin = this.data.pickerItem[1].num[1];
let sta = startHour + ":" + startMin;
let en = endHour + ":" + endMin;
if(sta == en){
app.showMessage("开始时间和结束时间不能设置成一样的!");
}else{
this.setData({
"cloudSecurityInfo.startTime": sta,
"cloudSecurityInfo.endTime": en
})
this.saveWeek();
}
},
//保存星期
saveWeek: function(){
let weekChoose = this.data.select;
for (let i = 0; i < weekChoose.length; i++) {
if (weekChoose[i].active) {
this.setData({
"cloudSecurityInfo.weekDayStr": weekChoose[i].week_day
})
break;
}
}
this.insertOrUpdateInfo();
},
//进行插入更新操作
insertOrUpdateInfo: function(){
console.log(this.data.cloudSecurityInfo);
requestapi.updateCloudSecurity(this.data.cloudSecurityInfo, function (response) {
console.log(response);
if(response.returnCode == "0"){
wx.navigateBack({
delta: 1,
})
}else{
app.showMessage(response.message)
}
})
}
})