<template>
	<view class="content ">
		<view class="tabbar">
			<scroll-view class="scroll-menu" scroll-x="true" style="white-space: nowrap;">
				<view v-for="(item,index) in labelList" :class="[active==index?'active':'']"
					@click="handleActive(item,index)">
					<text>{{item}}</text>
				</view>
			</scroll-view>
		</view>
		<!--  -->
		<view class="desc">
			<view class="statuevue">
				<view class="bi">
					<view class="peobox" :style="'left:'+Number(offset)+'%'">
						<view class="xx"></view>
					</view>
					<view class="item" v-for="(ite,ind) in lineList" :key="ind" :style="{backgroundColor:ite.color}">
						<view class="span1">{{ite.text}}</view>
						<view class="span" v-if="ind<lineList.length-1">{{ite.max_val}}</view>
					</view>
				</view>
			</view>
		</view>
		<!--  -->
		<view v-for="(ite,ind) in label_data" v-if="active == ind">
			<view class="info">
				<view class="left">
					<view class="left_view">
						<view class="title">{{ite.this_time_title}}:</view>
						<view class="val">
							<text class="yello"></text>
							{{ite.this_time_value?ite.this_time_value:'-'}}
						</view>
					</view>
					<view class="left_view">
						<view class="title">{{ite.today_time_title}}:</view>
						<view class="val">
							<text class="yello"></text>
							{{ite.today_time_value?ite.today_time_value:'-'}}
						</view>
					</view>
					<view class="left_view">
						<view class="title"></view>
						<view class="val">
							<text class="blues yello"></text>
							{{ite.today_times?ite.today_times:'-'}}
						</view>
					</view>
					<view class="left_view">
						<view class="title">{{ite.all_time_title}}:</view>
						<view class="val">
							<text class="yello"></text>
							{{ite.all_time_value?ite.all_time_value:'-'}}
						</view>
					</view>
					<view class="left_view">
						<view class="title"></view>
						<view class="val">
							<text class="blues yello"></text>
							{{ite.all_times?ite.all_times:'-'}}
						</view>
					</view>
				</view>
				<view class="right">
					<view class="title bold">训练成绩为</view>
					<view class="charts">
						<qiun-data-charts type="arcbar" :chartData="chartData" />
						<view class="name">{{ite.score?ite.score:'-'}}</view>
					</view>
					<view class="standard" v-if="ite.standard">
						<text :style="{backgroundColor:ite.color}">{{ite.standard}}</text>
					</view>
					<view v-if="ite.max_score" class="size12 c999"> 总成绩为{{ite.max_score}}分</view>
				</view>
			</view>
			<!-- 说明 -->
			<view class="info describe" v-if="ite.describe">
				{{ite.describe}}
			</view>
		</view>
		<!--  -->
		<view class="gridList">
			<view class="data">
				<view class="item" @click="navTo('/pages/PublicCards/charts?acd_id='+acd_id)">
					<view class="image">
						<image src="@/static/charts.png"></image>
					</view>
					<view class="name">运动曲线</view>
				</view>
				<view class="item" @click="navTo('/pages/PublicCards/history?acd_id='+acd_id)">
					<view class="image">
						<image src="@/static/add.png"></image>
					</view>
					<view class="name">历史记录</view>
				</view>
				<view class="item" @click="navTo('/pages/PublicCards/contrast?acd_id='+acd_id)">
					<view class="image">
						<image src="@/static/pk.png"></image>
					</view>
					<view class="name">数据对比</view>
				</view>
				<view class="item" @click="$store.commit('changeRecord',true)">
					<view class="image">
						<image src="@/static/history.png"></image>
					</view>
					<view class="name">添加记录</view>
				</view>
			</view>
		</view>
		<!-- 手动记录 -->
		<record :rtype='acd_id'></record>
	</view>
</template>

