<template>
	<!-- 血糖趋势 -->
	<view class="box" :style="boxstyle">
		<view class="box-title">
			<view class="box-title-left">血糖趋势</view>
		</view>
		<view class="ytitle" v-show="!loading && !isEmpty">单位：mmol/L</view>
		<view class="echartbox">
			<qiun-data-charts v-show="!isEmpty" type="area" :opts="opts" :chartData="chartData"
				tooltipFormat="bsTooltip" />
			<myEmpty v-show="isEmpty" style="padding: 40rpx 0 0 0;"></myEmpty>
		</view>
	</view>
</template>

<script>
	import myEmpty from "@/pages_watch/components/myEmpty/myEmpty.vue";
	export default {
		name: "bsChart",
		props: {
			loading: {
				type: Boolean,
				default: false
			},
			boxstyle: {
				type: Object,
				default: () => {}
			}
		},
		components: {
			myEmpty
		},
		data() {
			return {
				isEmpty: true,
				chartData: {},
				opts: {
					color: ["#FF7700"],
					padding: [20, 0, 15, 0],
					enableScroll: false,
					dataLabel: false,
					dataPointShapeType: "hollow",
					legend: {
						show: false,
					},
					xAxis: {
						disableGrid: true,
						fontSize: 12,
						axisLine: false,
						fontColor: '#ccc',
						// 横坐标最多展示几个
						labelCount: 7,
						// 自定义横坐标展示（在/u-charts/config-ucharts中有配置）
						format: "formatterTime",
					},
					yAxis: {
						gridType: "dash",
						dashLength: 2,
						// splitNumber: 6,
						data: [{
							fontColor: '#ccc',
							min: 0,
							// max: 33,
							axisLine: false,
							fontSize: 12,
						}]
					},
					extra: {
						tooltip: {
							gridType: "dash",
							showArrow: false,
							legendShow: true,
							legendShape: "circle"
						},
						area: {
							type: "straight",
							opacity: 0.2,
							addLine: true,
							width: 2,
							gradient: true,
							activeType: "solid"
						}
					}
				}
			}
		},
		methods: {
			setChartData(data) {
				if (data && data.length > 0) {
					this.isEmpty = false
					let chartData = {
						categories: data.map(item => item.createTime),
						series: [{
							name: "血糖",
							data: data.map(item => item.bloodGlucose)
						}]
					}
					this.chartData = JSON.parse(JSON.stringify(chartData));
				} else {
					this.isEmpty = true
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	@mixin u-flex($flexD, $alignI, $justifyC) {
		display: flex;
		flex-direction: $flexD;
		align-items: $alignI;
		justify-content: $justifyC;
	}

	.box-title {
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #757575;
		@include u-flex(row, center, space-between);

		&-left {
			font-weight: 500;
			font-size: 36rpx;
			color: #222222;
			line-height: 42rpx;
		}

		&-right {
			@include u-flex(row, center, flex-start);

			image {
				height: 48rpx;
				width: 48rpx;
			}
		}
	}

	.box {
		padding: 24rpx;
		margin-bottom: 20rpx;
		box-sizing: border-box;
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
	}

	.ytitle {
		margin-top: 10rpx;
		line-height: 34rpx;
		margin-bottom: 24rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #999999;
	}

	.echartbox {
		height: 466rpx;
		width: 100%;
	}
</style>