<template>
|
<Dialog v-model="dialogVisible" :title="dialogTitle" width="50%">
|
<el-form
|
ref="formRef"
|
v-loading="formLoading"
|
:model="formData"
|
:rules="formRules"
|
label-width="120px"
|
>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="编号" prop="itemno">
|
<el-input v-model="formData.itemno" placeholder="请输入编号"/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="预测项名" prop="itemname">
|
<el-input v-model="formData.itemname" placeholder="请输入预测项名"/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="类型ID" prop="itemtypeid">
|
<el-input v-model="formData.itemtypeid" placeholder="请输入类型ID"/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="类型名称" prop="itemtypename">
|
<el-input v-model="formData.itemtypename" placeholder="请输入类型名称"/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="粒度" prop="granularity">
|
<el-input v-model="formData.granularity" placeholder="请输入粒度"/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="是否融合" prop="isfuse">
|
<el-input v-model="formData.isfuse" placeholder="请输入是否融合"/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="是否检查" prop="workchecked">
|
<el-input v-model="formData.workchecked" placeholder="请输入是否检查"/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="模块ID" prop="moduleid">
|
<el-input v-model="formData.moduleid" placeholder="请输入模块ID"/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="排序" prop="itemorder">
|
<el-input v-model="formData.itemorder" placeholder="请输入排序"/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="是否启用" prop="status">
|
<el-input v-model="formData.status" placeholder="请输入是否启用"/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="类别ID" prop="categoryid">
|
<el-input v-model="formData.categoryid" placeholder="请输入类别ID"/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="数据点ID" prop="pointid">
|
<el-input v-model="formData.pointid" placeholder="请输入数据点ID"/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="数据点名称" prop="tagname">
|
<el-input v-model="formData.tagname" placeholder="请输入数据点名称"/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="存放表ID" prop="resulttableid">
|
<el-input v-model="formData.resulttableid" placeholder="请输入存放表ID"/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="存放表" prop="tablename">
|
<el-input v-model="formData.tablename" placeholder="请输入存放表"/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
</el-form>
|
<template #footer>
|
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
</template>
|
</Dialog>
|
</template>
|
<script lang="ts" setup>
|
import * as MmPredictItem from '@/api/model/pre/predict'
|
|
defineOptions({name: 'DataMmPredictItemForm'})
|
|
const {t} = useI18n() // 国际化
|
const message = useMessage() // 消息弹窗
|
const dialogVisible = ref(false) // 弹窗的是否展示
|
const dialogTitle = ref('') // 弹窗的标题
|
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
const formData = ref({
|
id: undefined,
|
itemno: undefined,
|
itemname: undefined,
|
itemtypeid: undefined,
|
itemtypename: undefined,
|
granularity: undefined,
|
isfuse: undefined,
|
workchecked: undefined,
|
moduleid: undefined,
|
itemorder: undefined,
|
status: undefined,
|
categoryid: undefined,
|
pointid: undefined,
|
tagname: undefined,
|
resulttableid: undefined,
|
tablename: undefined,
|
})
|
const formRules = reactive({
|
itemno: [{required: true, message: '编号不能为空', trigger: 'blur'}],
|
itemname: [{required: true, message: '预测项名不能为空', trigger: 'blur'}],
|
})
|
const formRef = ref() // 表单 Ref
|
|
/** 打开弹窗 */
|
const open = async (type: string, id?: number) => {
|
dialogVisible.value = true
|
dialogTitle.value = t('action.' + type)
|
formType.value = type
|
resetForm()
|
// 修改时,设置数据
|
if (id) {
|
formLoading.value = true
|
try {
|
formData.value = await MmPredictItem.getMmPredictItem(id)
|
} finally {
|
formLoading.value = false
|
}
|
}
|
}
|
defineExpose({open}) // 提供 open 方法,用于打开弹窗
|
|
/** 提交表单 */
|
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
const submitForm = async () => {
|
// 校验表单
|
if (!formRef) return
|
const valid = await formRef.value.validate()
|
if (!valid) return
|
// 提交请求
|
formLoading.value = true
|
try {
|
const data = formData.value as unknown as MmPredictItem.MmPredictItemVO
|
if (formType.value === 'create') {
|
await MmPredictItem.createMmPredictItem(data)
|
message.success(t('common.createSuccess'))
|
} else {
|
await MmPredictItem.updateMmPredictItem(data)
|
message.success(t('common.updateSuccess'))
|
}
|
dialogVisible.value = false
|
// 发送操作成功的事件
|
emit('success')
|
} finally {
|
formLoading.value = false
|
}
|
}
|
|
/** 重置表单 */
|
const resetForm = () => {
|
formData.value = {
|
id: undefined,
|
itemno: undefined,
|
itemname: undefined,
|
itemtypeid: undefined,
|
itemtypename: undefined,
|
granularity: undefined,
|
isfuse: undefined,
|
workchecked: undefined,
|
moduleid: undefined,
|
itemorder: undefined,
|
status: undefined,
|
categoryid: undefined,
|
pointid: undefined,
|
tagname: undefined,
|
resulttableid: undefined,
|
tablename: undefined,
|
}
|
formRef.value?.resetFields()
|
}
|
</script>
|