<script>
	import {
		mapState
	} from "vuex";
	import record from '@/element/manuallyAdd/record.vue';
	import qiunDataCharts from '@/uni_modules/qiun-data-charts/components/qiun-data-charts/qiun-data-charts.vue';
	export default {
		data() {
			return {
				active: 0,
				acd_id: null,
				lineList: [],
				label_data: [],
				offset: 0,
				labelName: "",
				chartData: {
					series: [{
						name: "正确率",
						color: "#4687F9",
						data: 0.8
					}]
				},
			}
		},
		components: {
			record,
			qiunDataCharts
		},
		computed: {
			...mapState(["PublicContent"]),
			labelList() {
				let that = this
				if (that.PublicContent) {
					that.labelName = that.PublicContent.label_list[0]
					that.lineList = that.PublicContent.line_list
					that.label_data = that.PublicContent.label_data
					that.offset = that.PublicContent.label_data[0].offset
				}
				return that.PublicContent ? that.PublicContent.label_list : []
			},
		},
		onLoad(options) {
			let that = this
			that.acd_id = options.acd_id
			that.$store.dispatch("getPublicContent", {
				acd_id: that.acd_id,
				aud_id: uni.getStorageSync('userid')
			})
		},
		methods: {
			handleActive(ite, ind) {
				let that = this
				that.active = ind
				that.labelName = ite
				that.offset = that.label_data[ind].offset
			},
			// 历史数据删除时重新加载接口
			reload() {
				let that = this
				console.log('返回历史页', that.acd_id)
				this.$nextTick(() => {
					that.$store.dispatch("getPublicContent", {
						acd_id: that.acd_id,
						aud_id: uni.getStorageSync('userid')
					})
				})
			},
			navTo(url) {
				uni.navigateTo({
					url: url
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.content {
		width: calc(100% - 30px);
		min-height: calc(100vh - 80px);
		padding: 65px 15px 15px;
		background-color: #f7f7f7;
	}

	.tabbar {
		display: flex;
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		z-index: 999;
		justify-content: space-between;
		border-bottom: 1px solid #f7f7f7;
		box-shadow: 0px 1px 5px 2px #dfe2e1fc;
		background-color: #fff;

		.scroll-menu {
			width: 100%;
			white-space: nowrap;

			view {
				height: 55px;
				line-height: 55px;
				display: inline-block;
				min-width: 100px;
				margin: 0 10px;
				text-align: center;
			}
		}

		.active {
			color: $maincolor;
			font-weight: bold;
			border-bottom: 2px solid $maincolor;
		}
	}

	.desc {
		padding: 15px;
		text-align: left;
		width: calc(100%-20px);
		height: auto;
		border-radius: 5px;
		font-size: 30rpx;
		color: #999;
		margin-top: 15px;
		background: #fff;


		.statuevue {
			height: 35px;
			position: relative;
			width: 100% !important;
			margin: 20px auto 10px;

			.bi {
				display: flex;
				justify-content: space-between;
				width: auto;
				padding-top: 10px;

				.peobox {
					position: absolute;
					right: 0;
					top: -1px;

					.xx {
						width: 5px;
						height: 5px;
						border-radius: 50%;
						background: #fff;
						position: absolute;
						z-index: 9;
						border: 2px solid #1b2086;
						top: 9px;
					}
				}
			}

			.item {
				position: relative;
				margin: 0;
				flex: 1;
				height: 5px;
				color: #666;
				font-size: 30rpx;

				.span1 {
					width: 100%;
					text-align: center;
					position: absolute;
					top: -23px;
				}

				.span {
					margin-top: 8px;
					position: absolute;
					right: -8px;
				}
			}
		}
	}

	.describe {
		color: #666;
		font-size: 28rpx;
		line-height: 25px;
	}

	.info {
		background-color: #fff;
		padding: 15px;
		margin-top: 15px;
		border-radius: 5px;
		display: flex;
		justify-content: space-between;

		.left {
			width: calc(100% - 280rpx);
			display: flex;
			flex-wrap: wrap;

			.left_view {
				width: 100%;
				display: flex;
				align-items: center;
			}

			.title {
				width: 80px;
				font-weight: bold;
				margin-right: 10px;
			}
		}

		.right {
			width: 260rpx;
			display: flex;
			flex-wrap: wrap;
			align-items: center;
			justify-content: center;

			.charts {
				width: 260upx;
				height: 260upx;
				margin: 10px 0;
				position: relative;
				display: flex;
				align-items: center;
				justify-content: center;

				.name {
					width: 100%;
					text-align: center;
					font-size: 56rpx;
					color: #4687F9;
					position: absolute;
				}
			}

			.title {
				width: 100%;
				text-align: center;
			}
		}
	}

	.standard {
		width: 100%;
		text-align: center;
		margin-top: -3px;
		margin-bottom: 8px;

		text {
			width: 100px;
			color: #fff;
			font-size: 14px;
			padding: 2px 10px;
			border-radius: 5px;
		}
	}

	.yello {
		width: 8px;
		height: 8px;
		border-radius: 50%;
		display: inline-block;
		margin-right: 5px;
		background-color: $btncolor;
	}

	.blues {
		background-color: $maincolor;
	}

	.gridList {
		margin: 0;
	}
</style>