龚焕茏
2024-03-13 4e53e13c41c87e46dce5fdd938684c5c665ca51f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<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>