alarmDisposeModule.vue
14.3 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
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
<template>
<!-- 查看详情弹框 -->
<el-dialog id="alarmDisposeModule" :close-on-click-modal="flag" @click="clickUser" :visible="detailFormVisible" @open="openDialog" @close="closeDialog" append-to-body width="800px">
<div class="dialog-header" slot="title">
<h2 class="header-title">{{isEditMode?'编辑配置':'新增配置'}}</h2>
</div>
<el-form ref="form" :model="form" :rules="rules" :inline="true" size="medium" label-width="110px" >
<el-form-item label="项目分组" prop="region">
<el-select v-model="form.region" placeholder="请选择项目分组" @change="getLabel">
<el-option
v-for="(item,index) in optionsData"
:key="index"
:value="item.value"
:label="item.lable"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="报警类型" prop="alarmType">
<el-select v-model="form.alarmType" @change = "change()" placeholder="请选择报警类型">
<el-option
v-for="item in alarmTypeData"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="严重级别" prop="severityLevel">
<el-select v-model="form.severityLevel" placeholder="请选择严重级别">
<el-option
v-for="item in severityLevelData"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="规则名称" prop="ruleName">
<el-input v-model="form.ruleName"></el-input>
</el-form-item>
<el-form-item label="报警阈值" v-if ="thresholdText" prop="threshold">
<el-input v-model="form.threshold" :disabled="isDisabled" @blur = 'changeThreshold()' :placeholder='tips' style='width: 200px'></el-input>
</el-form-item>
<el-form-item label="报警阈值" prop="threshold" v-if='flag'>
<el-select v-model="form.threshold" placeholder="请选择报警阈值" @change = "changePercentage" >
<el-option
v-for="item in powerAlarm"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="报警条件描述" prop="description">
<el-input type="textarea" v-model="form.description" :disabled="true"></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="cancel()" size="small">取消</el-button>
<el-button type="primary" @click="sure('form')" size="small">确定</el-button>
</div>
</el-dialog>
<!-- 查看详情弹框 /-->
</template>
<script>
import {services} from '../../api'
const REPORT_SERVICE = services.report;
export default{
props: ['detailFormVisible', 'detailForm','dataId','optionsData'],
watch: {
dataId: function(newValue) {
console.log(newValue); //可以看到数据已经拿到
}
},
data(){
let checkThreshold = (rule, vaule, cb)=>{
if(this.form.alarmType==1&&(parseInt(vaule)<2||parseInt(vaule)>30)){
cb('请输入提示信息范围内的值')
}else if(this.form.alarmType==2&&(parseInt(vaule)<1||parseInt(vaule)>99)){
cb('请输入提示信息范围内的值')
}else if(this.form.alarmType==4&&(parseInt(vaule)<10||parseInt(vaule)>99)){
cb('请输入提示信息范围内的值')
}else if(this.form.alarmType==5&&(parseInt(vaule)<1||parseInt(vaule)>99)){
cb('请输入提示信息范围内的值')
}else if(this.form.alarmType==6&&(parseInt(vaule)<10||parseInt(vaule)>999)){
cb('请输入提示信息范围内的值')
}
cb()
}
return {
scrollToRef: '',
showBigImg:false,
num:0,
isDisabled:false,
tips:'',
editName:'',
form:{
region:'',
alarmType:'',
severityLevel:'',
ruleName:'',
description:'',
threshold:0
},
flag:false,
thresholdText:true,
alarmTypeData:[{
value: '0',
label: '电量报警'
},{
value: '1',
label: '超时报警'
},{
value: '2',
label: '离线超时报警'
},{
value: '3',
label: '设备报警'
},{
value: '10',
label: '设备分离报警'
},{
value: '9',
label: '出省报警(经销商)'
},{
value: '12',
label: '区域报警(个人)'
}/* ,{
value: '4',
label: '二押区域报警'
},{
value: '5',
label: '翻转报警'
},{
value: '6',
label: '高危区域报警'
},{
value: '7',
label: '出国报警'
},{
value: '8',
label: '出入边境省份预警'
} */],
severityLevelData:[
{
value: '0',
label: '严重'
},{
value: '1',
label: '不严重'
}
],
powerAlarm:[{
value: '10',
label: '10%'
},{
value: '20',
label: '20%'
},{
value: '30',
label: '30%'
},{
value: '40',
label: '40%'
},{
value: '50',
label: '50%'
},{
value: '60',
label: '60%'
}],
rules :{
region: [
{ required: true, message: '请选择分组分类', trigger: 'change' }
],
alarmType: [
{ required: true, message: '请选择报警类型', trigger: 'change' }
],
severityLevel: [
{ required: true, message: '请选择严重级别', trigger: 'change' }
],
ruleName: [
{ required: true, message: '请输入规则名称', trigger: 'blur' }
],
threshold: [
{ validator: checkThreshold, trigger: 'blur'},
]
}
}
},
computed: {
isEditMode:{
get(){
return this.dataId
}
}
},
methods: {
openDialog(){
let form = this.form;
if(this.dataId!=""){
form.region = this.detailForm.projectType
form.severityLevel = String(this.detailForm.alarmLevelVal)
if(this.detailForm.alarmTypeVal == 0){
this.flag = true;
this.thresholdText = false;
}
form.alarmType = String(this.detailForm.alarmTypeVal)
form.threshold = this.detailForm.threshold
form.description = this.detailForm.alarmCondition
form.ruleName = this.detailForm.ruleName
}else{
form.region = ''
form.severityLevel = ''
form.alarmType = ''
form.threshold = ''
form.description = ''
form.ruleName = ''
}
this.$emit('onAlarmDisposeModuleChange', true)
},
closeDialog(){console.log(this.isOpen)
this.$emit('onAlarmDisposeModuleChange', false)
},
change(){
switch (parseInt(this.form.alarmType))
{
case 0:
this.form.threshold ='';
this.flag = true;
this.thresholdText = false;
break
case 1:
this.form.threshold ='';
this.tips ='2~30天';
this.form.description = '';
this.isDisabled = false;
this.thresholdText = true;
this.flag = false;
break;
case 2:
this.form.threshold ='';
this.tips ='1~99天';
this.form.description = '';
this.isDisabled = false;
this.thresholdText = true;
this.flag = false;
break;
case 4:
this.form.threshold ='';
this.tips ='10~99分钟';
this.form.description = '';
this.isDisabled = false;
this.thresholdText = true;
this.flag = false;
break;
case 5:
this.form.threshold ='';
this.tips ='1~99分钟';
this.form.description = '';
this.isDisabled = false;
this.thresholdText = true;
this.flag = false;
break;
case 6:
this.form.threshold ='';
this.tips ='10~999分钟';
this.form.description = '';
this.isDisabled = false;
this.thresholdText = true;
this.flag = false;
break;
case 10:
this.form.threshold ='10';
this.tips ='';
this.form.description = '';
this.isDisabled = false;
this.thresholdText = true;
this.flag = false;
break;
default:
this.form.threshold ='系统触发';
this.form.description = '系统自动触发报警'
this.isDisabled = true;
this.thresholdText = true;
this.flag = false;
break;
}
},
changeThreshold(){
switch (parseInt(this.form.alarmType))
{
case 0:
this.form.description = `无线设备电量低于百分之${this.form.threshold}报警`
break;
case 1:
this.form.description =`车辆在某个位置停止超过${this.form.threshold}天报警`
break;
case 2:
this.form.description =`设备连续${this.form.threshold}天没有回传位置点报警`
break;
case 4:
this.form.description =`车辆在二押区域停留${this.form.threshold}分钟报警`
break;
case 5:
this.form.description =`触发后${this.form.threshold}分钟内不重复报警`
break;
case 6:
this.form.description =`车辆在危区域停留${this.form.threshold}分钟报警`
break;
}
},
changePercentage(value){
let obj = {};
obj = this.powerAlarm.find((item)=>{
return item.value === value;
});
this.form.description =`无线设备电量低于百分之${obj.label}报警`
},
getLabel(val){
let obj = {};
obj = this.optionsData.find((item)=>{
return item.value === val;
});
this.labelName = obj.lable;
console.log(this.labelName)
},
getParams(){
const form = this.form;
const params = {};
if(this.labelName){
params.projectType = this.labelName;
}else{
params.projectType = form.region;
}
if(form.severityLevel){
params.alarmLevel = form.severityLevel;
}
if(form.alarmType){
params.alarmType = form.alarmType;
}
if(form.ruleName){
params.ruleName = form.ruleName;
}
if(form.threshold){
params.threshold =form.threshold
}
if(form.description){
params.alarmCondition =form.description
}
return params;
},
sure(formName){
let _this = this
let params = _this.getParams();
this.$refs[formName].validate((valid) => {
if (valid && !this.dataId) {
if(this.form.threshold==''){
this.$message({
message:'请输入/选择报警阈值' ,
type: 'error'
});
return false;
}else{
REPORT_SERVICE.validateRuleName(params).then((response)=>{
if(response.returnCode==0){
REPORT_SERVICE.addAlarmRule(params).then((response)=>{
if(response.returnCode==0){
this.$message({
message:response.message ,
type: 'success'
});
this.$emit('getData');
this.$emit('onAlarmDisposeModuleChange', false)
}
});
}else{
return false;
}
});
}
} else if(valid&&_this.dataId) {
params.id = _this.dataId;
let form = _this.form;
if(params.ruleName == _this.detailForm.ruleName){
if(params.projectType == _this.detailForm.projectType && params.alarmLevel == String(_this.detailForm.alarmLevelVal) && params.alarmType == String(_this.detailForm.alarmTypeVal) && params.ruleName == _this.detailForm.ruleName && params.threshold == _this.detailForm.threshold && params.alarmCondition == _this.detailForm.alarmCondition){
_this.$emit('onAlarmDisposeModuleChange', false)
}else{
REPORT_SERVICE.validateRuleName(params).then((response)=>{
if(response.returnCode==0){
_this.updateAlarmRule(params)
}
});
}
}else{
REPORT_SERVICE.validateRuleName(params).then((response)=>{
if(response.returnCode==0){
this.updateAlarmRule(params)
}
});
}
}else{
return false;
}
});
},
updateAlarmRule(params){
REPORT_SERVICE.updateAlarmRule(params).then((response)=>{
if(response.returnCode==0){
this.$message({
message:response.message ,
type: 'success'
});
this.$emit('getData');
this.$emit('onAlarmDisposeModuleChange', false)
}
});
},
cancel(){
this.$emit('onAlarmDisposeModuleChange', false)
}
},
components:{
}
}
</script>
<style scoped>
form {
height: 500px;
overflow: auto;
margin: -30px -20px;
padding: 20px;
}
.tip{
font-size: 12px;
}
#alarmDisposeModule .el-input--medium .el-input__inner{
width: 200px;
}
.imgList img{
width: 160px;
height: 100px;
border: none;
/* opacity: .9; */
transition: all 0.5s;
box-shadow: 10px 10px 16px #ccc;
}
.imgMask{
position: absolute;
height: 100%;
width:100%;
top:0;
left:0;
z-index: 100;
background:rgba(0,0,0,.6);
}
.showImg{
height:550px;
width:800px;
position: absolute;
left:50%;
top:50%;
transform:translate(-50%,-50%);
}
.bigImg{
width:100%;
height:100%;
}
.prev{
position: absolute;
top: 50%;
width: 27px;
height: 44px;
margin-top: -22px;
outline: 0;
left: 10px;
background-position: -5px -50px;
background: red;
z-index: 999;
}
.next {
position: absolute;
top: 50%;
width: 27px;
height: 44px;
margin-top: -22px;
outline: 0;
right: 10px;
background-position: -5px -50px;
background: red;
}
</style>