<template>
  <a-drawer :title="title" width="70vw" v-model:visible="visible" :footer-style="{ textAlign: 'right' }" @cancel="handleCancel"
    cancelText="关闭" :maskClosable="true">
    <template #footer>
      <a-button @click="handleCancel">关闭</a-button>
    </template>
    <CanAddDirectiveForm ref="registerForm" v-if="visible" @ok="submitCallback" :formDisabled="disableSubmit"
      :formBpm="false"></CanAddDirectiveForm>
  </a-drawer>
</template>

<script lang="ts" setup>
import { ref, nextTick, defineExpose, defineProps } from 'vue';
import CanAddDirectiveForm from './CanAddDirectiveDetail.vue'
import JModal from '/@/components/Modal/src/JModal/JModal.vue';
import { queryById } from '/@/views/services/serviceDirective/ConfigServiceDirective.api';

const props = defineProps({
});
const title = ref<string>('');
const visible = ref<boolean>(false);
const auditVisible = ref<boolean>(false);
const disableSubmit = ref<boolean>(false);
const registerForm = ref();
const auditListRef = ref();
const emit = defineEmits(['register', 'success']);
const opeType = ref('')//操作类型 add新增 edit编辑 editMedia主列表-指令资源 look详情 audit审核 auditMedia审核列表-指令资源


/**
 * 编辑
 * @param record
 */
function edit(record) {
  title.value = '详情';
  visible.value = true;
  queryById({ dataSourceCode: record.orgCode, id: record.directiveId }).then(res => {
    res.instructionTag = record.instructionTag;
    res.category = record.category;
    res.type = record.type;
    registerForm.value.edit(res);
  })
}

/**
 * 审核列表 - 审核
 * @param record
 */
function audit(record) {
  title.value = '审核';
  visible.value = true;
  nextTick(() => {
    registerForm.value.edit(record, false, true);
  });
}

/**
 * 打开审核列表
 */
function openAuditList() {
  auditVisible.value = true;
  auditListRef.value?.open();
}

/**
 * 编辑指令资源
 * @param record
 */
function editMedia(record) {
  title.value = '编辑指令资源';
  visible.value = true;
  nextTick(() => {
    registerForm.value.edit(record, true);
  });
}

/**
 * 确定按钮点击事件
 */
function handleOk() {
  if (opeType.value == 'audit') {
    registerForm.value.submitAudit();
  } else {
    registerForm.value.submitForm();
  }
}

/**
 * 暂存
 */
function handleSave() {
  registerForm.value.submitForm();
}

/**
 * 给审核对应的业务平台同步资源
 */
function handleMediaAsync() {
  registerForm.value.syncMediaForBizFunc();
}

/**
 * 给所有业务平台同步资源
 */
function handleMediaSyncAllPlat() {
  registerForm.value.syncMediaForAllBizFunc();
}

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

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

/**
 * 审核列表-关闭按钮回调事件
 */
function handleAuditCancel() {
  auditVisible.value = false;
  emit('success')
}

defineExpose({
  edit,
  editMedia,
  disableSubmit,
  audit,
  openAuditList,
  opeType,
});
</script>

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