<template>
  <a-modal :title="title" :width="width" :visible="visible" @ok="handleOk" :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }" @cancel="handleCancel" cancelText="关闭">
    
     <!-- 基本信息区域 -->
    <a-descriptions title="基本信息" class="modal-content">
      <a-descriptions-item label="压力测试名称">{{ bcsStreTest.name }}</a-descriptions-item>
      <a-descriptions-item label="牵头部门">{{ bcsStreTest.handleDepart }}</a-descriptions-item>
      <a-descriptions-item label="涉及的重要业务">{{ bcsStreTest.linkBusiName }}</a-descriptions-item>
      <a-descriptions-item label="涉及的重要信息系统">{{ bcsStreTest.linkSystemName }}</a-descriptions-item>
      <a-descriptions-item label="压力测试日期">{{ bcsStreTest.sttime }}</a-descriptions-item>
      <a-descriptions-item label="说明" :span="2">{{ bcsStreTest.des }}</a-descriptions-item>
    </a-descriptions>

    <a-descriptions title="特性信息" class="modal-content">
    </a-descriptions>

   

    <BcsStreTestexeFormView ref="registerForm"  :testId="testId"  @ok="submitCallback" :formDisabled="disableSubmit" :formBpm="false"></BcsStreTestexeFormView>
      
    

  </a-modal>
</template>

<script lang="ts" setup>
  import { ref, reactive, nextTick, defineExpose } from 'vue';
  
  import BcsStreTestexeFormView from './BcsStreTestexeFormView.vue';
  

  // 类型定义
interface BcsStreTest {
  name: string;
  handleDepart: string;
  linkBusiName: string;
  linkSystemName: string;
  sttime: string;
  des: string;
}
  
  const title = ref<string>('');
  const width = ref<number>(1024);
  const visible = ref<boolean>(false);
  const disableSubmit = ref<boolean>(false);
  const registerForm = ref();
  const emit = defineEmits(['register', 'success']);
  const testId = ref<number>(0);

  // 事件信息
const bcsStreTest = reactive<BcsStreTest>({
  name: '',
  handleDepart: '',
  linkBusiName: '',
  linkSystemName: '',
  sttime: '',
  des: ''
});


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

    testId.value = record.id;
    
    /**
    nextTick(() => {
      registerForm.value.edit(record);
    });
    */

    // 安全地更新事件信息
  Object.assign(bcsStreTest, {
    name: record.name || '',
    handleDepart: record.handleDepart || '',
    linkBusiName: record.linkBusiName || '',
    linkSystemName: record.linkSystemName || '',
    sttime: record.sttime || '',
    des: record.des || ''
  });

  //alert("record.id "+record.id);

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

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

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

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

<style>
  /**隐藏样式-modal确定按钮 */
  .jee-hidden {
    display: none !important;
  }
  .modal-content {
  padding: 0 15px;
  
  &:not(:last-child) {
    margin-bottom: 16px;
  }
  }

</style>
