<template>
  <div>
    <div class="mx-2 mb-6" v-for="item in basicData" :key="item.type">
      <DescCard :title="item.title" :type="item.type" :data="item.data" :id="info.id" />
    </div>
  </div>
</template>

<script setup lang="ts">
  import { ref, reactive } from 'vue';
  import DescCard from '/@/components/XTCard/src/DescCard.vue';
  import { BasicData } from './data';
  import { onMounted } from 'vue';
  import { formatDictValue } from '/@/utils';
  import { engineerDialysisDeviceDetail } from '/@/api/biz/engineer/dialysisDeviceApi';
  import { listDictModelBatch } from '/@/api/common';

  const props = defineProps({
    info: {
      type: Object,
      default: () => {},
    } as any,
  });
  const bizDictOptions = reactive({
    deviceType: [],
  });
  const bizDictData = ref([
    { key: 'deviceType', dictCode: 'bm_det' },
    { key: 'pumpType', dictCode: 'bm_pump' },
    { key: 'infectiousDiseases', dictCode: 'pb_epidemic' },
  ]);
  onMounted(async () => {
    const res = await listDictModelBatch(bizDictData.value.map(ele => ele.dictCode));
    for (const i in res) {
      const filter = bizDictData.value.filter(ele => ele.dictCode == i)[0];
      bizDictOptions[filter.key] = res[i];
    }
    await getData();
  });
  const basicData = ref(BasicData as any);
  // 获取数据
  async function getData() {
    const res = await engineerDialysisDeviceDetail(props.info?.id);
    basicData.value[0].data.forEach(ele => {
      if (ele.dict) {
        ele.value = formatDictValue(bizDictOptions[ele.field], res[ele.field]);
      } else {
        ele.value = res[ele.field];
      }
    });
  }
</script>

<style lang="less" scoped></style>
