holidayReport.vue 8.01 KB
<template>
	<div>
		<headerComp  :leftImgSrc="leftImg" :title="titleStr" :rightImgSrc="rightImg" @leftClick="backFun" @rightClick="conditionFun"></headerComp>
		<div style="height: 18.11upx;"></div>
		<v-table v-if="columns2.length>0"
			 is-horizontal-resize
		        style="width:100%;margin-bottom: 16.3upx;"
		        :columns="columns2"
		        :table-data="tableData2"
		        row-hover-color="#eee"
		        row-click-color="#edf7ff"
		        :height='600'
		></v-table>
		<circlebar :chart-data="chartData.HolidayEffect" bind-id='HolidayEffect'></circlebar>
		<v-table v-if="columns.length>0"
			 is-horizontal-resize
		        style="width:100%"
		        :columns="columns"
		        :table-data="tableData"
		        row-hover-color="#eee"
		        row-click-color="#edf7ff"
		        :height='600'
		></v-table>
	</div>
</template>

<script>
	import headerComp from '../../../components/header'
	import backArrow from '../../../static/header/backArrow.png'
	import other from '../../../static/header/other.png'
	import circlebar from '../../../components/circleBarChart'
	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:{},
				chartData:{},
				tableData:[],
				tableData2:[],
				columns:[],
				columns2:[],
				gateId:[],
				floorId:[],
				storeId:[]
			}
		},
		onLoad: function (option) {
			if(option.types){
				this.reportType=option.types;
			}
				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) => {
					}
				})
				
				var currentYear=[]
				uni.getStorage({
					key:'currentYear',
					success:(res)=> {
						currentYear=JSON.parse(res.data);
					},
					complete: (res) => {
					}
				})
				var a1=0;
				if(currentYear[0].index){
					a1=currentYear[0].index;
				}else{
					a1=currentYear[0];
				}
				var from='',to='';
				var year =new Date().getFullYear()-15+a1;
				from=year+'-01-01';
				to=year+'-12-31';
				this.date=from+','+to;
				uni.getStorage({
					key:'selectDate',
					success:(res)=> {
						if(res.data.indexOf(',')!=-1){
							this.date=res.data;
						}else{
							uni.setStorage({
								key:'selectDate',
								data:this.date
							})
						}
					},
					complete: (res) => {
					}
				})
				this.getReportKey();
		},
		computed: {
			i18n() {
				return this.$t("index")
			}
		},
		components:{
			headerComp,circlebar
		},
		methods: {
			backFun(){
				uni.reLaunch({
					url:"../index",
				})
			},
			conditionFun(){
				uni.setStorage({
					key:'backUrl',
					data:6
				})
				uni.navigateTo({
					url:'../condition'
				})
			},
			getReportKey(){
					var report='holidayeEvent';
					this.keyArr=['HolidayEvent','HolidayDetail','HolidayEffect'];
				
				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(){
				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)
				  })
			},
			getChartData(){
				this.orgIds=''
					var data={}
					var url=window.url+'/report/holidayeEvent/mall';
					if(this.reportType=='mall'){
						this.orgIds=this.accountId[0]
						url=window.url+'/report/holidayeEvent/mall';
						data={
							orgIds:this.orgIds,
							startDate:this.date.split(',')[0],
							endDate:this.date.split(',')[1],
							chartIds:this.chartIds,
							kpiType:'TRAFFIC',
							_t:Date.parse(new Date())/1000
						}
					}else if(this.reportType=='gate'){
						this.orgIds=this.gateId[0]
						url=window.url+'/report/holidayeEvent/gate';
						data={
							orgIds:this.orgIds,
							startDate:this.date.split(',')[0],
							endDate:this.date.split(',')[1],
							chartIds:this.chartIds,
							kpiType:'TRAFFIC',
							_t:Date.parse(new Date())/1000
						}
					}else if(this.reportType=='floor'){
						this.orgIds=this.floorId[0]
						url=window.url+'/report/holidayeEvent/floor';
						data={
							orgIds:this.orgIds,
							startDate:this.date.split(',')[0],
							endDate:this.date.split(',')[1],
							chartIds:this.chartIds,
							kpiType:'TRAFFIC',
							_t:Date.parse(new Date())/1000
						}
					}else if(this.reportType=='area'){
						this.orgIds=this.storeId[0]
						url=window.url+'/report/holidayeEvent/zone';
						data={
							orgIds:this.orgIds,
							startDate:this.date.split(',')[0],
							endDate:this.date.split(',')[1],
							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.chartData=datas.body;
							this.chartDatas=datas.body.HolidayDetail;
							this.chartDatas2=datas.body.HolidayEvent
							this.setTabelData()
						}
					})
				
			}
		},
	}
</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>