fuliqi
2024-11-06 23abf3c8d6ca9577608a3d5ab207d0da67e6e752
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
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
<template>
  <div class="app-container">
    <el-form style="margin-left :20px" :model="queryParams" ref="queryForm" size="small" :inline="true"
             v-show="showSearch" label-width="68px">
      <el-form-item label="考核类型" prop="examineCategory">
        <el-select v-model="queryParams.examineCategory" placeholder="考核类型" clearable @change="handleQuery">
          <el-option
            v-for="dict in dict.type.platform_examine_category"
            :key="dict.value"
            :label="dict.label"
            :value="parseInt(dict.value)"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="考核标签" prop="examineTag">
        <el-select v-model="queryParams.examineTag" placeholder="考核标签" clearable @change="handleQuery">
          <el-option
            v-for="dict in dict.type.platform_examine_tag"
            :key="parseInt(dict.value)"
            :label="dict.label"
            :value="parseInt(dict.value)"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
 
    <el-row :gutter="10" style="margin-left :15px">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增
        </el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </el-col> -->
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="warning"-->
      <!--          plain-->
      <!--          icon="el-icon-download"-->
      <!--          size="mini"-->
      <!--          @click="handleExport"-->
      <!--        >导出</el-button>-->
      <!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <div class="card-container">
      <el-card class="box-card" v-for="item in checkTemplateList" :key="item">
        <div class="text item">模板名称:{{ item.templateName }}</div>
        <div class="text item">考核标签:{{
            item.examineTag === 0 ? '省厅考核' :
              item.examineTag === 1 ? '区县考核' :
                item.examineTag === 2 ? '公安部考核' : '未知'
          }}
        </div>
        <div class="text item" style="display: flex">
          <span>考核类型:</span>
          <dict-tag :options="dict.type.platform_examine_category" :value="item.examineCategory"/>
        </div>
        <!-- <div class="text item">考核频率:{{ item.frequency == 0 ? '月度考核' : '季度考核' }}</div> -->
        <div class="text item" style="display: flex">
          <span>考核对象:</span>
          <el-tooltip effect="dark" :content="translateDeptIdList(item.deptId)" placement="top">
            <div class="item" style="margin-bottom: 0" v-for="(deptId,index) in item.deptId" :key=index>
              {{ translateDeptIdList(item.deptId) }}
            </div>
          </el-tooltip>
        </div>
        <div class="text item" style="display: flex">
          <span style="padding: 3px 0;">使用状态:</span>
          <dict-tag :options="dict.type.platform_use_state" :value="item.status"/>
        </div>
        <div class="bottom clearfix">
          <el-button type="text" class="button" @click="handleStatus(item)" v-show="item.status == 1">启用</el-button>
          <el-button type="text" class="button" @click="handleStatus(item)" v-show="item.status == 0">停用</el-button>
          <el-button type="text" class="button" @click="handleCopy(item)">复制</el-button>
          <el-button type="text" class="button" @click="handleUpdate(item)">修改</el-button>
          <el-button type="text" class="button" @click="handleDelete(item)">删除</el-button>
        </div>
      </el-card>
    </div>
 
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
 
    <!-- 添加或修改考核模板对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="模板名称" prop="templateName">
          <el-input v-model="form.templateName" placeholder="请输入模板名称"/>
        </el-form-item>
        <el-form-item label="考核标签" prop="examineTag">
          <el-select v-model="form.examineTag" placeholder="考核类型">
            <el-option
              v-for="dict in dict.type.platform_examine_tag"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            />
          </el-select>
        </el-form-item>
        <!--        <el-form-item label="考核频率" prop="frequency">-->
        <!--          <el-select v-model="form.frequency" placeholder="考核频率">-->
        <!--            <el-option-->
        <!--              v-for="dict in dict.type.platform_examine_frequency"-->
        <!--              :key="dict.value"-->
        <!--              :label="dict.label"-->
        <!--              :value="parseInt(dict.value)"-->
        <!--            />-->
        <!--          </el-select>-->
        <!--        </el-form-item>-->
        <el-form-item label="考核对象" prop="deptId">
          <el-select v-model="form.deptId" multiple placeholder="请选择">
            <el-option
              v-for="item in areaList"
              :key="item.id"
              :label="item.value"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="考核类型" prop="examineCategory">
          <el-select v-model="form.examineCategory" placeholder="考核类型" :disabled="tempRuleFormList.length > 0">
            <el-option
              v-for="dict in dict.type.platform_examine_category"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="考核规则" prop="tempRuleFormList">
          <div class="row-warp">
            <div class="row" v-for="(form) in tempRuleFormList">
              <div class="row-left">
                <div>规则</div>
                <div class="margin-5">
                  <el-select v-model="form.ruleId" placeholder="请选择">
                    <el-option
                      v-for="item in currentRuleList"
                      :key="item.id"
                      :label="item.ruleName"
                      :value="item.id"
                      :disabled="isRuleDisabled(item.id, index)"
                    >
                    </el-option>
                  </el-select>
                </div>
              </div>
              <div class="row-right">
                <div>权重</div>
                <div class="margin-5">
                  <el-input type="number" v-model.number="form.weight"/>
                </div>
              </div>
              <div class="item-op">
                <el-button @click="removeRule(form)" type="danger" icon="el-icon-delete" circle></el-button>
              </div>
            </div>
            <div style="margin-top: 25px">
              <el-button type="success" @click="nextAdd()" size="mini" plain>添加</el-button>
            </div>
          </div>
        </el-form-item>
        <el-form-item label="报警分数" prop="alarmScore">
          <el-input v-model="form.alarmScore" placeholder="请输入报警分数"/>
        </el-form-item>
        <el-form-item label="调整系数" prop="adjustCoefficient">
          <el-input v-model="form.adjustCoefficient" placeholder="请输入系数值"/>
        </el-form-item>
        <el-form-item label="调整方式" prop="adjustWay">
          <el-select v-model="form.adjustWay" placeholder="请选择调整系数计算方式">
            <el-option
              label="乘"
              value="*">
            </el-option>
            <el-option
              label="除"
              value="/">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="规则描述" prop="description">
          <el-input v-model="form.description" type="textarea" :autosize="{ minRows: 4, maxRows: 6}"
                    placeholder="请输入规则描述"/>
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-radio v-model="form.status" label="0">启用</el-radio>
          <el-radio v-model="form.status" label="1">停用</el-radio>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
 
