<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 == 2">
				<BloodFat :current="tabindex" :echartData="list" @taptimeindex='taptimeindex'
					v-on:websocket-message="handleWebSocketMessage"></BloodFat>
			</view>
			<view v-if="tabindex == 3">
				<BMI :current="tabindex" :echartData="list" @taptimeindex='taptimeindex'
					v-on:websocket-message="handleWebSocketMessage"></BMI>
			</view>
			<view v-if="tabindex == 4">
				<Blood-oxygen :current="tabindex" :echartData="list" @taptimeindex='taptimeindex'
					v-on:websocket-message="handleWebSocketMessage"></Blood-oxygen>
			</view>
			<view v-if="tabindex == 5">
				<Heart-rate :current="tabindex" :echartData="list" @taptimeindex='taptimeindex'
					v-on:websocket-message="handleWebSocketMessage"></Heart-rate>
			</view>
			<view v-if="tabindex == 6">
				<Temperature :current="tabindex" :echartData="list" @taptimeindex='taptimeindex'
					v-on:websocket-message="handleWebSocketMessage"></Temperature>
			</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 Temperature from '../../components/Temperature/Temperature.vue'
	import BloodFat from '../../components/BloodFat/BloodFat.vue'
	import BMI from '../../components/BMI/BMI.vue'
	import BloodOxygen from '../../components/BloodOxygen/BloodOxygen.vue'
	import HeartRate from '../../components/HeartRate/HeartRate.vue'
	export default {
		components: {
			BloodPressure,
			BloodSugar,
			Temperature,
			BloodFat,
			BMI,
			BloodOxygen,
			HeartRate
		},
		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>