<template>
    <div style="margin-bottom: 20px;">
        <el-button type="primary" @click="check" v-if="previewVisible">校验</el-button>
    </div>
    <ElGenerateForm ref="generateFormRef" v-if="previewVisible" :data="widgetForm" />
</template>

<script setup lang='ts'>
import { ref } from 'vue'
import { checkCommon } from '@/services/api/platformProducts'
import ElGenerateForm from '../../../../vueFormCreate/core/element/ElGenerateForm.vue'
import { ElMessage } from 'element-plus';

const previewVisible = ref(false)
const widgetForm = ref()
const generateFormRef = ref()
const dataJsonTemplate = ref({
    data: ''
})

const props = defineProps({
    code: {
        type: String,
        default: ''
    }
})

const emits = defineEmits(['codeData'])

// 获取数据
const handleGetData = () => {
    generateFormRef.value.getData().then((res: any) => {
        dataJsonTemplate.value.data = res
        emits('codeData', props.code, res)
    })
}

const check = () => {
    generateFormRef.value.getData().then((res: any) => {
        if (res) {
            checkCommon({ code: props.code, data: res }).then((checkData: any) => {
                if (checkData.code === 200) ElMessage({ type: 'success', message: '校验通过' })
            })
        }
    })
}

defineExpose({
    previewVisible,
    widgetForm,
    handleGetData
})
</script>
 
<style lang = "scss" scoped>
</style>