<template>
  <div>
    <form-designer ref="formDesigner" v-model="fdForm" @releaseJson="releaseJson"></form-designer>
  </div>

</template>
<script>
import { saveAndEdit,selectById } from "@/api/customerform/customerformapi";
export default {
  components: {  },
  name: "fdForm",
  data() {
    return {
      formID:'',
      fdForm: '',
      formName:'',
      formContent:{},
    };
  },
  created() {
    // console.log('query',this.$route.query);
    this.formID = this.$route.query.formID;
    if(this.formID){
      this.handleSelectById();
    }
  },
  methods: {
    handleSelectById(){
      selectById({id:this.formID}).then(res=>{
        // console.log('selectById',res);
        // this.formName = res.data.formName;
        this.formContent = JSON.parse(res.data.formContent);
        // console.log('this.formContent',this.formContent);
        let temp = {};
        temp.list = this.formContent.list;
        temp.config = this.formContent.config;
        temp.formName = res.data.formName;

        this.fdForm = JSON.stringify(temp)
      })
    },
    releaseJson(form, json){
      saveAndEdit({formName:form.name, formContent:JSON.parse(json)}).then(response => {
        this.$message({
          message: '模板添加成功',
          type: 'success'
        });
        }
      );
    }
  }
};
</script>
