<template>
	<view class="app">
		<u-tabs :list="tabList" :current="tabindex" @change="tabchange" active-color='#26A888'
			:show-bar='false'></u-tabs>
		<view class="content">
			<view v-if="tabindex == 0">
				<blood-sugar :current="tabindex" :echartData="list" @taptimeindex='taptimeindex'
					v-on:websocket-message="handleWebSocketMessage"></blood-sugar>
			</view>
			<view v-if="tabindex == 1">
				<blood-pressure :current="tabindex" :echartData="list" @taptimeindex='taptimeindex'
					v-on:websocket-message="handleWebSocketMessage"></blood-pressure>
			</view>
			<view v-if="tabindex == 6">
				<Bloodtemperature :current="tabindex" :echartData="list" @taptimeindex='taptimeindex'
					v-on:websocket-message="handleWebSocketMessage"></Bloodtemperature>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		record
	} from '@/api/pagesC/healthdata/index.js'
	import BloodPressure from '../../components/BloodPressure/BloodPressure.vue'
	import BloodSugar from '../../components/BloodSugar/BloodSugar.vue'
	import Bloodtemperature from '../../components/Bloodtemperature/Bloodtemperature.vue'
	export default {
		components: {
			BloodPressure,
			BloodSugar,
			Bloodtemperature
		},
		data() {
			return {
				tabindex: 0,
				tabList: [{
					name: '血糖',
				}, {
					name: '血压',
				}, {
					name: '血脂',
				}, {
					name: 'BMI',
				}, {
					name: '血氧',
				}, {
					name: '心率',
				}, {
					name: '体温',
				}, ],
				list: null,
				type: 0,
			};
		},
		onLoad(options) {
			this.tabindex = options.index
		},
		onShow() {
			this.info();
		},
		methods: {
			taptimeindex(e) {
				this.type = e
				this.info()
			},
			info() {
				let userinfo = uni.getStorageSync('userinfo');
				var obj = {
					label: Number(this.tabindex) + 1,
					// identity: userinfo.cardNo,
					identity: '370882199909092123',
					type: this.type,
				}
				record(obj).then(res => {
					this.list = res.data
				})
			},
			tabchange(e) {
				this.list = null
				this.tabindex = e
				setTimeout(() => {
					this.info();
				}, 1000)
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F7F5F5;
	}

	::v-deep .u-tabs {
		background-color: #F7F5F5 !important;
	}
</style>