<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 { smsLogDetail } from '/@/api/sys/smsLogApi';
  import { listDictModel } from '/@/api/common';
  import { formatDictValue } from '/@/utils';

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

  const sendStatusOptions = ref();
  const receiveStatusOptions = ref();
  const templateTypeOptions = ref();
  onBeforeMount(async () => {
    sendStatusOptions.value = await listDictModel({ dictCode: 'sys_sms_send' });
    receiveStatusOptions.value = await listDictModel({ dictCode: 'sys_sms_reveice' });
    templateTypeOptions.value = await listDictModel({ dictCode: 'sys_temp_type' });
  });
  const [registerDrawer] = useDrawerInner(async data => {
    console.log('::::::::::', data.record);
    const resData = await smsLogDetail(data.record.id);
    descData.value = {
      ...resData,
      sendStatus: formatDictValue(sendStatusOptions.value, resData.sendStatus),
      receiveStatus: formatDictValue(receiveStatusOptions.value, resData.receiveStatus),
      templateType: formatDictValue(templateTypeOptions.value, resData.templateType),
    };
  });
  const [registerDesc] = useDescription({
    schema: viewSchema,
    column: 2,
    size: 'middle',
    labelStyle: {
      width: '155px',
    },
  });
</script>
