yoyYearReport.vue 9.88 KB
<template>
	<div>
		<headerComp  :leftImgSrc="leftImg" :title="titleStr" :rightImgSrc="rightImg" @leftClick="backFun" @rightClick="conditionFun"></headerComp>
		<div style="height: 18.11upx;"></div>
		<div v-if="objId=='one'">
			<linebarchart :chart-data="chartDatas.trafficAndYO" bind-id='trafficAndYO'></linebarchart>
			<barchart :chart-data="chartDatas.thisYearTrafficTrend" bind-id='thisYearTrafficTrend'></barchart>
			<linechart :chart-data="chartDatas.thisYearYTrend" bind-id='thisYearYTrend'></linechart>
		</div>
		<div v-else>
			<barchart :chart-data="chartDatas.moreObjectBar" bind-id='moreObjectBar'></barchart>
		</div>
	</div>
</template>

<script>
	import headerComp from '../../../components/header'
	import backArrow from '../../../static/header/backArrow.png'
	import other from '../../../static/header/other.png'
	import tables from '../../../components/table'
	import barchart from '../../../components/barChart'
	import linechart from '../../../components/lineChart'
	import linebarchart from '../../../components/lineBarChart'

	export default{
		data(){
			return{
				titleStr:'同环比分析',
				leftImg:backArrow,
				rightImg:other,
				atoken:'',
				keyArr:[],
				chartIds:'',
				reportType:'mall',
				accountId:[],
				orgIds:'',
				date:'',
				isDay:true,
				isHour:false,
				isMin:false,
				chartDatas:{},
				chartDatas2:{},
				chartDatas3:{},
				chartDatas4:{},
				chartData:{},
				tableData:[],
				columns:[],
				tableData2:[],
				columns2:[],
				tableData3:[],
				columns3:[],
				tableData4:[],
				columns4:[],
				gateId:[],
				floorId:[],
				storeId:[],
				objId:'one'
			}
		},
		onLoad: function (option) {
			if(option.types){
				this.reportType=option.types;
			}
			uni.getStorage({
				key:'objId',
				success:(res)=>{
					this.objId=JSON.parse(res.data)[0];
					console.log(this.objId)
				}
			})
				uni.getStorage({
					key:'atoken',
					success:(res)=>{
						this.atoken=res.data;
					}
				})
				uni.getStorage({
					key:'accountList',
					success:(res)=>{
						if(res.data){
							var list=JSON.parse(res.data);
							list.forEach((item,index)=>{
								if(index==0){
									this.accountId.push(item.id)
								}
							})
						}
					}
				})
				uni.getStorage({
					key:'selectAccountIdArr',
					success:(res)=> {
						this.accountId=JSON.parse(res.data);
					},
					complete: (res) => {
					}
				})
				uni.getStorage({
					key:'selectGateIdArr',
					success:(res)=> {
						this.gateId=JSON.parse(res.data);
					},
					complete: (res) => {
					}
				})
				uni.getStorage({
					key:'selectFloorIdArr',
					success:(res)=> {
						this.floorId=JSON.parse(res.data);
					},
					complete: (res) => {
					}
				})
				uni.getStorage({
					key:'selectStoreIdArr',
					success:(res)=> {
						this.storeId=JSON.parse(res.data);
					},
					complete: (res) => {
					}
				})
				
				const date = new Date();
				var year = date.getFullYear();
				var monthIndex = date.getMonth();
				var month = monthIndex+1 > 9 ? monthIndex+1 : '0' + (monthIndex+1);
				  const d = date.getDate();
				   var day= d > 9 ? d : '0' + d;
				this.date=year+'-'+month+'-'+day;
				uni.getStorage({
					key:'selectDate',
					success:(res)=> {
						this.date=res.data
					},
					complete: (res) => {
					}
				})
				this.getReportKey();
		},
		computed: {
			i18n() {
				return this.$t("index")
			}
		},
		components:{
			headerComp,tables,barchart,linechart,linebarchart
		},
		methods: {
			backFun(){
				uni.reLaunch({
					url:"../index",
				})
			},
			conditionFun(){
				uni.setStorage({
					key:'backUrl',
					data:4
				})
				uni.navigateTo({
					url:'../condition'
				})
			},
			getReportKey(){
					var report='YearYoYMoM';
					if(this.objId=='one'){
						this.keyArr=['trafficAndYO','thisYearTrafficTrend','thisYearYTrend'];
					}else{
						this.keyArr=['moreObjectBar'];
					}
				
				uni.showLoading({
					title: '加载中'
				});
				uni.request({
					url:window.url+'/reportCharts',
					data:{
						report:report,
						_t:Date.parse(new Date())/1000
					},
					header: {
						'app-code':'mobile',
						'Authorization': this.atoken //自定义请求头信息
					},
					method:'GET',
					success:(res) =>{
						this.chartIds='';
						res.data.data.forEach(item=>{
							if(this.keyArr.indexOf(item.key)!='-1'){
								this.chartIds+=item.id+','
							}
						})
						this.chartIds=this.chartIds.substring(0,this.chartIds.length-1);
						this.getChartData();
					}
				})
			},
			setTabelData(){
				if(this.objId=='one'){
					this.columns=[];
					this.tableData=[];
					this.chartDatas.xaxis.data.forEach((item,index)=>{
						 if(index==0){
							 this.columns.push( {field: item, title:item, width: 100, titleAlign: 'center',columnAlign:'center',isResize:true,isFrozen: true})
						 }else{
							 this.columns.push( {field: item, title:item, width: 80, titleAlign: 'center',columnAlign:'center',isResize:true})
						 }
					})
					 this.chartDatas.series.forEach((item,index)=>{
						  var obj={}
						 item.data.forEach((item,index)=>{
							 obj[this.chartDatas.xaxis.data[index]]=item;
						 })
						 this.tableData.push(obj)
					 })
					 this.columns2=[];
					 this.tableData2=[];
					 this.chartDatas2.xaxis.data.forEach((item,index)=>{
					 	 if(index==0){
					 		 this.columns2.push( {field: item, title:item, width: 100, titleAlign: 'center',columnAlign:'center',isResize:true,isFrozen: true})
					 	 }else{
					 		 this.columns2.push( {field: item, title:item, width: 80, titleAlign: 'center',columnAlign:'center',isResize:true})
					 	 }
					 })
					  this.chartDatas2.series.forEach((item,index)=>{
					 	  var obj={}
					 	 item.data.forEach((item,index)=>{
					 		 obj[this.chartDatas2.xaxis.data[index]]=item;
					 	 })
					 	 this.tableData2.push(obj)
					  })
					  this.columns3=[];
					  this.tableData3=[];
					  this.chartDatas3.xaxis.data.forEach((item,index)=>{
					  	 if(index==0){
					  		 this.columns3.push( {field: item, title:item, width: 100, titleAlign: 'center',columnAlign:'center',isResize:true,isFrozen: true})
					  	 }else{
					  		 this.columns3.push( {field: item, title:item, width: 80, titleAlign: 'center',columnAlign:'center',isResize:true})
					  	 }
					  })
					   this.chartDatas3.series.forEach((item,index)=>{
					  	  var obj={}
					  	 item.data.forEach((item,index)=>{
					  		 obj[this.chartDatas3.xaxis.data[index]]=item;
					  	 })
					  	 this.tableData3.push(obj)
					   })
				}else{
					 this.columns4=[];
					this.tableData4=[];
					this.chartDatas4.xaxis.data.forEach((item,index)=>{
						 if(index==0){
							 this.columns4.push( {field: item, title:item, width: 100, titleAlign: 'center',columnAlign:'center',isResize:true,isFrozen: true})
						 }else{
							 this.columns4.push( {field: item, title:item, width: 80, titleAlign: 'center',columnAlign:'center',isResize:true})
						 }
					})
					 this.chartDatas4.series.forEach((item,index)=>{
						  var obj={}
						 item.data.forEach((item,index)=>{
							 obj[this.chartDatas4.xaxis.data[index]]=item;
						 })
						 this.tableData4.push(obj)
					 })
				}
				
				  
			},
			getChartData(){
				this.orgIds=''
					var data={}
					var url=window.url+'/report/yoyOrMom/year/mall';
					var startDate='';
					var endDate='';
						startDate=this.date.split(',')[0];
						endDate=this.date.split(',')[1];
					if(this.reportType=='mall'){
						if(this.objId=='one'){
							this.orgIds=this.accountId[0];
						}else{
							this.accountId.forEach(item=>{
								this.orgIds+=item+','
							})
							this.orgIds=this.orgIds.substring(0,this.orgIds.length-1)
						}
						url=window.url+'/report/yoyOrMom/year/mall';
						data={
							orgIds:this.orgIds,
							startDate:startDate,
							endDate:endDate,
							chartIds:this.chartIds,
							kpiType:'TRAFFIC',
							_t:Date.parse(new Date())/1000
						}
					}else if(this.reportType=='gate'){
						if(this.objId=='one'){
							this.orgIds=this.gateId[0];
						}else{
							this.gateId.forEach(item=>{
								this.orgIds+=item+','
							})
							this.orgIds=this.orgIds.substring(0,this.orgIds.length-1)
						}
						url=window.url+'/report/yoyOrMom/year/gate';
						data={
							orgIds:this.orgIds,
							startDate:startDate,
							endDate:endDate,
							chartIds:this.chartIds,
							kpiType:'TRAFFIC',
							_t:Date.parse(new Date())/1000
						}
					}else if(this.reportType=='floor'){
						this.floorId.forEach(item=>{
							this.orgIds+=item+','
						})
						this.orgIds=this.orgIds.substring(0,this.orgIds.length-1)
						url=window.url+'/report/yoyOrMom/year/floor';
						data={
							orgIds:this.orgIds,
							startDate:startDate,
							endDate:endDate,
							chartIds:this.chartIds,
							kpiType:'TRAFFIC',
							_t:Date.parse(new Date())/1000
						}
					}else if(this.reportType=='area'){
						this.storeId.forEach(item=>{
							this.orgIds+=item+','
						})
						this.orgIds=this.orgIds.substring(0,this.orgIds.length-1)
						url=window.url+'/report/yoyOrMom/year/zone';
						data={
							orgIds:this.orgIds,
							startDate:startDate,
							endDate:endDate,
							chartIds:this.chartIds,
							kpiType:'TRAFFIC',
							_t:Date.parse(new Date())/1000
						}
					}
					uni.request({
						url:url,
						header: {
							'app-code':'mobile',
						'Authorization': this.atoken //自定义请求头信息
						},
						data:data,
						method:'GET',
						success:(res) =>{
							uni.hideLoading()
							var datas=res.data.data;
							this.chartDatas=datas.body;
						}
					})
				
			}
		},
	}
</script>

<style>
	.selectBox{
		width: 646.73upx;
		height: 61.59upx;
		font-size:21.74upx;
		line-height: 61.59upx;
		display: flex;
		flex-direction: row;
		margin: 0 auto;
		margin-bottom: 18.11upx;
	}
	.sItem{
		flex: 1;
		background:#FFFFFF;
		text-align: center;
		cursor: pointer;
		border-right:1px solid #DBDBDB ;
	}
	.sItem:last-of-type{
		border-right:none
	}
	.checkedItem{
		background: #0069FF;
		color: #FFFFFF;
		border: #0069FF;
	}
</style>