|
|
@@ -5,13 +5,29 @@
|
|
|
<a-input v-model:value="formStates.regName" placeholder="请输入规程名称" />
|
|
|
</a-form-item>
|
|
|
<a-form-item label="规程类型:">
|
|
|
- <a-input v-model:value="formStates.regType" placeholder="请输入规程类型" />
|
|
|
+ <a-select
|
|
|
+ v-model:value="formStates.regType"
|
|
|
+ placeholder="请选择规程类型"
|
|
|
+ :options="regTypeOption"
|
|
|
+ :fieldNames="{ label: 'label', value: 'value' }"
|
|
|
+ />
|
|
|
</a-form-item>
|
|
|
<a-form-item label="设备种类:">
|
|
|
- <a-input v-model:value="formStates.deviceKind" placeholder="请输入设备种类" />
|
|
|
+ <a-select
|
|
|
+ v-model:value="formStates.deviceKind"
|
|
|
+ placeholder="请选择设备种类"
|
|
|
+ :options="deviceKindOption"
|
|
|
+ :fieldNames="{ label: 'label', value: 'value' }"
|
|
|
+ />
|
|
|
</a-form-item>
|
|
|
<a-form-item label="关联监测数据名称:">
|
|
|
- <a-input v-model:value="formStates.monitorDataName" placeholder="请输入关联监测数据名称" />
|
|
|
+ <a-select
|
|
|
+ v-model:value="formStates.dataId"
|
|
|
+ placeholder="请选择关联监测数据名称"
|
|
|
+ :options="monitorDataOptions"
|
|
|
+ :fieldNames="{ label: 'des', value: 'id' }"
|
|
|
+ :disabled="!formStates.deviceKind"
|
|
|
+ />
|
|
|
</a-form-item>
|
|
|
<a-form-item label="规则路由:">
|
|
|
<a-input v-model:value="formStates.regRoute" placeholder="请输入规则路由" />
|
|
|
@@ -26,7 +42,8 @@
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
import { ref, reactive, onMounted, watch } from 'vue';
|
|
|
- import { addList, editList } from './internalManager.api';
|
|
|
+ import { addList, editList, getRegDataList } from './internalManager.api';
|
|
|
+ import { getDictItemsByCode } from '/@/utils/dict';
|
|
|
|
|
|
let props = defineProps({
|
|
|
formState: {
|
|
|
@@ -46,20 +63,60 @@
|
|
|
regName: '',
|
|
|
regType: '',
|
|
|
deviceKind: '',
|
|
|
+ dataId: '',
|
|
|
monitorDataName: '',
|
|
|
regRoute: '',
|
|
|
});
|
|
|
+
|
|
|
+ // 下拉选项
|
|
|
+ const deviceKindOption = ref([]); // 设备类型选项
|
|
|
+ const regTypeOption = ref([]); // 规程类型选项
|
|
|
+ const monitorDataOptions = ref([]); // 关联监测数据名称选项
|
|
|
+
|
|
|
let emit = defineEmits<{
|
|
|
(e: 'close'): void;
|
|
|
}>();
|
|
|
|
|
|
+ // 获取关联监测数据名称选项
|
|
|
+ const fetchMonitorDataOptions = async () => {
|
|
|
+ if (!formStates.deviceKind) return;
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 调用接口获取关联监测数据
|
|
|
+ const res = await getRegDataList({
|
|
|
+ pagetype: 'left',
|
|
|
+ pageSize: 500,
|
|
|
+ deviceKind: formStates.deviceKind,
|
|
|
+ });
|
|
|
+ monitorDataOptions.value = res.records;
|
|
|
+ } catch (error) {
|
|
|
+ console.error('获取关联监测数据失败:', error);
|
|
|
+ monitorDataOptions.value = [];
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // 监听设备种类变化,获取关联监测数据
|
|
|
+ watch(
|
|
|
+ () => formStates.deviceKind,
|
|
|
+ async ([newDeviceKind], [oldDeviceKind]) => {
|
|
|
+ // 只有当两个值都存在时才请求
|
|
|
+ if (newDeviceKind) {
|
|
|
+ await fetchMonitorDataOptions();
|
|
|
+ } else if (newDeviceKind !== oldDeviceKind) {
|
|
|
+ // 当任一值清空时,重置关联监测数据
|
|
|
+ monitorDataOptions.value = [];
|
|
|
+ formStates.monitorDataName = '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+
|
|
|
async function getConfirm() {
|
|
|
const params = {
|
|
|
id: formStates.id,
|
|
|
regName: formStates.regName,
|
|
|
regType: formStates.regType,
|
|
|
deviceKind: formStates.deviceKind,
|
|
|
- monitorDataName: formStates.monitorDataName,
|
|
|
+ dataId: formStates.dataId,
|
|
|
regRoute: formStates.regRoute,
|
|
|
};
|
|
|
if (props.isToggle == 'add') {
|
|
|
@@ -69,21 +126,39 @@
|
|
|
}
|
|
|
emit('close');
|
|
|
}
|
|
|
+
|
|
|
function getCancel() {
|
|
|
emit('close');
|
|
|
}
|
|
|
+
|
|
|
// 监听formState变化,同步到表单
|
|
|
watch(
|
|
|
() => props.formState,
|
|
|
- (newVal) => {
|
|
|
+ async (newVal) => {
|
|
|
if (newVal) {
|
|
|
Object.assign(formStates, newVal);
|
|
|
+ // 当编辑时,同步获取关联监测数据
|
|
|
+ if (formStates.deviceKind) {
|
|
|
+ await fetchMonitorDataOptions();
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
{ immediate: true }
|
|
|
);
|
|
|
|
|
|
- onMounted(() => {});
|
|
|
+ onMounted(async () => {
|
|
|
+ // 获取设备类型字典
|
|
|
+ const deviceRes = getDictItemsByCode('devicekind');
|
|
|
+ deviceKindOption.value = deviceRes;
|
|
|
+ // 获取规程类型字典
|
|
|
+ const regRes = getDictItemsByCode('regType');
|
|
|
+ regTypeOption.value = regRes;
|
|
|
+
|
|
|
+ // 如果有初始值,获取关联监测数据
|
|
|
+ if (formStates.deviceKind) {
|
|
|
+ await fetchMonitorDataOptions();
|
|
|
+ }
|
|
|
+ });
|
|
|
</script>
|
|
|
|
|
|
<style lang="less" scoped>
|