<template>
	<view class="page" >
      <u-navbar :is-back="false" title="运营" :border-bottom="false" back-icon-color="000" :background="bgc"
      			title-color='#000' title-size='36' height='40' id="navbar">
      		</u-navbar>
      		<tab-bars :indexs='1' style=""></tab-bars>
      		<image src="https://api.ccttiot.com/smartmeter/img/static/umtXLN0X6kijXgwlI4bg" class="imgbj" mode=""></image>
      		<view class="box">
      			<view class="shouru">
      				<view class="name">
      					收入统计
      				</view>
      				<view class="tongji">
      					<view class="one">
      						<view class="bot">
      							今日收入
      						</view>
      						<view class="top">
      							0
      						</view>
      						<view class="bot">
      							今日订单数
      						</view>
      						<view class="top">
      							0
      						</view>
      					</view>
      					<view class="one">
      						<view class="bot">
      							本周收入
      						</view>
      						<view class="top">
      							0
      						</view>
      						<view class="bot">
      							本周订单数
      						</view>
      						<view class="top">
      							0
      						</view>
      					</view>
      					<view class="one">
      						<view class="bot">
      							本月收入
      						</view>
      						<view class="top">
      							0
      						</view>
      						<view class="bot">
      							本月订单数
      						</view>
      						<view class="top">
      							0
      						</view>
      					</view>
      				</view>
      			</view>
			<view class="gailan">
				<view class="name">
					运营概览
				</view>
				<view class="top">
					<view class="lt">
						经营概况
					</view>
					<view class="rt">
						<view @click="btntab(1)" :class="tabindex == 1 ? 'actives' : ''">
							近30天
						</view>
						<view @click="btntab(2)" :class="tabindex == 2 ? 'actives' : ''">
							近七天
						</view>
					</view>
				</view>
				<view class="zhixian">
					<!-- <l-echart class="line-chart" ref="lineChart2"></l-echart> -->
					<view class="echarts" style="padding: 20rpx;">
							<uni-ec-canvas  class="uni-ec-canvas" id="uni-ec-canvas" ref="canvas" canvas-id="uni-ec-canvas" :ec="ec"></uni-ec-canvas>
					</view>
					<view class="shuom">
						<view class="">
							<image src="https://api.ccttiot.com/smartmeter/img/static/uk2PaAnt4mMTrYhbM7PY" mode="">
							</image>订单营收
						</view>
						<view class="">
							<image src="https://api.ccttiot.com/smartmeter/img/static/ubLD9khOF4jiHmD9O9QA" mode="">
							</image>订单数
						</view>
					</view>
				</view>
				<view class="bijiao">
					<view class="lt" style="border-right: 1px solid #D8D8D8;">
						<view class="price">
							1359
						</view>
						<view class="wz">
							订单营收(元)
						</view>
					</view>
					<view class="lt" style="padding-left: 34rpx;box-sizing: border-box;">
						<view class="price">
							1359
						</view>
						<view class="wz">
							订单数(单)
						</view>
					</view>
				</view>
			</view>
			<view class="shebei">
				<view class="name">
					当前运营情况 <image @click="smflag = !smflag" src="https://api.ccttiot.com/smartmeter/img/static/uvgciot52bbI8bBduvPK" mode=""></image> <text v-if="smflag">使用数/总数</text>
				</view>
				<view class="bd">
					<view class="one">
						<view class="">
							设备总数
						</view>
						<view class="cu">
							<text>1/</text> 10
						</view>
					</view>
					<view class="one">
						<view class="">
							空闲
						</view>
						<view class="cu">
							<text>1/</text>6
						</view>
					</view>
					<view class="one" style="border: none;">
						<view class="">
							租赁中
						</view>
						<view class="cu">
							<text>1/</text>4
						</view>
					</view>
				</view>
			</view>
		</view>
		
         <!-- <tab-bar :indexs='1' style=""></tab-bar> -->
	</view>
</template>

