<template>
  <div>
    <BasicDrawer
      v-bind="$attrs"
      destroyOnClose
      @register="registerDrawer"
      :title="getTitle"
      :width="width"
    >
      <Description @register="registerDesc" :data="descData" />
    </BasicDrawer>

    <Button
      v-auth="['storage:config:add']"
      type="primary"
      @click="handleCreate"
      preIcon="icon-plus|iconfont"
    >
      新增
    </Button>
    <FormModal @register="registerModal" @success="handleSuccess" />
  </div>
</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 { archivesPatrolWardDetail } from '/@/api/biz/visit/checkApi';
  import { listDictModel } from '/@/api/common';
  import FormModal from './formModal.vue';
  import { formatDictValue } from '/@/utils';
  import { useModal } from '/@/components/Modal';

  const descData = ref({});
  const getTitle = '查看查房记录';
  const width = '45%';
  const [registerModal, { openModal }] = useModal();

  const typeOptions = ref();
  onBeforeMount(async () => {
    typeOptions.value = await listDictModel({ dictCode: 'sys_login_log_type' });
  });
  // 新增按钮事件
  function handleCreate() {
    openModal(true, {
      isUpdate: false,
    });
  }
  const [registerDrawer] = useDrawerInner(async data => {
    console.log('::::::::::', data.record);
    const resData = await archivesPatrolWardDetail(data.record.id);
    descData.value = {
      ...resData,
      type: formatDictValue(typeOptions.value, resData.type),
    };
  });
  const [registerDesc] = useDescription({
    schema: viewSchema,
    column: 1,
    size: 'middle',
    labelStyle: {
      width: '120px',
    },
  });
  // 弹窗回调事件
  async function handleSuccess({ isUpdate, values }) {
    console.log(isUpdate);
    console.log(values);
  }
</script>
