<template>
	<view class="content indexCarList">
		<!-- 头部 -->
		<headerIndex :isArea="false"></headerIndex>
		<!-- 卡片数据 -->
		<view class="list">
			<view v-for="(item,index) in user.card_data_list">
				<!-- 标题 -->
				<view class="card box" @click="handlerReport(item)">
					<view class="title border-bottom">
						<view class="name"><text>{{item.card_name}}</text>{{item.record_time}}</view>
						<uni-icons type="right" size="20" v-if="item.inside_data[0].value"></uni-icons>
					</view>
					<!-- 内容 -->
					<view class="item title"
						:style="{'justifyContent':item.inside_data.length>2?'space-between':'center'}">
						<view v-for="(ite,ind) in item.inside_data" :class="[item.inside_data.length>3?'item2':'']">
							<view class="name">{{ite.name}}</view>
							<view class="weight"><text>{{ite.value?ite.value:'-'}}</text>{{ite.unit}}</view>
							<view class="standardBtn" v-if="ite.standard" :style="{'backgroundColor':ite.color}">
								{{ite.standard}}
							</view>
						</view>
					</view>
					<!-- 手动记录 -->
					<view class="target" @click.stop>
						<view class="orangeBtn" v-if="item.acd_id==2"
							@click="$Bluetooth.handleDevicesMac(item.device_determine,item.acd_id)">蓝牙连接</view>
						<view v-else></view>
						<view class="blueBtn" @click="handlerRecord(item.acd_id)">手动记录</view>
					</view>
				</view>
				<!-- 小标签 -->
				<!-- <view class=" card box small" v-if="ite.size=='small'">
							<view class="title border-bottom">
								<view class="name"><text>{{ite.name}}</text>{{ite.time}}</view>
								<icon class="iconfont icon-arrow-right-bold size20"></icon>
							</view>
							<view class="item title">
								<view>
									<text>本次数据</text>
									<view class="weight"><text>{{ite.cnt?ite.cnt:'-'}}</text>{{ite.unit}}</view>
									<view class="standardBtn" :style="{'backgroundColor':ite.standardcolor}"
										v-if="ite.standardtext">
										{{ite.standardtext}}
									</view>
								</view>
							</view>
							<view class="target">
								<view class="left">
									<icon class="iconfont icon-notification"></icon>
									教程
								</view>
								<view class="targetBtn">手动记录</view>
							</view>
						</view> -->
			</view>
		</view>
		<!-- 设置数据卡片 -->
		<view class="setcard" @click="handleCard">
			设置数据页卡片
		</view>
		<!-- 手动 -->
		<record :rtype="rtype"></record>
	</view>
</template>

<script>
	import {
		mapState
	} from "vuex";
	import headerIndex from "@/components/headerIndex.vue"
	import record from '@/components/manuallyAdd/record.vue';
	export default {
		data() {
			return {
				rtype: 0,
				transition: 1.6
			}
		},
		components: {
			record,
			headerIndex
		},
		computed: {
			...mapState(["user", "familayList"]),
		},
		onLoad(options) {
			let that = this
			if (options && options.type == 1) {
				that.handleUserList()
			}
		},
		onShow() {
			let that = this
			that.$Bluetooth.stopBluetoothDevicesDiscovery()
			uni.hideLoading()
		},
		methods: {
			// 
			handlelenver(value) {
				let that = this
				let number = 0
				let length = that.list.length
				number = value / (that.list[0].max_val - that.list[length - 1].min_val) * 100
				return number.toFixed(0)
			},
			// 成员列表
			handleUserList() {
				let that = this
				that.$model.getUserList({
					type: 2
				}).then(res => {
					console.log("用户列表", res, uni.getStorageSync('userid'))
					if (res.code != 0) {
						that.$tools.msg(res.msg)
						return
					}
					that.$store.commit('changeFamilay', res.data)
					if (res.data.length) {
						that.$store.dispatch('getUserInfo', {
							aud_id: uni.getStorageSync('userid') ? uni.getStorageSync('userid') : res.data[
								0].id
						})
						that.$store.dispatch("getCardList", {
							aud_id: uni.getStorageSync('userid') ? uni.getStorageSync('userid') : res.data[
								0].id
						})
					}
				}).catch(err => {})
			},

			// 设置数据页卡片
			handleCard() {
				uni.navigateTo({
					url: "/pages/card/card"
				})
			},
			// 报告页
			handlerReport(item) {
				console.log("item", item)
				uni.navigateTo({
					url: item.page_url_report + "?acd_id=" + item.acd_id + '&device=' + item.device_determine
				})
			},
			// 手动添加
			handlerRecord(id) {
				this.rtype = id
				this.$store.commit('changeRecord', true)
			},
			navTo(url) {
				console.log("url", url)
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		min-height: 100vh;
		padding-bottom: 15px;
		background-color: #f7f7f7;
	}
</style>