<script>
	// import * as echarts from '@/components/lime-echart/static/echarts.min.js';
	import * as echarts from '@/components/uni-ec-canvas/echarts.js'
	let chart = null
	export default {
		data() {
			return {
				ec: {
					lazyLoad: true
				},
				
				bgc: {
					backgroundColor: "",
				},
				smflag:false
			}
		},
		// 分享到好友（会话）
		  onShareAppMessage: function () {  
		    return {  
		      title: '创想物联',  
		      path: '/pages/shouye/index'  
		    }  
		  },  
		  
		  // 分享到朋友圈  
		  onShareTimeline: function () {  
		    return {  
		      title: '创想物联',  
		      query: '',  
		      path: '/pages/shouye/index'  
		    }  
		  },
		onLoad(option) {

		},
		onShow() {
			this.timelist = []
			setTimeout(() => {
				console.log(this.$refs)
				this.$refs.canvas.init(this.initChart)
			}, 500)
			this.recharge = 0
			const now = new Date();
			this.yeartime = {
			    year: now.getFullYear(),
			    month: now.getMonth() + 1, // 月份从0开始，所以需要+1
			    day: 1 // 设置为月份的第一天
			}
			this.kstime = this.yeartime.year + '-' + (this.yeartime.month < 10 ? '0' + this.yeartime.month : this.yeartime.month) + '-' + (this.yeartime.day < 10 ? '0' + this.yeartime.day : this.yeartime.day)
			this.yeartimes.year = now.getFullYear()
			this.yeartimes.month = now.getMonth() + 1
			this.yeartimes.day = now.getDate()
			this.jstime = this.yeartimes.year + '-' + (this.yeartimes.month < 10 ? '0' + this.yeartimes.month : this.yeartimes.month) + '-' + (this.yeartimes.day < 10 ? '0' + this.yeartimes.day : this.yeartimes.day)
			this.gettime()
		},
		methods: {
			// 点击切换周还是月
			btntab(num) {
				this.tabindex = num
			},
			
			// 点击导航栏回到首页
			btnshouye() {
				uni.reLaunch({
					url: '/pages/shouye/index'
				})
			},


			gettimes() {
				let data = {
					deviceId: this.deviceId,
					year: this.yeartime.year,
					month: this.yeartime.month,
					groupBy: 'create_date'
				}
				this.loging = false
				this.$u.get('/app/device/electric/count', data).then((res) => {
					if (res.code == 200) {
						this.timelist = res.data
						this.chartData = this.timelist.map(item => item.usedElectriQuantity);
						this.chartday = [1,2,3,4,5,6,7,8];
						this.loging = true
					}
				})
			},
			generateWaveData(length) {
				const data = []
				for (let i = 0; i < length; i++) {
					const y = Math.sin((i / (length - 1)) * Math.PI * 2) // 正弦函数生成波浪形状的y值
					data.push((y + 1) * 50) // 映射到0-100的范围
				}
				return data
			},
			initChart(canvas, width, height, canvasDpr) {
				let that = this
				console.log(canvas, width, height, canvasDpr)
				const option = {
					grid: {
						left: 35,
						right: 0,
						top: 10,
						bottom: 20,
					},
					xAxis: {
						type: 'category',
						boundaryGap: false,
						axisLine: {
							show: false,
						},
						axisTick: {
							show: false,
						},
						axisLabel: {
							show: true,
							color: '#808080',
							fontSize: 11,
							rotate: 0,
						},
						splitLine: {
							show: false,
						},
						data: that.chartday,
					},
					yAxis: {
						show: true,
						axisLine: {
							show: false,
						},
						axisTick: {
							show: false,
						},
						axisLabel: {
							show: true,
							color: '#808080',
							fontSize: 11,
							formatter: function(value) {
								// 保留两位小数，没有小数时显示00
								return value
							},
						},
						splitLine: {
							show: false,
						},
					},
					series: [{
						type: 'line',
						smooth: 0.6,
						symbol: 'none',
						lineStyle: {
							color: '#E0DBFF',
							width: 4,
						},
						areaStyle: {
							normal: {
								color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
									offset: 0,
									color: '#ECE8FF'
								}, ]),
							}, 
						},
						data: that.chartData,
					},{
						type: 'line',
						smooth: 0.6,
						symbol: 'none',
						lineStyle: {
							color: '#A9D2FF',
							width: 4,
						},
						areaStyle: {
							normal: {
								color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
									offset: 0,
									color: '#C3E0FF'
								}, ]),
							}, 
						},
						data: that.chartData,
					}],
				}
				chart = echarts.init(canvas, null, {
					width: width,
					height: height,
					devicePixelRatio: canvasDpr
				})
				option.series[0].data = [2000,400,1000,800,5000,2000,6000,8000]
				option.series[1].data = [104,205,350,510,250,630,720,801]
				canvas.setChart(chart)
				chart.setOption(option)
				return chart
			},
		}
	}
</script>

