<template>
    <el-radio-group v-model="dataValue" @change='change'
                    :size="size">
        <el-radio v-for="item in radioArr" :key="item.id" :label="item.id">
            {{ item.dataName }}
        </el-radio>
    </el-radio-group>
</template>

<script>
export default {
    name: "plCommonRadio",
    props: {
        value: {required: false, default: ""},
        typeId: {required: true, type: String, default: ""},
        parentId: {required: false, default: "-1"},
        sourceKey: {required: false, default: ""},
        size: {required: false, default: "medium"}
    },
    data() {
        return {
            dataValue: '',
            currentParentId: "",
            radioArr: [],
            radioObj: {},
        }
    },
    watch: {
        value() {
            this.dataValue = this.value;
        }
    },
    created() {
        // console.log('pl-common-radio,created', this.value);
        this.dataValue = this.value;
        this.init();
    },
    methods: {
        change(val) {
            this.$emit("input", val);
        },
        init() {
            this.currentParentId = this.parentId || "";
            this.radioObj = {};
            this.axios.post(this.api.mixDataTool.getDataByType, {
                sourceKey: this.sourceKey || window.currentDataSourceKey,
                typeId: this.typeId,
                parentId: this.currentParentId
            }).then(dataRes => {
                this.radioArr = dataRes.data || [];
                this.radioArr.forEach(item => {
                    this.radioObj[item.id] = item;
                });
            });
        }
    }
}
</script>

<style scoped>

</style>