<script setup>
	// 数据中心
	import {
		ref,
		reactive,
	} from 'vue';
	import {
		onLoad,
	} from '@dcloudio/uni-app'
	// 工具库
	import util from '@/common/js/util';
	// api请求体
	import api from '@/api/index'
	// 
	import apex from '@/components/header/apex.vue'

	// 图表数据
	const chartData = ref(null)
	// 图表配置
	const opts = reactive({
		color: ["#C2ECFF", "#FFD2D2", "#C2FFCC", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4", "#ea7ccc"],
		padding: [0, 35, 0, 0],
		touchMoveLimit: 24,
		enableScroll: true,
		legend: {
			padding: 20,
			margin: 30,
			position: 'top',
			backgroundColor: 'rgb(0,0,0)',
			fontColor: '#fff',
			itemGap: 10,
		},
		xAxis: {
			titleFontSize: 16,
			disableGrid: true,
			scrollShow: true,
			itemCount: 10,
			showTitle: true,
			title: '秒数',
		},
		yAxis: {
			data: [{
				min: 0,
				titleFontSize: 16,
				title: '人数',
			}],
			showTitle: true,
		},
		extra: {
			column: {
				type: "group",
				width: 5,
				activeBgColor: "#000000",
				activeBgOpacity: 0.08
			},
		}
	})
	// 推流id
	const pushId = ref('')
	// 推流详情
	const pushDetail = reactive({})

	onLoad((option) => {
		// 推流id
		if (option.pushId) pushId.value = option.pushId
		// 获取推流详情
		getDetail()
	})

	// 获取推流详情
	function getDetail() {
		api.video.getVideoPushDetail({
			query: {
				Id: pushId.value,
			}
		}).then(rs => {
			if (rs.code == 200) {
				Object.assign(pushDetail, rs.data)
				// console.log('chartStatistics',)
				chartData.value = pushDetail.chartStatistics
				return
			}
			util.alert({
				content: rs.msg,
				showCancel: false,
			})
		})
	}

	/**
	 * 跳转
	 * @param {Object} url 路径参数
	 */
	function link(url) {
		uni.navigateTo({
			url,
		})
	}
</script>

<template>
	<view class="app">
		<!-- 顶部 -->
		<view class="apex  ptb30 plr30 bfff">
			<view class="rows">
				<view class="title c333 f36 b">统计中心</view>
			</view>
			<!-- 查看时间 -->
			<view class="line mt20 c999 f26">统计时间：{{pushDetail.statisticalTime}}</view>
		</view>

		<!-- 视频详情 -->
		<view class="video df mtb20 ptb20 plr30 bfff">
			<image class="poster br10" :src="pushDetail.coverUrl" mode="aspectFill"></image>
			<view class="info df fdc jcsb f1 ml30">
				<view class="title t2hd f34 c111">{{pushDetail.title}}</view>
				<view class="desc t2hd f28 c666">{{pushDetail.description}}</view>
				<view class="time f26 c999">{{pushDetail.createTime}}</view>
			</view>
		</view>

		<view class="container" v-if="chartData">
			<view class="rows">
				<view class="title">流量统计</view>
			</view>

			<view class="charts">
				<qiun-data-charts type="column" :opts="opts" :chartData="chartData" :ontouch="true" />
			</view>
		</view>

		<view class="container">
			<view class="title">数据统计</view>

			<view class="dataList">
				<view class="main">
					<view class="item tac">
						<view class="key">推流消耗榴莲果</view>
						<view class="value">{{pushDetail.consumeFruit}}</view>
					</view>
					<!-- 点击订单 显示推广产生的订单列表 -->
					<view class="item tac">
						<view class="key">产生订单数量</view>
						<view class="value">{{pushDetail.numberOfOrders}}</view>
					</view>
					<!-- 增加明细列表 商品详情 订单号 显示分享收益详情 获取了多少积分/余额 -->
					<view class="item tac">
						<view class="key">商家推广返利</view>
						<view class="value">{{pushDetail.rebatePrice}}</view>
					</view>
				</view>
			</view>
		</view>

		<view class="container">
			<view class="main rows" @click="link(util.setUrl('/pages/index/dataCenter/pushDetailUser',{
				pushId: pushId,
			}))">
				<view class="key">推流的用户</view>
				<uni-icons type="right" />
			</view>
		</view>

		<view class="fill" style="height: 30rpx;"></view>
	</view>
</template>

<style lang="scss" scoped>
	// 页面标题
	.apex {
		border-bottom: 2rpx solid #eee;
	}

	// 视频
	.video {

		.poster {
			height: 288rpx;
			width: 162rpx;
		}
	}

	// 锁
	.lock {
		background-color: #FF9B27;

		.lockImg {
			display: none;
		}

		.unlockImg {
			display: block;
		}

		&.active {
			background-color: #ddd;

			.lockImg {
				display: block;
			}

			.unlockImg {
				display: none;
			}
		}
	}

	// 内容
	.container {
		margin: 30rpx;
		padding: 30rpx 20rpx;
		background-color: #fff;
		border-radius: 20rpx;

		// 标题
		.title {
			margin: 0 30rpx;
			font-size: 30rpx;
			font-weight: bold;
		}

		// 图表
		.charts {
			height: 700rpx;
		}

		// 数据列表
		.dataList {
			margin-top: 30rpx;

			.main {
				display: grid;
				grid-template-columns: repeat(2, 1fr);
				grid-gap: 20rpx;
			}

			.item {
				padding: 30rpx 0;
				background-color: #f8f8f8;
				border-radius: 20rpx;

				.value {
					margin-top: 10rpx;
					font-size: 40rpx;
					font-weight: bold;
				}
			}
		}
	}
</style>