<style lang="scss">
	/deep/ .u-title{
		padding-bottom: 20rpx;
	}
	/deep/ .u-icon__icon{
		padding-bottom: 20rpx;
	}
    .imgbj{
		width: 750rpx;
		height: 100vh;
		position: fixed;
		top: 0;
		left: 0;
		z-index: -1;
	}
	.uni-ec-canvas {
		width: 100%;
		height: 320rpx;
		display: block;
		margin-top: 30rpx;
	}
	.btnxz {
		padding: 0 20rpx;
		box-sizing: border-box;
		font-size: 28rpx;
		font-family: Source Han Sans, Source Han Sans;
		font-weight: 400;
		color: #FFFFFF;
	}

	page {
		background-color: #F7FAFE;
	}
    .actives {
    	background: #fff !important;
    	box-shadow: 0rpx 0rpx 4rpx 0rpx rgba(0, 0, 0, 0.15) !important;
    }
    
    .box {
    	width: 100%;
    	height: 77vh;
    	overflow: scroll;
    }
    .shebei{
    	width: 680rpx;
    	margin: auto;
    	margin-top: 34rpx;
    	.name{
    		font-weight: 600;
    		font-size: 36rpx;
    		color: #3D3D3D;
    		display: flex;
    		align-items: center;
    		text{
    			width: 184rpx;
    			height: 54rpx;
    			background: #E8E8E8;
    			border-radius: 8rpx 8rpx 8rpx 8rpx;
    			line-height: 54rpx;
    			text-align: center;
    			font-size: 26rpx;
    			color: #3D3D3D;
    			margin-left: 20rpx;
    		}
    		image{
    			margin-left: 10rpx;
    			width: 30rpx;
    			height: 30rpx;
    		}
    	}
    	.bd{
    		width: 680rpx;
    		height: 172rpx;
    		background: #FFFFFF;
    		box-shadow: 0rpx 8rpx 40rpx 0rpx rgba(72,137,59,0.1);
    		border-radius: 24rpx 24rpx 24rpx 24rpx;
    		display: flex;
    		justify-content: space-between;
    		align-items: center;
    		text-align: center;
    		margin-top: 20rpx;
    		.one{
    			border-right: 1px solid #C7C7C7;
    			width: 33%;
    			view{
    				font-size: 24rpx;
    				color: #3D3D3D;
    			}
    			.cu{
    				font-weight: 600;
    				font-size: 40rpx;
    				color: #3D3D3D; 
    				margin-top: 8rpx;
    				text{
    					color: #48893B !important;
    				}
    			}
    		}
    	}
    }
    .gailan {
    	width: 680rpx;
    	max-height: 1868rpx;
    	background: #FFFFFF;
    	box-shadow: 0rpx 8rpx 40rpx 0rpx rgba(72, 137, 59, 0.1);
    	border-radius: 24rpx 24rpx 24rpx 24rpx;
    	margin: auto;
    	margin-top: 34rpx;
    	padding: 0 30rpx;
    	padding-top: 38rpx;
    	padding-bottom: 24rpx;
    	box-sizing: border-box;
    
    	.bijiao {
    		width: 636rpx;
    		max-height: 204rpx;
    		background: #DEF1DA;
    		border-radius: 24rpx 24rpx 24rpx 24rpx;
    		display: flex;
    		padding: 24rpx 40rpx;
    		box-sizing: border-box;
    		margin-top: 34rpx;
    
    		.lt {
    			width: 50%;
    
    			.price {
    				font-weight: 600;
    				font-size: 36rpx;
    				color: #3D3D3D;
    			}
    
    			.wz {
    				font-size: 24rpx;
    				color: #3D3D3D;
    				display: flex;
    				align-items: center;
    				margin-top: 10rpx;
    
    				image {
    					width: 32rpx;
    					height: 32rpx;
    					margin-left: 10rpx;
    				}
    			}
    		}
    	}
    
    	.zhixian {
    		.shuom {
    			margin-top: 26rpx;
    			display: flex;
    			align-items: center;
    			padding: 0 76rpx;
    			box-sizing: border-box;
    			justify-content: space-between;
    
    			view {
    				font-size: 24rpx;
    				color: #3D3D3D;
    
    				image {
    					width: 76rpx;
    					height: 18rpx;
    					margin-right: 10rpx;
    				}
    			}
    		}
    	}
    
    	.top {
    		display: flex;
    		justify-content: space-between;
    		height: 66rpx;
    		line-height: 66rpx;
    		align-items: center;
    		margin-top: 24rpx;
    
    		.lt {
    			border-left: 10rpx solid #48893B;
    			font-weight: 600;
    			font-size: 32rpx;
    			color: #3D3D3D;
    			height: 50rpx;
    			line-height: 50rpx;
    			padding-left: 16rpx;
    			box-sizing: border-box;
    		}
    
    		.rt {
    			width: 236rpx;
    			height: 66rpx;
    			background: #F6F6F6;
    			border-radius: 8rpx 8rpx 8rpx 8rpx;
    			display: flex;
    			justify-content: space-between;
    			align-items: center;
    
    			view {
    				width: 116rpx;
    				height: 58rpx;
    				border-radius: 8rpx 8rpx 8rpx 8rpx;
    				text-align: center;
    				line-height: 58rpx;
    			}
    		}
    	}
    
    	.name {
    		font-weight: 600;
    		font-size: 36rpx;
    		color: #3D3D3D;
    		text-align: center;
    		width: 100%;
    	}
    }
    
    .shouru {
    	width: 680rpx;
    	max-height: 838rpx;
    	background: #FFFFFF;
    	box-shadow: 0rpx 8rpx 40rpx 0rpx rgba(72, 137, 59, 0.1);
    	border-radius: 24rpx 24rpx 24rpx 24rpx;
    	margin: auto;
    	margin-top: 24rpx;
    	padding: 26rpx 32rpx;
    	box-sizing: border-box;
    
    	.tongji {
    		display: flex;
    		text-align: center;
    		margin-top: 20rpx;
    		box-sizing: border-box;
    		justify-content: space-between;
            padding:0 50rpx;
    		.one {
    			.top {
    				font-weight: 600;
    				font-size: 36rpx;
    				color: #48893B;
					margin-bottom: 12rpx;
    			}
    
    			.bot {
    				font-size: 28rpx;
    				color: #7C7C7C;
					margin-top: 12rpx;
    			}
    		}
    	}
    
    	.name {
    		font-weight: 600;
    		font-size: 36rpx;
    		color: #3D3D3D;
    	}
    }
    
	.page {
		// padding: 0 59rpx;
		.titles {
			padding-left: 32rpx;
			font-size: 40rpx;
			color: #fff;
			margin-bottom: 30rpx;
			padding-top: 104rpx;
			height: 200rpx;
			background-color: #48893B;
			text {
				padding-left: 33%;
			}
		}
        .name{
			font-size: 36rpx;
			color: #3D3D3D;
			margin-top: 20rpx;
		}
		.gongneng{
			margin-top: 40rpx;
			width: 632rpx;
			height: 150rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 16rpx 40rpx 0rpx rgba(42,130,228,0.1);
			border-radius: 24rpx 24rpx 24rpx 24rpx;
			display: flex;
			justify-content: space-between;
			padding: 26rpx 50rpx;
			box-sizing: border-box;
			image{
				width: 96rpx;
				height: 102rpx;
			}
		}
		.title {
			margin-top: 120rpx;
			font-size: 48rpx;
			font-weight: 400;
			letter-spacing: 0rpx;
            
			color: rgba(38, 43, 55, 1);
		}

		.card {
			padding-top: 32rpx;
			margin-top: 10rpx;
			width: 632rpx;
			height: 540rpx;
			background: #48893B;
			box-shadow: 0rpx 16rpx 40rpx 0rpx rgba(42, 130, 228, 0.1);
			opacity: 1;
			border-radius: 40rpx;

			.month {

				margin-left: 22rpx;
				font-size: 28rpx;
				font-family: Source Han Sans, Source Han Sans;
				font-weight: 400;
				color: #FFFFFF;
			}

			.tit {
				margin-top: 18rpx;
				margin-left: 22rpx;
				font-size: 20rpx;
				font-family: HarmonyOS Sans SC, HarmonyOS Sans SC;
				font-weight: 400;
				color: #FFFFFF;

			}

			.txt {
				margin-top: 2rpx;
				margin-left: 22rpx;
				font-size: 36rpx;
				font-family: HarmonyOS Sans SC, HarmonyOS Sans SC;
				font-weight: 700;
				color: #FFFFFF;
			}

			.echarts {
				margin-left: 22rpx;
				margin-top: 60rpx;
				width: 588rpx;
				height: 320rpx;
			}
		}

		.list {
			margin-top: 16rpx;
            height: 630rpx;
			overflow: auto;
			.card_list {
				width: 632rpx;
				height: 88rpx;
				background: #FFFFFF;
				opacity: 1;
				border-radius: 30rpx;
				display: flex;
				flex-wrap: nowrap;
				justify-content: space-between;
				margin-top: 16rpx;
				align-items: center;

				.left {
					margin-left: 52rpx;
					font-size: 28rpx;
					font-family: HarmonyOS Sans SC, HarmonyOS Sans SC;
					font-weight: 400;
					color: #808080;
				}

				.right {
					margin-right: 20rpx;
					font-size: 28rpx;
					font-family: HarmonyOS Sans SC, HarmonyOS Sans SC;
					font-weight: 400;
					color: #808080;
				}
			}
		}
	}
</style>