timeFlowReport.vue 7.25 KB
<template>
	<div>
		<headerComp  :leftImgSrc="leftImg" :title="titleStr" :rightImgSrc="rightImg" @leftClick="backFun" @rightClick="conditionFun"></headerComp>
		<div style="height: 18.11upx;"></div>
		<timechart :chart-data="chartDatas.TimeThermodynamic" bind-id='TimeThermodynamic'></timechart>
	</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 timechart from '../../../components/timeChart'
	export default{
		data(){
			return{
				titleStr:'时段客流分布',
				leftImg:backArrow,
				rightImg:other,
				atoken:'',
				keyArr:[],
				chartIds:'',
				reportType:'mall',
				accountId:[],
				orgIds:'',
				date:'',
				isDay:true,
				isHour:false,
				isMin:false,
				chartDatas:{},
				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) => {
					}
				})
				var currentWeek=[]
				uni.getStorage({
					key:'currentWeek',
					success:(res)=> {
						currentWeek=JSON.parse(res.data);
					},
					complete: (res) => {
					}
				})
				var a1=0,a2=0,a3=0;
				if(currentWeek[0].index){
					a1=currentWeek[0].index;
					a2=currentWeek[1].index;
					a3=currentWeek[2].index;
				}else{
					a1=currentWeek[0];
					a2=currentWeek[1];
					a3=currentWeek[2];
				}
				var year =1999+a1;
				var month=a2+1;
				month=month>9?month:'0'+month;
				var d = new Date();
				// 该月第一天
				d.setFullYear(year, month-1, 1);
				var w1 = d.getDay();
				// 该月天数
				d.setFullYear(year, month, 0);
				var dd = d.getDate();
				// 第一个周一
				let week1;
				//当月第一周有几天
				week1=7 - w1+1;
				var from='',to='';
				if(a3==0){
					from=year+"-"+month+"-01";
					var toDay=week1>9?week1:'0'+week1;
					to=year+'-'+month+'-'+toDay
				}else{
					var fromDay=week1+7*(a3-1)+1;
					var toDay=week1+7*a3;
					if(fromDay>dd){
						for(var i=(a3-1);i>=0;i--){
							fromDay=week1+7*(i-1);
							toDay=week1+7*i;
							if(fromDay<=dd){
								if(toDay>dd){
									toDay=dd;
								}
								break;
							}
						}
					}else if(fromDay<=dd&&toDay>dd){
						toDay=dd;
					}
					fromDay=fromDay>9?fromDay:'0'+fromDay;
					toDay=toDay>9?toDay:'0'+toDay;
					from=year+"-"+month+"-"+fromDay;
					to=year+"-"+month+"-"+toDay;
				}
				this.date=from+','+to;
				uni.getStorage({
					key:'selectDate',
					success:(res)=> {
						if(res.data.indexOf(',')!=-1){
							this.date=res.data;
						}else{
							console.log(this.date)
							uni.setStorage({
								key:'selectDate',
								data:this.date
							})
						}
					},
					complete: (res) => {
					}
				})
				this.getReportKey();
		},
		computed: {
			i18n() {
				return this.$t("index")
			}
		},
		components:{
			headerComp,tables,timechart
		},
		methods: {
			backFun(){
				uni.reLaunch({
					url:"../index",
				})
			},
			conditionFun(){
				uni.setStorage({
					key:'backUrl',
					data:5
				})
				uni.navigateTo({
					url:'../condition'
				})
			},
			getReportKey(){
				var report='TimeThermodynamic';
				this.keyArr=['TimeThermodynamic'];
				
				uni.showLoading({
					title: '加载中'
				});
				uni.request({
					url:window.url+'/reportCharts',
					data:{
						report:report,
						_t:Date.parse(new Date())/1000
					},
					header: {
						'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();
					}
				})
			},
			getChartData(){
				this.orgIds=''
					var data={}
					var url=window.url+'/report/thermodynamic/mall';
					var startDate='';
					var endDate='';
					startDate=this.date.split(',')[0];
					endDate=this.date.split(',')[1];
					if(this.reportType=='mall'){
						this.orgIds=this.accountId[0];
						url=window.url+'/report/thermodynamic/mall';
						data={
							orgIds:this.orgIds,
							startDate:startDate,
							endDate:endDate,
							chartIds:this.chartIds,
							_t:Date.parse(new Date())/1000
						}
					}else if(this.reportType=='gate'){
							this.orgIds=this.gateId[0];
						url=window.url+'/report/thermodynamic/gate';
						data={
							orgIds:this.orgIds,
							startDate:startDate,
							endDate:endDate,
							chartIds:this.chartIds,
							_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/thermodynamic/floor';
						data={
							orgIds:this.orgIds,
							startDate:startDate,
							endDate:endDate,
							chartIds:this.chartIds,
							_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/thermodynamic/zone';
						data={
							orgIds:this.orgIds,
							startDate:startDate,
							endDate:endDate,
							chartIds:this.chartIds,
							_t:Date.parse(new Date())/1000
						}
					}
					uni.request({
						url:url,
						header: {
							'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>