<!--
 * @Author: zhanghaifeng
 * @Date: 2024-11-27 15:44:12
 * @LastEditors: zhanghaifeng
 * @LastEditTime: 2025-06-24 17:11:05
 * @Description:
 * @FilePath: /hospital-project/src/components/personList/index.vue
-->
<template>
  <div class="mr-8">
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="title" width="100">
        <template #default="scope">
          <div class="text-black">{{ scope.row.quotaName }}</div>
        </template>
      </el-table-column>
      <el-table-column
        v-if="showList?.showIndicRemark"
        prop="remark"
        label="指标说明"
      />
      <el-table-column
        v-if="showList?.showScoreRule"
        prop="scoreRule"
        label="评价标准"
      />
      <el-table-column
        v-if="showList?.showDatasource"
        prop="datasoure"
        label="数据来源"
      />
      <el-table-column
        v-if="showList?.showTargetValue"
        prop="targetValue"
        label="目标值"
      />
      <el-table-column prop="finalValue" label="完成值" />
      <el-table-column
        v-if="showList?.showStartValue"
        prop="startValue"
        label="门槛值"
      />
      <el-table-column
        v-if="showList?.showChallengeValue"
        prop="challengeValue"
        label="挑战值"
      />
      <el-table-column prop="ranking" label="排名" />
      <el-table-column prop="quotaScore" label="得分" />
    </el-table>
  </div>
</template>

<script lang="ts" setup>
import { ref, nextTick, watch } from "vue";
const tableData = ref([]);
const showList = ref();
const watchData = ref();
const props = defineProps({
  paramsIndex: {
    type: Object
  },
  detailData: {
    type: Array,
    default: () => []
  }
});
watch(props, newVal => {
  showList.value = newVal.detailData[0]?.dimensionList[0];
  tableData.value = newVal.detailData[0]?.dimensionList[0]?.quotaList;
});
const init = (data?: any, id?: any) => {
  if (data) {
    tableData.value = [];
    watchData.value = data;
    setTimeout(() => {
      nextTick(() => {
        if (id) {
          data[0]?.dimensionList.map(it => {
            if (it.dimId == id) {
              showList.value = it;
              tableData.value = it.quotaList;
            }
          });
        } else {
          showList.value = data[0]?.dimensionList[0];
          tableData.value = data[0]?.dimensionList[0].quotaList;
        }
      });
    }, 0);
  }
};
watch(
  watchData.value,
  newVal => {
    showList.value = newVal[0]?.dimensionList[0];
    tableData.value = newVal[0]?.dimensionList[0].quotaList;
  },
  { deep: true }
);
defineExpose({
  init
});
</script>
