刘光辉
9 小时以前 0dfe84494048ce27ba8449831782128412d3eb13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<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>