<template>
|
<div class="system-menu-dialog-container">
|
<el-dialog :title="unitDialogState.title" v-model="unitDialogState.unitDialogVisible" width="600px">
|
<el-form ref="UnitFormRef" :rules="unitDialogState.unitFormRules" :model="unitDialogState.unitForm" size="default" label-width="120px">
|
<el-row :gutter="35">
|
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
|
<el-form-item label="设备编号" prop="deviceCode">
|
<el-input v-model="unitDialogState.unitForm.deviceCode" placeholder="设备编号" clearable class="input-length"></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
|
<el-form-item label="设备名称" prop="deviceName">
|
<el-input v-model="unitDialogState.unitForm.deviceName" placeholder="设备名称" clearable class="input-length"></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
|
<el-form-item label="设备功率" prop="devicePower">
|
<el-input v-model="unitDialogState.unitForm.devicePower" placeholder="设备功率" clearable class="input-length"></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
|
<el-form-item label="计量单位" prop="deviceUnit">
|
<el-select v-model="unitDialogState.unitForm.deviceUnit" placeholder="计量单位" clearable class="input-length">
|
<el-option v-for="item in unitDialogState.deviceUnitList" :key="item.id" :label="item.name" :value="item.id"></el-option>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
|
<el-form-item label="是否特种设备">
|
<el-select v-model="unitDialogState.unitForm.specialDevice" placeholder="是否特种设备" clearable class="input-length">
|
<el-option v-for="item in unitDialogState.specialDeviceList" :key="item.id" :label="item.name" :value="item.id"></el-option>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
|
<el-form-item label="安全防护">
|
<el-input type="textarea" :rows="3" v-model="unitDialogState.unitForm.safeProtect" placeholder="安全防护" clearable class="input-length"></el-input>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
</el-form>
|
<template #footer>
|
<span class="dialog-footer">
|
<el-button @click="unitDialogState.unitDialogVisible = !unitDialogState.unitDialogVisible" size="default">取 消</el-button>
|
<el-button type="primary" @click="onSubmitUnit" size="default">确定</el-button>
|
</span>
|
</template>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script setup lang="ts">
|
import { reactive, ref } from "vue";
|
import {ElMessage} from "element-plus";
|
import {unitApi} from "/@/api/basic/unit";
|
|
const UnitFormRef = ref()
|
|
const unitDialogState = reactive<UnitDialogType>({
|
title: '',
|
unitDialogVisible: false,
|
unitForm: {
|
id: null,
|
deviceCode: '',
|
deviceName: '',
|
devicePower: '',
|
deviceUnit: null,
|
safeProtect: '',
|
},
|
unitFormRules: {
|
deviceCode: [{ required: true, message: '请填写设备编号', trigger: 'blur' }],
|
deviceName: [{ required: true, message: '请填写设备名称', trigger: 'blur' }],
|
devicePower: [{ required: true, message: '请填写设备功率', trigger: 'blur' }],
|
deviceUnit: [{ required: true, message: '请选择计量单位', trigger: 'change' }]
|
},
|
riskSourceTypeList: [
|
{id: 1, name: '区域、实验场所'},
|
{id:2, name: '设施设备'},
|
{id:3, name: '固定工艺节点'},
|
],
|
evaluateStatusList: [
|
{id: 1, name: '未评价'},
|
{id:2, name: '已评价'},
|
]
|
})
|
|
const showUnitDialog = (title: string, value: UnitType) => {
|
unitDialogState.unitDialogVisible = true;
|
setTimeout(() => {
|
UnitFormRef.value.clearValidate();
|
});
|
if(title === '新增'){
|
unitDialogState.title = '新增';
|
unitDialogState.unitForm = {
|
id: null,
|
deviceCode: '',
|
deviceName: '',
|
devicePower: '',
|
deviceUnit: null,
|
safeProtect: '',
|
};
|
}else{
|
unitDialogState.title = '编辑'
|
unitDialogState.unitForm = {
|
id: value.id,
|
deviceCode: value.deviceCode,
|
deviceName: value.deviceName,
|
devicePower: value.devicePower,
|
deviceUnit: value.deviceUnit,
|
safeProtect: value.safeProtect,
|
};
|
}
|
};
|
|
const onSubmitUnit = () => {
|
UnitFormRef.value.validate(async(valid: boolean) => {
|
if(valid){
|
if(unitDialogState.title === '新增'){
|
let res = await unitApi().addUnit(unitDialogState.unitForm);
|
if(res.data.code === 100){
|
emit('refresh')
|
unitDialogState.unitDialogVisible = false;
|
ElMessage({
|
type: 'success',
|
message: '新增成功'
|
})
|
}else{
|
ElMessage({
|
type: 'warning',
|
message: res.data.msg,
|
});
|
}
|
}else{
|
let res = await unitApi().modUnit(unitDialogState.unitForm)
|
if(res.data.code === 100){
|
emit('refresh')
|
unitDialogState.unitDialogVisible = false;
|
ElMessage({
|
type: 'success',
|
message: '编辑成功'
|
})
|
}else{
|
ElMessage({
|
type: 'warning',
|
message: res.data.msg,
|
});
|
}
|
}
|
}else{
|
ElMessage({
|
type: 'warning',
|
message: '请完善基本信息',
|
});
|
}
|
})
|
}
|
|
const emit = defineEmits(['refresh'])
|
|
defineExpose({
|
showUnitDialog
|
})
|
</script>
|
|
<style scoped>
|
|
</style>
|