wecomp.vue 6.41 KB
<template>
    <div class="wecomp-wrapper">
        <div class="wecomp-chart-wrapper">
            <div class="weekend-chart-wrapper">
                <!-- <span class="ehcarts-title">{{ i18nFormatter(chartTitle) }}</span> -->
                <!-- <wecomp-chart id="wecompChart" class="wecomp-chart-box" :options="weekdayOrEnd_ops" chartType="LineBar"></wecomp-chart> -->
                <mix-charts chartId="wecompChart" class="wecomp-chart-box" :chartData="weekdayOrEnd_ops" chartType='LineBar' />
                <span class="download-text" @click="exportDataHandle('wecompChart',i18nFormatter(chartTitle),'weekdayOrEnd')">{{$t('allPages.load')}}</span>
            </div>
        </div> 
        <export-data-dialog ref="exportDialog"></export-data-dialog>
    </div>
</template>

<script>
import exportData from '../../public/exportData'
import publicChart from '../common/publicChart'
export default {
    props: {
        propparam: Object
    },
    data () {
        return {
            weekdayOrEnd_ops: {},
            tableKeyToId: {},
            tableIds: '',
            emitData: [],
            chartTitle: '',
            startTime:'',
            endTime:'',
        }
    },
    components: {
        'wecomp-chart': publicChart,
        'export-data-dialog': exportData,
	},
    watch: {
        propparam: {
            handler: 'refreshHandle',
            immediate: true
        }
    },
    mounted() {
        // this.getTableId();
    },
    methods: {
        refreshHandle(param) {
            if(param.dateType !== '/weekComp/wecomp') return;
			this.emitData = param.data;
            // this.getMock();
            if(this.tableIds && JSON.stringify(this.tableKeyToId) !== '{}') {
                this.getChartData(this.tableIds);
            } else {
                this.getChartId();
            }
		},
        getMock() {
            // this.weekdayOrEnd_ops = {
            //     title: '周中周末对比',
            //     series: [{
            //         name: '工作日平均客流',
            //         type: 'bar',
            //         data: [600, 230, 800, 364, 160, 440, 600]
            //     }, {
            //         name: '双休日平均客流',
            //         type: 'bar',
            //         data: [200, 230, 800, 364, 160, 440, 600]
            //     }, {
            //         name: '增长率',
            //         type: 'line',
            //         data: [25, 28, 100, 45, 19, 55, 75]
            //     }],
            //     xaxis: {
            //         data: ['1', '2', '3', '4', '5', '6', '7']
            //     }
            // }
        },
		getChartId() {
            this.tableKeyToId = {};
            this.tableIds = '';
			this.$api.baseReport.reportChart({
                report: 'WeekCompared',
                // _t: Date.parse(new Date()) / 1000
            })
            .then(res => {
				let tableItem = res.data.data;
				tableItem.forEach((item, index) => {
                    this.tableKeyToId[item.key] = item.id;
                    if(item.key === 'weekdayOrEnd') {
                        if(index == tableItem.length - 1) {
                            this.tableIds += item.id;
                        } else {
                            this.tableIds += item.id + ',';
                        }
                    }
				});
				this.getChartData(this.tableIds);
			})
		},
		getChartData(tableIds) {
            if(!tableIds) return;
            this.weekdayOrEnd_ops = {};
			if(this.emitData.asis_time) {
                this.startTime = this.emitData.asis_time[0];
                this.endTime = this.emitData.asis_time[1];
            } else {
                // this.startTime = this.dayAdd(new Date(this.emitData.asis_time[0].replace(/\-/g, '/')), 0);
                this.startTime = this.dayReduce(new Date(), 30);
                this.endTime = dateUnit.dateFormat(new Date(), 'yyyy-MM-dd');
            }
            let param = {
                orgIds: this.emitData.asis_org,
                startDate: this.startTime,
                endDate: this.endTime,
                chartIds: tableIds,
                kpiType: this.emitData.asis_kpi,
            }
            let {params,asisLevel} = this.dealFormat(param,this.emitData);
            this.$api.analysisReport.weekComparedAnalysis(asisLevel, params)
            .then(res => {
                let report = 'WeekCompared';
                let { weekdayOrEnd } = res.data.data.body
                weekdayOrEnd['otherConf'] = {
                    _color: ['#3BB8FF', '#87D14B', '#FFC62E'],
                    grid: { top: 68, right: 60, bottom: 66, left: 60 },
                    isCylindrical: true,
                    legendBottom: 16,
                    yAxisName: [this.$t('echarts.traffic'), this.$t('echarts.growthRate')]
                }
                this.weekdayOrEnd_ops = weekdayOrEnd;
                // this.chartTitle = res.data.data.body.weekdayOrEnd.title;
                this.chartTitle = report + 'weekdayOrEnd';
			})
			.catch(err => {
                this.catchErrorHandle(err)
            })
        },
        exportDataHandle(domId, title, chartKey) {
            // 
            let chartId = this.tableKeyToId[chartKey];
            let exportNeed = {
                domId: domId,
                title: title,
                data: {
                    url: '/report/weekCompared/' + this.emitData.asis_level + '/' + chartId + '/excel',
                    params: 'orgIds=' + this.emitData.asis_org + '&startDate=' + this.startTime + '&endDate=' + this.endTime  + '&kpiType=' + this.emitData.asis_kpi
                }
            }
            // console.log('wecomp exportNeed', exportNeed)
            this.$refs.exportDialog.dialogInit(exportNeed);
        },
    }
}
</script>


<style scoped>
    .wecomp-wrapper {
        width: 100%;
    }
    .weekend-chart-wrapper {
        background: #fff;
        position: relative;
    }

    .ehcarts-title {
        z-index: 1;
    }

    .wecomp-chart-box {
        height: 569px;
    }

    @media only screen and (max-width: 1680px) {
        .wecomp-chart-box {
            height: 500px;
        }
    }
    @media only screen and (max-width: 1440px) {
        .wecomp-chart-box {
            height: 400px;
        }
    }

    @media only screen and (max-width: 1366px) {
        .wecomp-chart-box {
            height: 400px;
        }
    }
    @media only screen and (max-width: 1280px) {
        .wecomp-chart-box {
            height: 400px;
        }
    }
</style>