<template>
    <div class="row  go-form-row">
        <go-label :required="false" :labelWidth="labelWidth" :labelAlign="labelAlign" :label="label" :item="inputItem"
        ></go-label>
        <div :class="'go-content padding-l-bs ' + getInputWid()" :style="getInputWidStyle()">
            <div class="go-content-body">
                <div class="go-common-list-content" :style="contentStyle">{{ showValue }}</div>
            </div>
        </div>
    </div>
</template>

<script>
    import formMixin from '../../mixins/formMixins';
    import GoLabel from './commponents/go-label';
    import {AssertUtils} from "goingutils";
    import EditorTypeUtils from "../../common/editorTypeUtils";

    export default {
        name: 'go-common-list',
        mixins: [formMixin],
        data() {
            return {
                showValue: this.value,
            };
        },
        props: {
            noBottom:{
                type:Boolean,
                default:false,
            },
            value: {},
            item: {
                type: Object,
                default: () => {
                    return {};
                }
            }
        },
        computed: {
            //内容区域的样式信息
            contentStyle () {
                if(this.noBottom){
                    return {borderBottom:"0px"};
                }else{
                    return {};
                }
            }
        },
        methods: {
            initShowValue(newVal) {
                let editorType = EditorTypeUtils.getEditorType(this.inputItem);
                //根据编辑类型获取对象
                let object = EditorTypeUtils.getObj(editorType);
                //如果是用户定义的类型 根据类型获取选择的值
                if (AssertUtils.isNotNull(object)) {
                    this.showValue = object.getShowValue(newVal, this.inputItem);
                } else {
                    this.showValue = AssertUtils.isNotEmpty(newVal) ? newVal : '';
                }
            }
        },
        mounted() {
            //如果传入了值  需要根据类型进行翻译
            if(AssertUtils.isNotEmpty(this.value)){
                this.initShowValue(this.value);
            }
        },
        watch: {
            value(newVal) {
                this.initShowValue(newVal);
            }
        },
        components: {
            GoLabel
        }
    };
</script>
