<template>
  <a-drawer :title="title" :width="width"  v-model:visible="visible" :closable="true"
    :footer-style="{ textAlign: 'right' }" @close="handleCancel">
    <CheckSbForm ref="registerForm" @ok="submitCallback"></CheckSbForm>
    <template #footer>
      <a-button type="primary" style="margin-right: 8px" @click="handleCancel">关闭</a-button>
    </template>
  </a-drawer>
</template>

<script lang="ts" setup>
  import { ref, nextTick, defineExpose } from 'vue';
  import CheckSbForm from './CheckSbForm.vue'
  import JModal from '/@/components/Modal/src/JModal/JModal.vue';
  
  const title = ref<string>('');
  const width = ref<string>('80%');
  const visible = ref<boolean>(false);
  const disableSubmit = ref<boolean>(false);
  const registerForm = ref();
  const emit = defineEmits(['register', 'success']);

  
  /**
   * 编辑
   * @param record
   */
  function init(record) {
    title.value = '电表';
    visible.value = true;
    nextTick(() => {
      registerForm.value.init(record);
    });
  }
  
  /**
   * 确定按钮点击事件
   */
  function handleOk() {
    registerForm.value.submitForm();
  }

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

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

  defineExpose({
    init,
    disableSubmit,
  });
</script>

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