<template>
    <component :is="componentCode"
               :propParams="propParams"
               :callfillParamArr="callfillParamArr"
               @updateEmitParam="updateEmitParam"
               ref="registerCompRef">
    </component>
</template>

<script>
    export default {
        name: "plDiyCustomComp",
        props:{
            optFormData:{type:Object,default:() => {return {}}},
            componentCode:{type:String,default:''},
            callfillParamArr:{type:Array,default:() => {return [];}},
        },
        data () {
            return {
                propParams: {}, //传递的参数对象
                propParamsArr: [] // 自定义组件标识
            }
        },
        watch: {
            optFormData: {
                handler: function() {
                    this.analysisParam();
                },
                deep:true
            }
        },
        created() {
            this.analysisParam();
        },
        methods:{
            // 解析参数, 传参
            analysisParam() {
                let callfillParamArr = this.callfillParamArr || [];
                this.propParamsArr = callfillParamArr;
                callfillParamArr.forEach(item => {
                    let paramKey = item["paramKey"];
                    let paramId = item["paramValue"];
                    this.$set(this.propParams, paramKey, this.optFormData[paramId]);
                })
            },

            // 修改表单字段
            updateEmitParam(param) {
                (Object.keys(param) || []).forEach(item => {
                    (this.propParamsArr || []).forEach(data => {
                        if(data["paramValue"] === item) {
                            let paramId = data["paramValue"];
                            this.optFormData[paramId] = param[item];
                        }
                    })
                })
            }
        }
    }
</script>

<style scoped>

</style>
