freqModal.vue
14.5 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
447
448
449
450
451
452
453
454
<template>
<!-- 一键调频弹框 -->
<el-dialog title="一键调频" :visible="freqVisible" @open="openDialog" @close="closeDialog" append-to-body width="700px" :close-on-click-modal="false">
<el-form :model="freqForm" ref="freqForm" :rules="freqFormRules" size="mini" label-width="150px" v-loading="formLoading">
<el-form-item label="调频开关:">
<el-switch v-model="freqForm.enableFreq"></el-switch>
<span class="type_tips">(关闭时,恢复出厂设置,打开时支持模式选择,默认关闭)</span>
</el-form-item>
<el-form-item label="调频模式:" prop="fqType">
<el-radio-group v-model="freqForm.fqType" :disabled="!freqForm.enableFreq" @change="onChange">
<el-radio :label="0">追车模式</el-radio>
<el-radio :label="1">闹钟模式</el-radio>
<el-radio :label="2">星期模式</el-radio>
</el-radio-group>
<div class="type_tips">{{typeTips[freqForm.fqType]}}</div>
</el-form-item>
<el-form-item label="调频内容:" v-if="freqForm.fqType === 0" prop="catchingTimer">
<!-- <el-input v-model="freqForm.catchingTimer" class="sort_input" :placeholder="`1~${maxNumber}`" :maxlength="String(maxNumber).length" :disabled="!freqForm.enableFreq"></el-input> -->
<el-input-number v-model="freqForm.catchingTimer" class="sort_input" precision="0" :placeholder="`1~${maxNumber}`" :controls="false" :min="1" :max="maxNumber" :disabled="!freqForm.enableFreq"></el-input-number>
<span>分钟</span>
</el-form-item>
<el-form-item label="调频内容:" v-if="freqForm.fqType == 1" prop="teamList" class="is-required">
<el-checkbox-group v-model="freqForm.teamList" class="freq_check_group" :disabled="!freqForm.enableFreq">
<el-checkbox :label="1">
<span>第一组</span>
<el-time-select v-model="freqForm.timer1" :editable="false" :clearable="false" class="sort_input" :picker-options="pickerOptions" :disabled="!freqForm.enableFreq">
</el-time-select>
</el-checkbox>
<el-checkbox :label="2">
<span>第二组</span>
<el-time-select v-model="freqForm.timer2" :editable="false" :clearable="false" class="sort_input" :picker-options="pickerOptions" :disabled="!freqForm.enableFreq">
</el-time-select>
</el-checkbox>
<el-checkbox :label="3">
<span>第三组</span>
<el-time-select v-model="freqForm.timer3" :editable="false" :clearable="false" class="sort_input" :picker-options="pickerOptions" :disabled="!freqForm.enableFreq">
</el-time-select>
</el-checkbox>
<el-checkbox :label="4">
<span>第四组</span>
<el-time-select v-model="freqForm.timer4" :editable="false" :clearable="false" class="sort_input" :picker-options="pickerOptions" :disabled="!freqForm.enableFreq">
</el-time-select>
</el-checkbox>
</el-checkbox-group>
</el-form-item>
<el-form-item label="调频内容:" v-if="freqForm.fqType == 2" class="is-required">
<el-form-item label="" label-width="0" class="week_item" prop="weekTimer">
<span class="name">上点时间</span>
<el-time-select v-model="freqForm.weekTimer" class="sort_input" :editable="false" :clearable="false" :picker-options="pickerOptions" :disabled="!freqForm.enableFreq">
</el-time-select>
</el-form-item>
<el-form-item label="" label-width="0" prop="weekList">
<el-checkbox-group v-model="freqForm.weekList" class="week_checkbox" :disabled="!freqForm.enableFreq">
<el-checkbox label="1">周一</el-checkbox>
<el-checkbox label="2">周二</el-checkbox>
<el-checkbox label="3">周三</el-checkbox>
<el-checkbox label="4">周四</el-checkbox>
<el-checkbox label="5">周五</el-checkbox>
<el-checkbox label="6">周六</el-checkbox>
<el-checkbox label="7">周日</el-checkbox>
</el-checkbox-group>
</el-form-item>
</el-form-item>
<el-form-item label="调频操作持续时长:" class="is-required">
<div class="duration_type">
<el-form-item label="" label-width="0">
<el-select v-model="freqForm.durationType" class="sort_select" :disabled="!freqForm.enableFreq">
<el-option :value="1" label="永久有效"></el-option>
<el-option :value="2" label="自定义时长"></el-option>
</el-select>
</el-form-item>
<el-form-item label="" label-width="0" prop="duration" v-if="freqForm.durationType == 2">
<!-- <el-input v-model="freqForm.duration" class="sort_input" placeholder="1~7200" maxlength="4" :disabled="!freqForm.enableFreq"></el-input> -->
<el-input-number v-model="freqForm.duration" class="sort_input" precision="0" placeholder="1~7200" :controls="false" :min="1" :max="7200" :disabled="!freqForm.enableFreq"></el-input-number>
<span>分钟</span>
</el-form-item>
</div>
</el-form-item>
</el-form>
<span v-if="tenantFlag">* 提示:每周五晚,系统自动恢复无线设备调频状态</span>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm" :loading="loading" size="small">确认</el-button>
<el-button @click="$emit('onFreqModalChange', false)" size="small">取消</el-button>
</div>
</el-dialog>
<!-- 查看详情弹框 /-->
</template>
<script>
import { adjFreq, GET_FREQ_DETAILS, REST_FREQ_INFO } from "services/vehicle";
import { deepClone, showToast } from "@/utils/util";
export default {
props: ["freqVisible", "sn", "enableFreq", "tenantFlag"],
data() {
let checkCatchingTimer = (rule, vaule, cb) => {
if (this.freqForm.fqType == "0") {
if (!/^[^0]\d{0,3}$/.test(this.freqForm.catchingTimer)) {
cb(new Error(`请输入分钟数,1~${this.maxNumber}`));
} else if (this.freqForm.catchingTimer > this.maxNumber) {
cb(new Error(`请输入分钟数,1~${this.maxNumber}`));
}
}
cb();
};
const timePattern = /^(([0-1]\d|2[0-3])\:[0-5]\d)$|^24\:00$/;
/*let checkTimer1 = (rule, vaule, cb)=>{console.log(this.freqForm.timer1)
if(this.freqForm.fqType == '1' && this.freqForm.fqClock1 && !timePattern.test(this.freqForm.timer1)){
cb(new Error('请输入正确的时间格式'))
}
}*/
return {
freqForm: {
fqType: 0,
weekTimer: "10:00",
teamList: [],
weekList: [],
durationType: 1,
},
freqFormRules: {
fqType: [
{ required: true, message: "请选择调频模式", trigger: "change" },
],
catchingTimer: [
{
required: true,
message: `请输入分钟数,1~${this.enableFreq ? 5555 : 999}`,
trigger: "blur",
},
{ validator: checkCatchingTimer, trigger: "blur" },
],
teamList: [
{ required: true, message: "请选择调频内容", trigger: "change" },
],
weekTimer: [
{ required: true, message: "请输入上点时间", trigger: "blur" },
],
weekList: [{ required: true, message: "请选择", trigger: "blur" }],
duration: [{ required: true, message: "请输入持续时长" }],
},
typeTips: {
0: "注:适用于收车场景,指定设备每隔几分钟更新定位信息",
1: "注:适用于催款环节,增加设备每天的上点频率,防止人车失联",
2: "注:适用于日常场景,可按需设置每周的设备回传次数。",
},
pickerOptions: {
start: "00:00",
step: "00:15",
end: "23:45",
format: "HH:mm",
},
loading: false,
formLoading: false,
timeList: {
1: "01:00",
2: "10:00",
3: "14:00",
4: "23:00",
},
};
},
computed: {
maxNumber() {
return this.enableFreq ? 5555 : 999;
},
},
watch: {
sn: {
handler: function (n, o) {
if (n || n == o) {
console.log(this);
this.getFreqInfo(n);
}
},
immediate: true,
},
},
methods: {
openDialog() {
this.$emit("onFreqModalChange", true);
},
// 关闭弹框
closeDialog() {
this.$refs.freqForm.clearValidate();
this.$emit("onFreqModalChange", false);
},
// 获取参数
getParams() {
const form = deepClone(this.freqForm);
const params = {};
params.sn = this.sn;
params.type = form.fqType;
params.duration = form.duration;
//params.nableFreq = form.enableFreq
// 追车模式
if (form.fqType == 0) {
params.catchingTimer = form.catchingTimer;
}
// 闹钟模式
if (form.fqType == 1) {
let arr = form.teamList;
let _timer = [];
for (let i = 1; i < 5; i++) {
let idx = arr.findIndex((k) => k == i);
if (idx >= 0) {
_timer.push(form["timer" + i]);
} else {
_timer.push("NA");
}
}
// arr.map((k) => {
// console.log(k);
// _timer.push(form["timer" + k]);
// });
params.timer = _timer.join(",");
}
// 星期模式
if (form.fqType == 2) {
params.week = form.weekList.sort().join("");
params.weekTimer = form.weekTimer;
}
// 持续时长
if (form.durationType == 1) {
params.duration = "-1";
}
console.log(params);
return params;
},
// 保存调频信息
submitForm() {
let _this = this;
let params = this.getParams();
console.log(params);
if (!this.freqForm.enableFreq) {
//_this.closeDialog();
_this.closeFreq();
return false;
}
this.$refs.freqForm.validate((valid, field) => {
if (!valid) {
return false;
}
_this.loading = true;
adjFreq(params)
.then((res) => {
_this.loading = false;
if (res.code == 200) {
showToast({
type: "success",
message: res.message,
});
_this.closeDialog();
}
})
.catch((error) => {
_this.loading = false;
});
});
},
validateClock() {
if (this.freqForm.fqType == "1") {
if (
this.freqForm.fqClock1 ||
this.freqForm.fqClock2 ||
this.freqForm.fqClock3 ||
this.freqForm.fqClock4
) {
this.freqForm.clockError = false;
return true;
} else {
this.freqForm.clockError = true;
return false;
}
} else {
this.freqForm.clockError = false;
return true;
}
},
validateWeak() {
if (this.freqForm.fqType == "2") {
if (
this.freqForm.fqWeekday1 ||
this.freqForm.fqWeekday2 ||
this.freqForm.fqWeekday3 ||
this.freqForm.fqWeekday4 ||
this.freqForm.fqWeekday5 ||
this.freqForm.fqWeekday6 ||
this.freqForm.fqWeekday7
) {
this.freqForm.weekError = false;
return true;
} else {
this.freqForm.weekError = true;
return false;
}
} else {
this.freqForm.weekError = false;
return true;
}
},
// 获取调频配置信息
async getFreqInfo(sn) {
this.formLoading = true;
let res = await GET_FREQ_DETAILS({ sn: sn });
console.log(res);
this.formLoading = false;
if (res.code == 200) {
let obj = res.data || {};
let teamList = [];
let weekList = [];
// 星期
if (obj.week) {
weekList = obj.week.split("");
}
// 闹钟
if (obj.timer) {
let arr = obj.timer.split(",");
let len = arr.length;
console.log(arr);
arr.forEach((k, i) => {
console.log(k, i);
if (k != "NA") {
teamList.push(i + 1);
obj["timer" + (i + 1)] = k;
} else {
obj["timer" + (i + 1)] = this.timeList[i + 1];
}
});
}
// 非闹钟模式,设置默认值
if (!obj.timer) {
obj.timer1 = "01:00";
obj.timer2 = "10:00";
obj.timer3 = "14:00";
obj.timer4 = "23:00";
}
// 关闭状态,timer 有个默认值 14:30,后台没填充占位,需要手动补齐后面三个
if (obj.freqType == 3) {
obj.timer2 = "10:00";
obj.timer3 = "14:00";
obj.timer4 = "23:00";
}
obj.fqType = obj.freqType == 3 ? "" : obj.freqType;
obj.teamList = teamList;
obj.weekList = weekList;
obj.weekTimer = obj.weekTimer || "10:00";
obj.enableFreq = obj.freqType == 3 ? false : true;
if (!obj.duration || obj.duration == "-1") {
obj.durationType = 1;
} else {
obj.durationType = 2;
}
console.log(obj);
this.freqForm = obj;
this.onChange();
}
},
// 关闭一键调频
async closeFreq() {
let oParams = {};
oParams.sn = this.sn;
this.loading = true;
let res = await REST_FREQ_INFO(oParams);
console.log(res);
this.loading = false;
if (res.code == 200) {
showToast({
message: "调频已关闭",
type: "success",
});
this.closeDialog();
}
},
// 监听调频模式切换
onChange() {
let _this = this;
setTimeout(function () {
_this.$refs.freqForm.clearValidate();
}, 10);
},
},
components: {},
};
</script>
<style lang="scss" scoped>
.freq-des {
color: #999;
}
.row-ct {
padding-left: 20px;
margin-bottom: 10px;
}
.type_tips {
font-size: 12px;
color: #999;
}
.sort_input,
.sort_select {
width: 120px;
margin-right: 10px;
::v-deep .el-input__inner {
text-align: left;
}
}
.freq_check_group {
display: flex;
align-items: center;
flex-wrap: wrap;
.el-checkbox {
flex: 0 0 50%;
margin: 0 0 10px 0;
.sort_input {
margin-left: 10px;
width: 100px;
}
}
}
.week_item {
display: flex;
align-items: center;
.name {
margin-right: 10px;
}
}
.week_checkbox {
.el-checkbox {
margin: 0 20px 10px 0;
.el-checkbox__label {
padding-left: 5px !important;
}
}
}
.duration_type {
display: flex;
align-items: center;
}
</style>