<template>
  <j-modal :title="title" width="70vw" :visible="visible" @ok="handleOk"
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }" @cancel="handleCancel" cancelText="关闭">
    <OrgApplyInfoForm ref="registerForm" @ok="submitCallback" :formDisabled="disableSubmit" :formBpm="false">
    </OrgApplyInfoForm>
  </j-modal>
  <j-modal title="合同上传" width="70vw" :visible="contractVisible" @cancel="handleContractCancel">
    <template #footer>
      <a-button @click="handleContractCancel">关闭</a-button>
      <a-button @click="saveContract">保存为草稿</a-button>
      <a-button type="primary" @click="submitContract">保存并提交</a-button>
    </template>
    <OrgUpContractForm ref="upContractForm" @ok="submitContractCallback" :formBpm="false"></OrgUpContractForm>
  </j-modal>
</template>

<script lang="ts" setup>
import { ref, nextTick, defineExpose } from 'vue';
import OrgApplyInfoForm from './OrgApplyInfoForm.vue'
import OrgUpContractForm from './OrgUpContractForm.vue'
import JModal from '/@/components/Modal/src/JModal/JModal.vue';

const title = ref<string>('');
const visible = ref<boolean>(false);
const disableSubmit = ref<boolean>(false);
const registerForm = ref();
const contractVisible = ref<boolean>(false);
const upContractForm = ref();
const emit = defineEmits(['register', 'success']);
function handleExtraButton(){

}
/**
 * 新增
 */
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;
}

/**
 * 关闭合同上传窗口
 */
function handleContractCancel() {
  contractVisible.value = false
}

/**
 * 打开上传合同编辑窗口
 */
function editContract(record) {
  contractVisible.value = true
  nextTick(() => {
    upContractForm.value.edit(record);
  });
}

/**
 * 上传合同提交
 */
function submitContractCallback() {
  console.log(99999)
  handleContractCancel();
  emit('success');
}

/**
 * 保存为草稿
 */
function saveContract() {
  upContractForm.value.saveForm();
}

/**
 * 保存并提交
 */
function submitContract() {
  upContractForm.value.submitForm();
}

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

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