<template>
  <BasicDrawer
    v-bind="$attrs"
    destroyOnClose
    @register="registerDrawer"
    :title="getTitle"
    :width="width"
  >
    <Description @register="registerDesc" :data="descData" />
  </BasicDrawer>
</template>
<script lang="ts" setup>
  import { onBeforeMount, ref } from 'vue'; // onBeforeMount,
  import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
  import { Description, useDescription } from '/@/components/Description';
  import { viewSchema } from './data';

  import { smsTempDetail } from '/@/api/sys/smsTempApi';
  import { listDictModel } from '/@/api/common';
  import { formatDictValue } from '/@/utils';

  const descData = ref({});
  const getTitle = '查看短信模板';
  const width = '45%';

  const createTypeOptions = ref();
  const tempTypeOptions = ref();
  const disableOptions = ref();
  onBeforeMount(async () => {
    createTypeOptions.value = await listDictModel({ dictCode: 'sys_create_type' });
    tempTypeOptions.value = await listDictModel({ dictCode: 'sys_temp_type' });
    disableOptions.value = await listDictModel({ dictCode: 'sys_disable_type' });
  });
  const [registerDrawer] = useDrawerInner(async data => {
    console.log('::::::::::', data.record);
    const resData = await smsTempDetail(data.record.id);
    descData.value = {
      ...resData,
      createType: formatDictValue(createTypeOptions.value, resData.createType),
      tempType: formatDictValue(tempTypeOptions.value, resData.tempType),
      disable: formatDictValue(disableOptions.value, resData.disable),
    };
  });
  const [registerDesc] = useDescription({
    schema: viewSchema,
    column: 2,
    size: 'middle',
    labelStyle: {
      width: '130px',
    },
  });
</script>
