<!--
 * @Description: 
 * @Author: gcz
 * @Date: 2023-09-21 13:57:16
 * @LastEditors: gcz
 * @LastEditTime: 2023-09-22 15:00:06
 * @FilePath: \gybank_webui\src\views\tool\customerform\fdform\edit.vue
 * @Copyright: Copyright (c) 2016~2023 by gcz, All Rights Reserved. 
-->
<template>
    <div class=''>
        <form-builder ref="formBuilder" v-model="formEditVal" :value="formEditVal" :buildData="formEditCode" />
        <div style="margin-bottom:15px;text-align:center" v-if="viewType!='view'">
            <el-button type="primary" class="button" @click="editFormData()">提交</el-button>
        </div>
    </div>
</template>

<script>
    import formBuilder from '@/components/formDesigner/formBuilder';
    import { frmSaveAndUpdate,selectById ,frmFindById} from "@/api/customerform/customerformapi";
    export default {
        name: '',
        components: {
            formBuilder,
        },
        data () {
            return {
                viewType:'',
                tableName:'',
                templateId:'',//模版id
                formID:'',
                formEditVal:'',
                formEditCode:''
            };
        },
        created(){
            this.formID = this.$route.query.formID;
            this.templateId = this.$route.query.templateId;
            this.tableName = this.$route.query.formCode;
            this.viewType = this.$route.query.type;
            if(this.templateId){
                this.handleSelectById();
            }
            if(this.formID){
                this.getVal()
            }
            
        },
        methods: {
            handleSelectById(){
                selectById({id:this.templateId}).then(res=>{
                    // console.log('selectById',res);
                    // this.formName = res.data.formName;
                    this.formContent = res.data.formContentJson;
                    this.formContent.formID = this.formID;
                    this.formContent.tableName = this.tableName;
                    this.formEditCode = JSON.stringify(this.formContent)
                    // this.formEditCode = res.data.formContent;
                })
            },
            getVal(){
                frmFindById({tableName:this.tableName,id:this.formID}).then(res=>{
                    this.formEditVal = JSON.stringify(res.data)
                    // console.log('getVal',res.data);
                })
            },
            editFormData(){
                this.$refs['formBuilder'].validate(this.viewType);
            }
        },
    }
</script>

<style lang='scss' scoped>


</style>