<script lang="ts" setup>
|
import { computed, nextTick, ref, unref } from 'vue';
|
|
import { BasicModal, useModalInner } from '@jnpf/ui/modal';
|
|
import Parser from '#/components/FormGenerator/src/components/Parser.vue';
|
import { $t } from '#/locales';
|
|
const props = defineProps(['formConf']);
|
defineEmits(['register']);
|
const [registerModal, { changeOkLoading }] = useModalInner(init);
|
const parserRef = ref<any>(null);
|
const loading = ref(true);
|
const key = ref(Date.now());
|
const reviewVisible = ref(!!props.formConf.hasReviewBtn && !props.formConf.reviewBtnConfig?.noShow);
|
const reviewPassed = ref(!isReviewRequired());
|
|
function isReviewRequired() {
|
return reviewVisible.value && !props.formConf.reviewBtnConfig?.biz_review_optional;
|
}
|
|
const getOkText = computed(() => {
|
const text = props.formConf.confirmButtonTextI18nCode
|
? $t(props.formConf.confirmButtonTextI18nCode, props.formConf.confirmButtonText)
|
: props.formConf.confirmButtonText;
|
return text || $t('common.okText');
|
});
|
const getReviewText = computed(() => {
|
const text = props.formConf.reviewButtonTextI18nCode
|
? $t(props.formConf.reviewButtonTextI18nCode, props.formConf.reviewButtonText)
|
: props.formConf.reviewButtonText;
|
return text || $t('common.reviewText');
|
});
|
const getCancelText = computed(() => {
|
const text = props.formConf.cancelButtonTextI18nCode
|
? $t(props.formConf.cancelButtonTextI18nCode, props.formConf.cancelButtonText)
|
: props.formConf.cancelButtonText;
|
return text || $t('common.cancelText');
|
});
|
|
function init() {
|
loading.value = true;
|
reviewVisible.value = !!props.formConf.hasReviewBtn && !props.formConf.reviewBtnConfig?.noShow;
|
reviewPassed.value = !isReviewRequired();
|
key.value = Date.now();
|
nextTick(() => {
|
loading.value = false;
|
});
|
}
|
function getParser() {
|
const parser = unref(parserRef);
|
if (!parser) {
|
throw new Error('parser is null!');
|
}
|
return parser;
|
}
|
|
function handleConfirm() {
|
getParser().handleSubmit();
|
}
|
function handleReview() {
|
getParser().handleReview();
|
}
|
function submitForm(data, callback) {
|
changeOkLoading(true);
|
// eslint-disable-next-line no-console
|
console.log('提交数据:', data);
|
if (callback && typeof callback === 'function') callback();
|
changeOkLoading(false);
|
}
|
</script>
|
<template>
|
<BasicModal
|
v-bind="$attrs"
|
@register="registerModal"
|
:title="$t('common.previewText')"
|
@ok="handleConfirm"
|
can-fullscreen
|
destroy-on-close
|
:ok-text="getOkText"
|
:ok-button-props="{ disabled: reviewVisible && !reviewPassed }"
|
:cancel-text="getCancelText">
|
<template #insertFooter>
|
<a-button v-if="reviewVisible" @click="handleReview">{{ getReviewText }}</a-button>
|
</template>
|
<Parser
|
ref="parserRef"
|
:form-conf="formConf"
|
:is-preview="true"
|
:model-id="formConf.id"
|
@review-status-change="reviewPassed = $event"
|
@review-visibility-change="reviewVisible = $event"
|
@submit="submitForm"
|
:key="key"
|
v-if="!loading" />
|
</BasicModal>
|
</template>
|