<script lang="ts" setup>
import { ref } from 'vue';

import { useVbenModal } from '@vben/common-ui';

import { message, Radio, RadioGroup } from 'ant-design-vue';

import {refuseReceptionApi, refuseReceptionListApi} from '#/views/doctor/doctor-reception/api';

const registerId = ref('');
const refuseReception = ref('');
const refuseReceptionList = ref([]);
const activeRegister = ref();
const getPatientListByReceptionApi = ref();
const updateReceptionStatusApi = ref();

const [Modal, modalApi] = useVbenModal({
  fullscreenButton: false,
  draggable: true,
  onCancel() {
    modalApi.close();
  },
  onConfirm: async () => {
    if (registerId.value === '') {
      message.error('请选择接诊单');
      return;
    }
    if (refuseReception.value === '') {
      message.error('请选择拒诊原因');
      return;
    }
    refuseReceptionApi({
      register_id: registerId.value,
      refuse_reason: refuseReception.value,
    }).then(() => {
      if (getPatientListByReceptionApi.value) {
        getPatientListByReceptionApi.value();
      }
      if (updateReceptionStatusApi.value) {
        updateReceptionStatusApi.value(activeRegister.value);
      }
      modalApi.close();
      message.success('拒绝成功');
    });
    // setUpdateDiagnosis.value(selectDiagnosisList.value);
  },
  onOpenChange(isOpen: boolean) {
    if (isOpen) {
      // 更新患者列表
      getPatientListByReceptionApi.value = isOpen
        ? modalApi.getData()?.getPatientListByReception
        : null;
      // 更新患者信息
      updateReceptionStatusApi.value = isOpen
        ? modalApi.getData()?.updateReceptionStatus
        : null;
      // // 当前挂号信息
      // activeRegister.value = isOpen
      //   ? modalApi.getData()?.activeRegister
      //   : null;
      // console.log('模态框：', activeRegister.value)
      const { values } = modalApi.getData<Record<string, any>>();
      if (values) {
        registerId.value = values.register_id;
        refuseReceptionListApi().then((res) => {
          refuseReceptionList.value = res;
        });
        console.log(values.register_id, 'sssssssssss');
        // selectDiagnosisList.value = values;
      }
    }
  },
});
</script>

<template>
  <Modal class="w-[20%]" title="拒诊原因">
    挂号ID：{{ registerId }}
    <RadioGroup style="align-items: center" v-model:value="refuseReception">
      <Radio
        v-for="item in refuseReceptionList"
        :key="item.key"
        :value="item.value"
        class="mt-3 w-full"
      >
        {{ item.value }}
      </Radio>
    </RadioGroup>
  </Modal>
</template>
<style lang="scss"></style>
