<template>
    <ImgageDownloadPreviewBase
            :btnStyle="btnStyle"
            :imageStyle="imageStyle"
            :myData="BASEDATA"
            :typeCode="typeCode"
            @download="handleDownload"
    />
</template>

<script>
    /**
     * @summary 缩略图 业务对接组件
     * @author wxy
     * @date 2020/3/27
     */
    import ImgageDownloadPreviewBase from './ImgageDownloadPreviewBase';

    export default {
        name:       'ImageDownloadPreview',
        components: {
            [ImgageDownloadPreviewBase.name]: ImgageDownloadPreviewBase,
        },
        props:      {
            // 业务识别 code
            typeCode:   {
                type:     String,
                required: true,
            },
            // 图片地址数据
            imgUrl:     {
                type:     String,
                required: true,
            },
            // 按钮样式修正
            btnStyle:   {
                type:    Object,
                default: () => ({}),
            },
            // 缩略图样式修正
            imageStyle: {
                type:    Object,
                default: () => ({}),
            },
        },
        data() {
            return {
                // 业务数据转化
                BASEDATA: {
                    smallImgUrl: '',
                    imgUrlList:  [],
                    btnIsShow:   true,
                },
            };
        },
        methods:    {

            /**
             * @summary 业务鉴别函数
             * @des     根据typeCode 进行业务区分掉用不同初始化函数 修正数据
             * @author  wxy
             * @date    2020/3/27
             */
            checkTypeCode() {
                //
                switch (this.typeCode) {
                    case 'rengongpingjuan':
                        this.handleChengjiDataProcessing();
                        break;
                    default:
                        throw new Error('ImgageDownloadPreview：未找到业务识别码：typeCode字段映射');
                }
            },
            /**
             * @summary 人工pingjuan 业务数据转换
             * @author  wxy
             * @date    2020/3/27
             */
            handleChengjiDataProcessing() {
                // 初始化业务数据
                this.BASEDATA = {
                    smallImgUrl: '',
                    imgUrlList:  [],
                    btnIsShow:   true,
                };

                // 组件业务数据整理
                this.BASEDATA.btnIsShow = true;
                this.BASEDATA.smallImgUrl = this.imgUrl;
                this.BASEDATA.imgUrlList.push(this.imgUrl);


            },
            /**
             * @summary 反向提供业务触发功能 至 页面
             * @param data
             */
            handleDownload(data) {
                this.$emit('download', data);
            },
        },
        watch:      {
            imgUrl: {
                handler(a, b) {
                    // 传入数据变更 业务校验开始
                    this.checkTypeCode();
                },
                immediate: true,
            },
        },
    };
</script>

<style scoped>

</style>
