<template>
    <div class="edb-detail-wrap" v-show="edbData.DataList">
        <chartInfo
            :edbData="edbData"
            :lang="lang"
            @refreshData="refreshData"
            ref="chartInfo"
        />
        <div class="author" style="float:right">添加人：{{edbData.EdbInfo.SysUserRealName}}</div>
    </div>
</template>

<script>
import * as preDictEdbInterface from '@/api/modules/predictEdbApi.js';
import { dataBaseInterface } from '@/api/api.js';
import chartInfo from './chartInfo.vue'
export default {
    props:{
        id: Number,
        lang: String
    },
    components:{chartInfo},
    watch:{
        id:{
            handler(n){
                if(n){
                    this.$nextTick(()=>{
                        this.getDetail()
                    })
                }
            },
            immediate:true
        },
        lang(newval){
            this.$emit('updateTit',{
                edb_name: this.edbData.EdbInfo.EdbName,
                edb_nameEn: this.edbData.EdbInfo.EdbNameEn,
                userid: this.edbData.EdbInfo.SysUserId
            })
        }
    },
    data() {
        return {
            edbData:{
                DataList:null,
                EdbInfo:{}
            },
        }
    },
    methods: {
        getDetail(type=''){
            preDictEdbInterface.edbChartInfo({
				EdbInfoId: this.id,
                DateType: this.$refs.chartInfo.year_select,
				StartDate: this.$refs.chartInfo.select_date[0]||'',
				EndDate: this.$refs.chartInfo.select_date[1]||'',
                ChartType:this.$refs.chartInfo.chartInfo.ChartType,
                SeasonStartDate:this.$refs.chartInfo.season_year[0]||'',
                SeasonEndDate:this.$refs.chartInfo.season_year[1]||'',
                Calendar:this.$refs.chartInfo.calendar_type
			}).then(res=>{
                if(res.Ret!=200) return
                this.edbData.DataList=res.Data.DataList
                this.edbData.EdbInfo={
                    ...res.Data.EdbInfo,
                    ChartColor:'',
                    ChartStyle:'',
                    ChartType:0,
                    ChartWidth:0,
                    MaxData:type==='saveLimit' ? this.$refs.chartInfo.tableData[0].MaxData : res.Data.EdbInfo.MaxValue,
                    MinData:type==='saveLimit' ? this.$refs.chartInfo.tableData[0].MinData : res.Data.EdbInfo.MinValue,
                    EdbInfoCategoryType:1,
                    EdbInfoType:1,
                    EdbName:res.Data.EdbInfo.EdbName,
                    IsAxis:1
                }
                this.$emit('updateTit',{
                    edb_name: res.Data.EdbInfo.EdbName,
                    edb_nameEn: res.Data.EdbInfo.EdbNameEn,
                    userid: res.Data.EdbInfo.SysUserId
                })
                this.$emit('setOpera',res.Data.Button)
                //更新图片
                if(type==='updateImg' || !res.Data.EdbInfo.ChartImage) {
                    console.log(type);
                    console.log(res.Data.EdbInfo.ChartImage);
                    this.$nextTick(() => {
                        this.setChartImage()
                    })
                }
            })
        },
        refreshData(type=''){
            this.getDetail(type)
        },
        changeEnOptions() {
            this.$emit('openEnNameDia',this.edbData.EdbInfo)
        },

        /* 关联图片 */
        setChartImage() {
            let svg = this.$refs.chartInfo.$refs.chartRef.chart.getSVG({
                chart:{
                width: 340,
                height: 230,
                }
            });
            let form = new FormData();
            form.append('Img', svg);
            this.setImageHandle(form);
        },

        async setImageHandle(form) {
            let { Data } = await dataBaseInterface.uploadImgSvg(form);
            await preDictEdbInterface.setImg({
                EdbInfoId: this.id,
                ImageUrl: Data.ResourceUrl,
            });
        },

    },

}
</script>

<style>

</style>