yearly.vue 11.6 KB
<template>
	<div class="yearly">
		<el-row class="chartRow" :gutter="12">
			<el-col :span="24" class="download-parent">
				<!-- 近15天对比 -->
				<div class="date-radio-wrapper tf-ratio-group">
                    <el-radio-group v-model="radioDate" size="mini" fill="#0069FF" @change="changeTabSelect(radioDate)">
                        <el-radio-button label="dayTrend" border>{{$t('asisTab.day')}}</el-radio-button>
                        <el-radio-button label="monthTrend" border>{{$t('asisTab.month')}}</el-radio-button>
                    </el-radio-group>
                </div>
				<comprehen-chart id="ynearfifChart" class="nearfif-wrapper" :options="dayTrend_ops" chartType="YearLine"></comprehen-chart>
                <span class="ehcarts-title">{{ i18nFormatter(Trend_title) }}</span>
				<span class="download-text" @click="exportDataHandle('ynearfifChart',i18nFormatter(Trend_title),radioDate)">{{$t('allPages.load')}}</span>
			</el-col>
		</el-row>
		<el-row class="chartRow" :gutter="12">
			<el-col :span="12" class="download-parent">
				<!-- 顾客性别对比 -->
				<!-- <div class="gender-wrapper"></div> -->
				<comprehen-chart id="ygenderChart" class="gender-wrapper" :options="customerfeatureGender_ops" chartType="GenderBar"></comprehen-chart>
                <span class="ehcarts-title">{{ i18nFormatter(customerfeature_gender_title) }}</span>
				<span class="download-text" @click="exportDataHandle('ygenderChart',i18nFormatter(customerfeature_gender_title),'customerfeature_gender')">{{$t('allPages.load')}}</span>
			</el-col>
			<el-col :span="12" class="download-parent">
				<!-- 顾客年龄对比 -->
				<!-- <div class="age-wrapper"></div> -->
				<comprehen-chart id="yageChart" class="age-wrapper" :options="customerfeatureAge_ops" chartType="AgeBar"></comprehen-chart>
                <span class="ehcarts-title">{{ i18nFormatter(customerfeature_age_title) }}</span>
				<span class="download-text" @click="exportDataHandle('yageChart',i18nFormatter(customerfeature_age_title),'customerfeature_age')">{{$t('allPages.load')}}</span>
			</el-col>
		</el-row>
		<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 {
			customerfeatureGender_ops: {},	// 顾客性别对比
			customerfeatureAge_ops: {},	// 顾客年龄对比
			dayTrend_ops: {},	// 近15天趋势对比
			tableKeyToId: {},
			tableIds: '',
			radioDate:'日',
			emitData: [],
			_startTime:'',
			_endTime:'',
            _apiUrl:'',
            Trend_title: '',
			customerfeature_gender_title: '',
			customerfeature_age_title: '',
		}
	},
	components: {
		'comprehen-chart': publicChart,
		'export-data-dialog': exportData,
	},
	watch: {
        propparam: {
            handler: 'refreshHandle',
            immediate: true
        }
    },
    mounted() {
        // this.getTableId();
    },
	methods: {
		refreshHandle(param) {
			if(param.dateType !== '/comprehen/yearly') return;
			this.emitData = param.data;
			if(this.tableIds && JSON.stringify(this.tableKeyToId) !== '{}') {
				this.getChartData(this.tableIds);
			} else {
				this.getChartId();
			}
		},
		getChartId() {
			this.tableKeyToId = {};
			this.tableIds = '';
			this.$api.baseReport.reportChart({
                report: 'SynthesizeCompare',
                // _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 === 'customerfeature_gender' || item.key === 'customerfeature_age' || item.key === 'dayTrend' || item.key === 'monthTrend') {
                        if(index == tableItem.length - 1) {
							this.tableIds += item.id;
                        } else {
							this.tableIds += item.id + ',';
                        }
                    }
				});
				this.getChartData(this.tableIds);
			})
		},
		getChartData(tableIds) {
			if(!tableIds) return;
			this.customerfeatureGender_ops = {};
			this.customerfeatureAge_ops = {};
			this.dayTrend_ops = {};
			let apiUrl = '', param = {}, startTime = '', endTime = '';
			if(this.emitData.asis_time) {
                if(this.emitData.asis_time.getFullYear() === new Date().getFullYear()) {
                    endTime = dateUnit.dateFormat(this.emitData.asis_time, 'yyyy-MM-dd');
                    startTime = dateUnit.dateFormat(new Date(Date.parse(this.emitData.asis_time.getFullYear() + '/01/01')), 'yyyy-MM-dd');
					if(startTime == endTime) {
                        endTime = dateUnit.dateFormat(new Date(), 'yyyy-MM-dd');
                    }
				} else {
                    const fullyear = this.emitData.asis_time.getFullYear()
                    const fullDays = (fullyear % 4 == 0 && fullyear % 100 != 0) || (fullyear % 100 == 0 && fullyear % 400 == 0) ? 366 : 365;
                    startTime = this.emitData.asis_time;
                    endTime = new Date(Date.parse(this.dayAdd(this.emitData.asis_time, fullDays).replace(/\-/, '/')));
					let formatTime = this.unitTime(startTime, endTime, 'year');
					startTime = formatTime.startTime;
					endTime = formatTime.endTime;
                }
            } else {
				endTime = dateUnit.dateFormat(new Date(), 'yyyy-MM-dd');
				startTime = dateUnit.dateFormat(new Date(Date.parse(new Date().getFullYear() + '/01/01')), 'yyyy-MM-dd');
			}
			this._startTime = startTime;
			this._endTime = endTime;
            if(this.emitData.asis_level === 'format') {
                // apiUrl = '/report/synthesize/mall';
                this.emitData.asis_level = 'mall';
                param = {
                    orgIds: this.emitData.asis_org,
                    startDate: startTime,
                    endDate: endTime,
                    chartIds: tableIds,
                    kpiType: this.emitData.asis_kpi,
                    formatIds: this.emitData.asis_format,
                    // _t: Date.parse(new Date()) / 1000
                }
            } else {
                // apiUrl = '/report/synthesize/' + this.emitData.asis_level;
                param = {
                    orgIds: this.emitData.asis_org,
                    startDate: startTime,
                    endDate: endTime,
                    chartIds: tableIds,
                    kpiType: this.emitData.asis_kpi,
                    // _t: Date.parse(new Date()) / 1000
                }
			}
			this._apiUrl = '/report/synthesize/' + this.emitData.asis_level;
            this.$api.analysisReport.synthesizeAnalysis(this.emitData.asis_level, param)
            .then(res => {
                let report = 'SynthesizeCompare';
				let gender_ops = {}, age_ops = {};
				gender_ops = res.data.data.body.customerfeature_gender;
				gender_ops['color'] = ['#3BB8FF', '#FFC62E'];
                this.customerfeatureGender_ops = gender_ops;
                // this.customerfeature_gender_title = gender_ops.title;
                this.customerfeature_gender_title = report + 'customerfeature_gender';
				age_ops = res.data.data.body.customerfeature_age;
				age_ops['color'] = ['#6e6fc1', '#33bafe', '#fec62b', '#ff9c01', '#38d4be', '#79ce4c'];
                this.customerfeatureAge_ops = age_ops;
                // this.customerfeature_age_title = age_ops.title;
                this.customerfeature_age_title = report + 'customerfeature_age';
                this.dayTrend_ops = res.data.data.body.dayTrend;
                // this.Trend_title = res.data.data.body.dayTrend.title;
                this.Trend_title = report + 'dayTrend';
			})
			.catch(err => {
                this.catchErrorHandle(err)
            })
		},
		changeTabSelect(val){
			// switch (val) {
            //     case '日':
            //         val = 'dayTrend'
            //         break;
            //     case '月':
            //         val = 'monthTrend'
            //         break;
            //     default:
            //         break;
			// }
			let apiUrl = '', param = {}, startTime = '', endTime = '';
			let tabId = this.tableKeyToId[val]
			if(this.emitData.asis_time) {
                if(this.emitData.asis_time.getFullYear() === new Date().getFullYear()) {
                    endTime = dateUnit.dateFormat(this.emitData.asis_time, 'yyyy-MM-dd');
                    startTime = dateUnit.dateFormat(new Date(Date.parse(this.emitData.asis_time.getFullYear() + '/01/01')), 'yyyy-MM-dd');
					if(startTime == endTime) {
                        endTime = dateUnit.dateFormat(new Date(), 'yyyy-MM-dd');
                    }
				} else {
                    startTime = this.emitData.asis_time;
                    const fullyear = this.emitData.asis_time.getFullYear()
                    const fullDays = (fullyear % 4 == 0 && fullyear % 100 != 0) || (fullyear % 100 == 0 && fullyear % 400 == 0) ? 366 : 365;
                    endTime = new Date(Date.parse(this.dayAdd(this.emitData.asis_time, fullDays).replace(/\-/, '/')));
                    // if((startTime instanceof Object) && (endTime instanceof Object)) {
					let formatTime = this.unitTime(startTime, endTime, 'year');
					startTime = formatTime.startTime;
					endTime = formatTime.endTime;
                    // }
                }
            } else {
				endTime = dateUnit.dateFormat(new Date(), 'yyyy-MM-dd');
				startTime = dateUnit.dateFormat(new Date(Date.parse(new Date().getFullYear() + '/01/01')), 'yyyy-MM-dd');
			}
			this._startTime = startTime;
			this._endTime = endTime;
            if(this.emitData.asis_level === 'format') {
				// apiUrl = '/report/synthesize/mall/' + tabId;
                this.emitData.asis_level = 'mall';
                param = {
                    orgIds: this.emitData.asis_org,
                    startDate: startTime,
                    endDate: endTime,
                    chartIds: this.tableIds,
                    kpiType: this.emitData.asis_kpi,
                    formatIds: this.emitData.asis_format,
                    // _t: Date.parse(new Date()) / 1000
                }
            } else {
				//apiUrl = '/report/synthesize/' + this.emitData.asis_level;
				// apiUrl = '/report/synthesize/' + this.emitData.asis_level + '/' + tabId;
                param = {
                    orgIds: this.emitData.asis_org,
                    startDate: startTime,
                    endDate: endTime,
                    chartIds: this.tableIds,
                    kpiType: this.emitData.asis_kpi,
                    // _t: Date.parse(new Date()) / 1000
                }
			}
			this._apiUrl = '/report/synthesize/' + this.emitData.asis_level + '/' + tabId;
            this.$api.analysisReport.synthesizeAnalysis(`${this.emitData.asis_level}/${tabId}`, param)
			 .then(res => {
				this.dayTrend_ops = res.data.data
             })
             .catch(err => {
                 this.catchErrorHandle(err)
             })
		},
        exportDataHandle(domId, title, chartKey) {
            // 
            let chartId = this.tableKeyToId[chartKey];
            let exportNeed = {
                domId: domId,
                title: title,
                data: {
                    url: window._vionConfig.apiUrl + '/report/synthesize/' + 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('comprehen year exportNeed', exportNeed)
            this.$refs.exportDialog.dialogInit(exportNeed);
        },
	}
}
</script>

<style scoped>
	.tf-ratio-group {
		left: 255px;
	}
</style>