<template>
|
<div class="p-2">
|
<el-form ref="indicatorInfoFormRef" :model="form" :rules="rules" label-width="80px">
|
<el-form-item :label="indicator.indicatorName" v-for="indicator in indicatorInfoList" :key="indicator.id">
|
<el-radio-group v-model="indicator.status">
|
<el-radio :label="2">接口取值</el-radio>
|
<el-radio :label="1">自定义</el-radio>
|
</el-radio-group>
|
</el-form-item>
|
</el-form>
|
<div class="dialog-footer">
|
<el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
|
</div>
|
</div>
|
</template>
|
|
<script setup lang="ts">
|
import { ref, reactive, onMounted, toRefs } from 'vue';
|
import { listIndicatorInfo, updateIndicatorInfo } from '@/api/indicatorInfo';
|
import { IndicatorInfoVO, IndicatorInfoForm } from '@/api/indicatorInfo/types';
|
import { ElForm, ElFormItem, ElRadioGroup, ElRadio, ElButton } from 'element-plus';
|
|
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
|
const indicatorInfoList = ref<IndicatorInfoVO[]>([]);
|
const buttonLoading = ref(false);
|
const loading = ref(true);
|
const total = ref(0);
|
|
const indicatorInfoFormRef = ref<ElFormInstance>();
|
|
const initFormData: IndicatorInfoForm = {
|
id: undefined,
|
indicatorName: undefined,
|
status: undefined
|
}
|
const data = reactive({
|
form: {...initFormData},
|
queryParams: {
|
pageNum: 1,
|
pageSize: 10,
|
indicatorName: undefined,
|
createTime: undefined,
|
status: undefined,
|
params: {}
|
},
|
rules: {
|
id: [
|
{ required: true, message: "编号不能为空", trigger: "blur" }
|
],
|
indicatorName: [
|
{ required: true, message: "指标名称不能为空", trigger: "blur" }
|
],
|
status: [
|
{ required: true, message: "状态 1自定义 2指标取值不能为空", trigger: "change" }
|
]
|
}
|
});
|
|
const { queryParams, form, rules } = toRefs(data);
|
|
/** 查询指标取值列表 */
|
const getList = async () => {
|
loading.value = true;
|
try {
|
const res = await listIndicatorInfo(queryParams.value);
|
indicatorInfoList.value = res.rows;
|
total.value = res.total;
|
} catch (error) {
|
console.error(error);
|
} finally {
|
loading.value = false;
|
}
|
}
|
|
/** 提交按钮 */
|
const submitForm = async () => {
|
try {
|
// 循环提交每个单独的对象
|
for (const indicator of indicatorInfoList.value) {
|
const object = {
|
id: indicator.id,
|
status: indicator.status
|
};
|
console.log(object)
|
await updateIndicatorInfo(object);
|
}
|
await getList();
|
proxy?.$modal.msgSuccess("修改成功");
|
} catch (error) {
|
console.error(error);
|
} finally {
|
buttonLoading.value = false;
|
}
|
}
|
|
onMounted(() => {
|
getList();
|
});
|
</script>
|
|
<style scoped>
|
.p-2 {
|
padding: 2rem;
|
}
|
</style>
|