<script>
import {
  listCheckTemplate,
  getCheckTemplate,
  delCheckTemplate,
  addCheckTemplate,
  updateCheckTemplate,
  copyCheckTemplate
} from "@/api/platform/check-template";
import {areaSelect} from '@/api/system/dept'
import {listCheckRule} from "../../../../api/platform/check-rule";
 
export default {
  name: "CheckTemplate",
  dicts: ['platform_use_state', 'platform_examine_category', 'platform_rule_category', 'platform_examine_frequency', 'platform_examine_tag'],
  data() {
    return {
      props: {multiple: true},
      value: [],
      areaList: [],
      ruleList: [],
      unitList: [],
      selectedRuleIds: [],
      examineCategory: null,
      isExamineCategoryDisabled: false,
      // 临时规则表单列表
      tempRuleFormList: [],
      // 最终
      ruleFormList: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 考核模板表格数据
      checkTemplateList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 状态时间范围
      daterangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        examineCategory: null,
        examineTag: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        templateName: [
          {required: true, message: "模板名称不能为空", trigger: "blur"}
        ],
        examineTag: [
          {required: true, message: "请选择考核标签", trigger: "change"}
        ],
        frequency: [
          {required: true, message: "请选择状态考核频率", trigger: "change"}
        ],
        deptId: [
          {required: true, message: "请至少选择一个考核对象", trigger: "change"}
        ],
        examineCategory: [
          {required: true, message: "请选择考核类型", trigger: "change"}
        ],
        adjustCoefficient: [
          {required: true, message: "调整系数不能为空", trigger: "blur"}
        ],
        adjustWay: [
          {required: true, message: "请选择调整方式", trigger: "change"}
        ],
        status: [
          {required: true, message: "请选择状态", trigger: "change"}
        ],
      },
    };
  },
  computed: {
    formattedDeptIds() {
      // 使用map将数组元素转换为字符串,然后用join方法连接它们
      return this.item.deptId.map(deptId => deptId.toString()).join(', ');
    },
    currentRuleList() {
      // 根据当前考核类型返回相应的规则列表
      const ruleListKey = this.form.examineCategory;
      // 有三个不同的规则列表
      const videoRules = this.ruleList['videoRules']; // 视频相关的规则集合
      const carRules = this.ruleList['carRules']; // 汽车相关的规则集合
      const faceRules = this.ruleList['faceRules']; // 人脸相关的规则集合
 
      // 使用条件语句来选择规则列表
      if (ruleListKey == 2) {
        return carRules;
      } else if (ruleListKey == 3) {
        return faceRules;
      } else if (ruleListKey == 1) {
        return videoRules;
      } else {
        // 默认返回一个空数组或备选方案
        return [];
      }
    }
  },
  created() {
    this.getList();
    this.areaSelect();
    this.selectCheckRule();
    if (typeof this.form.deptId === 'string' && this.form.deptId.length > 0) {
      this.form.deptId = this.form.deptId.split(',').map(Number); // 假设deptId的值是以逗号分隔的数字字符串
    }
  },
  methods: {
    isRuleDisabled(ruleId, index) {
      // 检查规则是否已被添加到 tempRuleFormList 中并且不是当前遍历的项
      return this.tempRuleFormList.some(item => item.ruleId === ruleId && item !== this.tempRuleFormList[index]);
    },
    removeRule(form) {
      console.log(form)
      this.ruleFormList = this.ruleFormList.filter(item => item !== form);
      this.tempRuleFormList = this.tempRuleFormList.filter(item => item !== form)
    },
    nextAdd() {
      this.tempRuleFormList.push({"ruleId": null, "weight": null});
    },
    handleChange(value) {
      console.log(value);
    },
    // 考核规则下拉数据
    selectCheckRule() {
      listCheckRule().then(res => {
        this.ruleList = res.data;
      })
    },
    // 区域下拉数据
    areaSelect() {
      areaSelect().then(res => {
        this.areaList = res.data;
      })
    },
    translateDeptId(deptId) {
      const department = this.areaList.find(dept => dept.id === deptId);
      return department ? department.value : '未知';
    },
    translateDeptIdList(deptNames) {
      return deptNames.map(this.translateDeptId).join(', ');
    },
    /** 查询考核模板列表 */
    getList() {
      this.loading = true;
      console.log(this.queryParams)
      listCheckTemplate(this.queryParams).then(response => {
        this.checkTemplateList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        templateName: null,
        examineTag: null,
        frequency: null,
        deptId: [],
        examineCategory: null,
        alarmScore: null,
        adjustCoefficient: null,
        adjustWay: null,
        status: null,
        description: null,
        createTime: null,
        updateTime: null,
        deleted: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.selectedRuleIds = [];
      this.tempRuleFormList = [];
      this.open = true;
      this.title = "添加考核模板";
    },
    /** 复制按钮操作 */
    handleCopy(row) {
      copyCheckTemplate(row).then(response => {
        this.$modal.msgSuccess("复制成功");
        this.open = false;
        this.getList();
      });
    },
    handleStatus(row) {
      let text = row.status == 1 ? '启用' : '停用';
      const templateName = row.templateName;
      this.$modal.confirm('是否确认' + text + '考核名为"' + templateName + '"的数据项?').then(function () {
        row.status = row.status == 1 ? "0" : "1";
        return updateCheckTemplate(row);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess(text + "成功");
      }).catch(() => {
      });
 
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCheckTemplate(id).then(response => {
        this.form = response.data;
        this.tempRuleFormList = this.form.ruleFormList;
        this.ruleFormList = this.form.ruleFormList;
        this.open = true;
        this.title = "修改考核模板";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          // 遍历表单中的每个权重字段
          for (let i = 0; i < this.tempRuleFormList.length; i++) {
            const weight = this.tempRuleFormList[i].weight;
            const ruleId = this.tempRuleFormList[i].ruleId;
            // 如果权重为空,则显示错误提示,并阻止提交
            if (!weight || !ruleId) {
              this.$message.error('规则或权重不能为空');
              return;
            }
          }
          this.form.ruleFormList = this.tempRuleFormList;
          if (this.form.id != null) {
            updateCheckTemplate(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCheckTemplate(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id
      this.$modal.confirm('是否确认删除考核模板名为"' + row.templateName + '"的数据项?').then(function () {
        return delCheckTemplate(id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/checkTemplate/export', {
        ...this.queryParams
      }, `checkTemplate_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
 
<style scoped>
.margin-5 {
  margin-left: 5px;
}
 
.row-warp {
  display: flex;
  flex-direction: column;
}
 
.row {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  margin: 5px 0;
}
 
.row-left {
  flex: 1;
  display: flex;
  flex-direction: row;
}
 
.row-right {
  flex: 1;
  display: flex;
  flex-direction: row;
}
 
.text {
  font-size: 14px;
}
 
.item {
  margin-bottom: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
 
.box-card {
  width: 20%;
 
  margin-right: 50px;
  margin-bottom: 30px;
}
 
.card-container {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: stretch;
  margin-top: 20px;
  padding: 0 20px;
}
</style>