he wei
5 天以前 3c3576d5792bfabcef84979757ee344712e71cd3
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
<script setup name="alarmParams">
import { ref, reactive, computed, watch, onMounted } from 'vue';
 
import useElement from "@/hooks/useElement.js";
    const { $loading, $message, $confirm } = useElement();
 
import {
  setBattAlmParam,
} from '@/api/alarm.js';
 
const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  },
  info: {
    type: Object,
    default: () => ({})
  }
});
 
const emit = defineEmits(['update:visible', 'change']);
 
const initFlag = ref(false);
 
const layout = {
  gutter: 16,
  span: 8,
}
const option = {
  // almId: '告警ID',
  // almName: '电池告警名称',
  almHighCoeUpper: '上上限告警阈值',
  almHighLevelUpper: '上上限告警等级',
  almHighCoeUpperEn: '上上限制告警使能',
  almHighCoe: '上限告警阈值',
  almHighLevel: '上限告警等级',
  almHighEn: '上限告警等级使能',
  almLowCoe: '下限告警阈值',
  almLowLevel: '下限告警等级',
  almLowEn: '下限告警使能',
  almLowCoeLower: '下下限告警阈值',
  almLowLevelLower: '下下限告警等级',
  almLowCoeLowerEn: '下下限告警使能',
  almDelayTime: '告警延时时长',
};
const form1 = reactive({});
 
const almId = ref('');
 
Object.keys(option).forEach(key => {
  form1[key] = '';
});
 
 
const alarmLevels = [
  {
    label: '一级告警',
    value: 1,
  },
  {
    label: '二级告警',
    value: 2,
  },
  {
    label: '三级告警',
    value: 3,
  },
  {
    label: '四级告警',
    value: 4,
  },
];
 
async function submit() {
  // console.log(obj, '=============');
  let loading = $loading();
  let res = await setBattAlmParam([form1]);
  let { code, data } = res;
  if (code && data) {
    $message.success('操作成功');
    emit('update:visible', false);
    emit('change');
  } else {
    $message.error('操作失败');
  }
  loading.close();
}
 
function close() {
  emit('update:visible', false);
}
 
onMounted(() => {
  Object.keys(option).forEach(key => {
    form1[key] = props.info[key];
  });
  form1.almId = props.info.almId;
  form1.battgroupId = props.info.battgroupId;
  initFlag.value = true;
});
</script>
 
<template>
  <div class="alarm-form">
    <!-- 表单区域 -->
    <div class="content">
      <el-form ref="formRef" :model="form1" label-width="10em" :key="initFlag">
        <el-row :gutter="layout.gutter">
          <el-col
            :span="layout.span"
            v-for="(item, idx) in Object.keys(option)"
            :key="'list1_' + idx"
          >
            <el-form-item :label="option[item]" :prop="item">
              <el-checkbox
                :checked="form1[item] == 1"
                @change="(v) => form1[item] = v ? 1 : 0"
                v-if="/En$/.test(item)"
              ></el-checkbox>
              <el-select
                v-else-if="/Level/.test(item)"
                v-model="form1[item]"
                placeholder="请选择"
              >
                <el-option
                  v-for="(item, key) in alarmLevels"
                  :key="'list3_' + idx + '_' + key"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
              <el-input v-else v-model="form1[item]"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="footer">
      <el-button  @click="close">关闭</el-button>
      <el-button type="primary" @click="submit">提交</el-button>
    </div>
  </div>
</template>
 
<style scoped lang="less">
.search-container {
  margin-bottom: 10px;
  padding-left: 20px;
  display: flex;
  align-items: center;
  .label {
    margin-right: 10px;
    font-size: 20px;
    font-family: 'YouSheBiaoTiHei';
  }
  .el-select {
    width: 200px;
  }
}
.footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}
</style>