<template>
  <Card :bordered="false">
    <Descriptions bordered :column="3">
      <Descriptions.Item
        v-for="p in displayProps"
        :key="p.title"
        :label="p.title"
        :span="['avatar'].includes(p.name) ? 3 : 1"
      >
        <span v-if="p.key === 'licensePic'">
          <ImagePreview :imageList="[p.value]" style="width: 120px" />
        </span>
        <template v-else>
          {{ p.value }}
        </template>
      </Descriptions.Item>
    </Descriptions>
  </Card>
</template>
<script lang="ts" setup name="DeviceDetail">
  import { onMounted, computed, ref, reactive } from 'vue';
  import { useRoute } from 'vue-router';
  import { ComputedRef } from '@vue/reactivity';
  import { Descriptions, Card } from 'ant-design-vue';
  import { descriptionColumns } from './schema';
  import * as HospitalApi from '/@/api/system/hospitalApi';
  import { Hospital } from '/@/api/model/hospital';
  import { ImagePreview } from '/@/components/Preview/index';

  const route = useRoute();
  const id = ref(route.params?.id);
  let data = reactive({
    detail: {},
    isOver: false,
  });
  const getDetail = () => {
    HospitalApi.getById(id.value).then((res: Hospital) => {
      data.isOver = true;
      data.detail = res;
    });
  };

  onMounted(() => {
    getDetail();
  });

  const displayProps: ComputedRef<Array<any>> = computed(() => {
    if (!data.isOver) return {};
    const display: any = descriptionColumns.map(({ title, dataIndex = '', customRender }) => ({
      key: dataIndex,
      title,
      value: customRender
        ? customRender({ text: data.detail[dataIndex], record: data.detail })
        : data.detail[dataIndex],
    }));
    return display;
  });
</script>

<style scoped></style>
