<template>
    <div :class="curClassName" :style="curStyle">
        <img v-if="imgUrl" :src="imgUrl" />
        <i v-else :class="imageClass ? imageClass : ''"></i>
    </div>
</template>
<script lang = 'ts'>
import { Vue, Component, Prop } from 'vue-property-decorator';
@Component({})
export default class AppRawItemImage extends Vue {
    /**
     * 名称
     *
     * @type {*}
     * @memberof AppRawItemImage
     */
    @Prop() public name!: string;

    /**
     * 模型
     *
     * @type {*}
     * @memberof AppRawItemImage
     */
    @Prop() public layoutModelDetails!: any;

    /**
     * 图片地址
     *
     * @type {string}
     * @memberof AppRawItemImage
     */
    @Prop() public imgUrl?: string;

    /**
     * 图标
     *
     * @type {string}
     * @memberof AppRawItemImage
     */
    @Prop() public imageClass?: string;

    /**
     * 下标
     *
     * @type {number}
     * @memberof AppRawItemImage
     */
    @Prop() public index?: number;

    /**
     * 项名称
     *
     * @type {*}
     * @memberof AppRawItemImage
     */
    get itemName() {
        return (this.index || this.index === 0) ? `${this.name}_${this.index}` : this.name;
    }

    /**
     * 类名
     *
     * @memberof AppRawItemImage
     */
    get curClassName() {
        const layoutModel = this.layoutModelDetails[this.itemName];
        if (layoutModel) {
            return `app-rawitem-image ${this.itemName} ${layoutModel.sysCss}`;
        }
    }

    /**
     * 当前容器样式
     * 
     * @memberof AppRawItemImage
     */
    get curStyle() {
        const layoutModel = this.layoutModelDetails[this.itemName];
        if (layoutModel) {
            return layoutModel.getElementStyle();
        }
    }

}
</script>
<style lang = "less">
@import './app-rawitem-image.less';
</style>