<template>
  <a-drawer :title="title" width="70vw" :visible="visible" :closable="true" :footer-style="{ textAlign: 'right' }"
    @close="handleCancel">
    <template #footer>
      <a-button type="primary" style="margin-right: 8px" @click="handleCancel">关闭</a-button>
      <a-button type="primary" @click="handleOk" v-if="!disableSubmit">确认</a-button>
    </template>
    <ElderInfoForm v-if="visible" ref="registerForm" @ok="submitCallback" :formDisabled="disableSubmit"
      :formBpm="false">
    </ElderInfoForm>
  </a-drawer>
  <!-- 长者信息变更审核 -->
  <a-drawer :title="title" width="70vw" :visible="elderUpInfoVisible" :closable="true"
    :footer-style="{ textAlign: 'right' }" @close="handleElderUpInfoCancel">
    <template #footer>
      <a-button type="primary" style="margin-right: 8px" @click="handleElderUpInfoCancel">关闭</a-button>
      <a-button type="primary" @click="handleElderUpInfoOk">确认</a-button>
    </template>
    <ElderUpInfoForm v-if="elderUpInfoVisible" ref="elderUpInfoForm" @ok="handleElderUpInfoCancel" :formBpm="false">
    </ElderUpInfoForm>
  </a-drawer>
  <!-- 监护人信息变更审核 -->
  <a-drawer :title="title" width="70vw" :visible="upInfoVisible" :closable="true" :footer-style="{ textAlign: 'right' }"
    @close="handleUpInfoCancel">
    <template #footer>
      <a-button type="primary" style="margin-right: 8px" @click="handleUpInfoCancel">关闭</a-button>
      <a-button type="primary" @click="handleUpInfoOk">确认</a-button>
    </template>
    <GuaUpInfoForm v-if="upInfoVisible" ref="upInfoForm" @ok="handleUpInfoCancel" :formBpm="false">
    </GuaUpInfoForm>
  </a-drawer>
  <!-- 护理流程展示 -->
  <a-drawer :title="title" width="100vw" :visible="hllcVisible" :closable="true" :footer-style="{ textAlign: 'right' }"
    @close="handlehllcCancel">
    <template #footer>
      <a-button type="primary" style="margin-right: 8px" @click="handlehllcCancel">关闭</a-button>
    </template>
    <ElderHllc v-if="hllcVisible" ref="hllcForm" @ok="handlehllcCancel" :formBpm="false">
    </ElderHllc>
  </a-drawer>
</template>

<script lang="ts" setup>
import { ref, nextTick, defineExpose } from 'vue';
import ElderInfoForm from './ElderInfoForm.vue'
import JModal from '/@/components/Modal/src/JModal/JModal.vue';
import GuaUpInfoForm from '/@/views/elder/elderinfo/components/GuaUpInfoForm.vue'
import ElderUpInfoForm from '/@/views/elder/elderinfo/components/ElderUpInfoForm.vue'
import ElderHllc from '/@/views/elder/elderinfo/components/ElderHllc.vue'

const title = ref<string>('');
const width = ref<number>(800);
const visible = ref<boolean>(false);
const disableSubmit = ref<boolean>(false);
const registerForm = ref();
const upInfoForm = ref();
const upInfoVisible = ref<boolean>(false);
const hllcVisible = ref<boolean>(false);
const hllcForm = ref();
const elderUpInfoForm = ref();
const elderUpInfoVisible = ref<boolean>(false);
const emit = defineEmits(['register', 'success']);

/**
 * 新增
 */
function add() {
  title.value = '新增';
  visible.value = true;
  nextTick(() => {
    registerForm.value.add();
  });
}

/**
 * 编辑
 * @param record
 */
function edit(record) {
  title.value = disableSubmit.value ? '详情' : '编辑';
  visible.value = true;
  nextTick(() => {
    registerForm.value.edit(record);
  });
}

/**
 * 确定按钮点击事件
 */
function handleOk() {
  registerForm.value.submitForm();
}

/**
 * form保存回调事件
 */
function submitCallback() {
  handleCancel();
  emit('success');
}

/**
 * 取消按钮回调事件
 */
function handleCancel() {
  visible.value = false;
}

/**
 * 监护人信息变更审核
 * @param record
 */
function upInfoEdit(record) {
  title.value = '审核';
  upInfoVisible.value = true;
  nextTick(() => {
    upInfoForm.value.show(record);
  });
}

/**
 * 监护人信息变更确认
 */
function handleUpInfoOk() {
  upInfoForm.value.submitForm();
}

/**
 * 监护人信息变更-关闭
 */
function handleUpInfoCancel() {
  console.log(123123)
  upInfoVisible.value = false
  emit('success');
}
/**
 * 护理流程展示
 * @param record
 */
function handlehllcCancel() {
  hllcVisible.value = false
}

/**
 * 监护人信息变更审核
 * @param record
 */
function hllcView(record) {
  title.value = '护理流程';
  hllcVisible.value = true;
  nextTick(() => {
    hllcForm.value.init(record);
  });
}

/**
 * 长者审核
 * @param record
 */
function upElderInfoEdit(record) {
  title.value = '审核';
  elderUpInfoVisible.value = true;
  nextTick(() => {
    elderUpInfoForm.value.show(record);
  });
}

/**
 * 长者信息变更确认
 */
function handleElderUpInfoOk() {
  elderUpInfoForm.value.submitForm();
}

/**
 * 长者信息变更-关闭
 */
function handleElderUpInfoCancel() {
  console.log(123123)
  elderUpInfoVisible.value = false
  emit('success');
}

defineExpose({
  add,
  edit,
  disableSubmit,
  upInfoEdit,
  upElderInfoEdit,
  hllcView,
});
</script>

<style lang="less">
/**隐藏样式-modal确定按钮 */
.jee-hidden {
  display: none !important;
}
</style>
<style lang="less" scoped></style>
