<template>
|
<Dialog v-model="dialogVisible" :title="dialogTitle" width="55%">
|
<el-form
|
ref="formRef"
|
v-loading="formLoading"
|
:model="formData"
|
:rules="formRules" label-width="100px">
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="指标编码" prop="itemNo">
|
<el-input v-model="formData.itemNo" disabled/>
|
</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="指标分类" prop="itemCategory">
|
<el-select v-model="formData.itemCategory" clearable placeholder="请选择指标分类">
|
<el-option
|
v-for="item in dataCategoryList"
|
:key="item.id"
|
:label="item.label"
|
:value="item.id + ''"
|
/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="时间粒度" prop="timeGranularity">
|
<el-select v-model="formData.timeGranularity" placeholder="请选择">
|
<el-option
|
v-for="dict in getStrDictOptions(DICT_TYPE.TIME_GRANULARITY)"
|
:key="dict.value"
|
:label="dict.label"
|
:value="dict.value"
|
/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="6">
|
<el-form-item label="指标精度" prop="precision">
|
<el-input v-model="formData.precision"/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="6">
|
<el-form-item label="转换系数" prop="coefficient">
|
<el-input v-model="formData.coefficient"/>
|
</el-form-item>
|
</el-col>
|
<el-col :span="6">
|
<el-form-item label="数量单位" prop="unit">
|
<el-input v-model="formData.unit"/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="6">
|
<el-form-item label="数据集" prop="atomItem.dataSet">
|
<el-select v-model="formData.atomItem.dataSet" clearable placeholder="请选择数据集" @change="handleDataSetChange($event)">
|
<el-option
|
v-for="item in dataSetList"
|
:key="item.id"
|
:label="item.name"
|
:value="item.id + ''"
|
/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="6">
|
<el-form-item label="使用字段" prop="atomItem.usingField">
|
<el-select v-model="formData.atomItem.usingField" clearable placeholder="请选择字段">
|
<el-option
|
v-for="item in dataSetFieldList"
|
:key="item.id"
|
:label="item.fieldCode"
|
:value="item.id + ''"
|
/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="6">
|
<el-form-item label="统计方式" prop="statFunc">
|
<el-select v-model="formData.atomItem.statFunc" placeholder="请选择">
|
<el-option
|
v-for="dict in getStrDictOptions(DICT_TYPE.DATA_STAT_FUNC)"
|
:key="dict.value"
|
:label="dict.label"
|
:value="dict.value"
|
/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="24">
|
<el-form-item label="备注" prop="remark">
|
<el-input v-model="formData.remark" type="textarea" maxlength="100"/>
|
</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 {DICT_TYPE, getStrDictOptions} from '@/utils/dict'
|
import * as ItemApi from '@/api/data/ind/item/item'
|
import * as DataSetApi from '@/api/data/ind/data/data.set'
|
import * as DataSetFieldApi from '@/api/data/ind/data/data.field'
|
import * as CategoryApi from '@/api/data/ind/category/index'
|
|
|
defineOptions({name: 'IndDataSetForm'})
|
|
const {t} = useI18n() // 国际化
|
const message = useMessage() // 消息弹窗
|
|
const dialogVisible = ref(false) // 弹窗的是否展示
|
const dialogTitle = ref('') // 弹窗的标题
|
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
let formData = ref({
|
id: undefined,
|
itemNo: '',
|
itemName: '',
|
itemType: '',
|
itemCategory: '',
|
coefficient: 1,
|
precision: 0,
|
businessType: '',
|
timeRange: '',
|
timeGranularity: '',
|
remark: '',
|
atomItem:{
|
dataSource:'',
|
dataSet: '',
|
usingField: '',
|
statFunc: ''
|
}
|
})
|
const validateAsNumber = (rule, value, callback) => {
|
const regex = /^(\-|\+)?\d+(\.\d+)?$/;
|
if (!regex.test(value)) {
|
callback(new Error('请输入数字!'));
|
}
|
}
|
const formRules = reactive({
|
itemName: [{required: true, message: '指标名称不能为空', trigger: 'blur'}],
|
itemCategory: [{required: true, message: '指标分类不能为空', trigger: 'blur'}],
|
/*precision: [{validator: validateAsNumber, trigger: 'blur' }],
|
coefficient: [{validator: validateAsNumber, trigger: 'blur' }],
|
statFunc: [{required: true, message: '统计方式不能为空', trigger: 'blur'}],
|
timeGranularity: [{required: true, message: '时间粒度不能为空', trigger: 'blur'}],
|
"atomItem.dataSet": [{required: true, message: '数据集不能为空', trigger: 'blur'}],
|
"atomItem.usingField":[{required: true, message: '使用字段不能为空', trigger: 'blur'}]*/
|
})
|
const formRef = ref() // 表单 Ref
|
const dataSetList = ref([] as DataSetApi.DataSetVO[])
|
const dataSetFieldList = ref([] as DataSetFieldApi.DataSetFieldVO[])
|
const dataCategoryList = ref([])
|
/** 打开弹窗 */
|
const open = async (type: string, id?: string) => {
|
dialogVisible.value = true
|
dialogTitle.value = '原子指标'
|
formType.value = type
|
resetForm()
|
// 加载数据源列表
|
dataSetList.value = await DataSetApi.getDataSetList()
|
dataCategoryList.value = await CategoryApi.getCategoryListAllSimple()
|
// 修改时,设置数据
|
if (id) {
|
formLoading.value = true
|
try {
|
formData.value = await ItemApi.getItem(id)
|
if(formData.value.atomItem.dataSet !== null){
|
const queryParams = reactive({
|
dataSetId: formData.value.atomItem.dataSet,
|
})
|
dataSetFieldList.value = (await DataSetFieldApi.getDataSetFieldPage(queryParams)).list
|
}
|
} finally {
|
formLoading.value = false
|
}
|
}
|
|
}
|
defineExpose({open}) // 提供 open 方法,用于打开弹窗
|
|
/** 提交表单 */
|
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
const submitForm = async () => {
|
debugger
|
// 校验表单
|
if (!formRef) return
|
const valid = await formRef.value.validate()
|
if (!valid) return
|
// 提交请求
|
formLoading.value = true
|
try {
|
formData.value.itemType = 'ATOM'
|
for (let index in dataSetList.value){
|
if(formData.value.atomItem.dataSet === dataSetList.value[index].id){
|
formData.value.atomItem.dataSource = dataSetList.value[index].dataSource
|
}
|
}
|
const data = formData.value as ItemApi.ItemVO
|
if (formType.value === 'create') {
|
await ItemApi.createItem(data)
|
message.success(t('common.createSuccess'))
|
} else {
|
await ItemApi.updateItem(data)
|
message.success(t('common.updateSuccess'))
|
}
|
dialogVisible.value = false
|
// 发送操作成功的事件
|
emit('success')
|
} finally {
|
formLoading.value = false
|
}
|
}
|
|
/** 重置表单 */
|
const resetForm = () => {
|
formData.value = {
|
id: '',
|
itemNo: '',
|
itemName: '',
|
itemType: '',
|
itemCategory: '',
|
coefficient: 1,
|
precision: 0,
|
businessType: '',
|
timeRange: '',
|
timeGranularity: '',
|
remark: '',
|
atomItem:{
|
dataSource:'',
|
dataSet: '',
|
usingField: '',
|
statFunc: ''
|
}
|
}
|
dataSetFieldList.value = []
|
formRef.value?.resetFields()
|
}
|
|
async function handleDataSetChange(event) {
|
if (event !== null && event !== undefined) {
|
const queryParams = reactive({
|
dataSetId: event,
|
})
|
dataSetFieldList.value = (await DataSetFieldApi.getDataSetFieldPage(queryParams)).list
|
}
|
}
|
|
</script>
|