<template>
	<view class="content indexCarList">
		<!-- 头部 -->
		<headerIndex></headerIndex>
		<!-- 卡片数据 -->
		<view class="list">
			<view v-for="(item,index) in user.card_data_list">
				<!-- 标题 -->
				<view class="card box">
					<view class="title border-bottom" @click="handlerReport(item)">
						<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="left">
							<!-- <icon class="iconfont icon-notification"></icon>
							{{ite.name}}教程 -->
						</view>
						<view class="targetBtn" @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
			}
		},
		components: {
			record,
			headerIndex
		},
		computed: {
			...mapState(["user"]),
		},
		onLoad() {
			let that = this
			let systemInfo = uni.getSystemInfoSync();
			this.isAndroid = systemInfo.platform.toLowerCase() === 'android';
			uni.onLocaleChange((e) => {
				if (this.isAndroid) {
					uni.showModal({
						content: this.$t('index.language-change-confirm'),
						success: (res) => {
							if (res.confirm) {
								uni.setLocale(e.code);
							}
						}
					})
				} else {
					uni.setLocale(e.code);
					this.$i18n.locale = e.code;
				}
			})
			that.handleUserList()
		},
		methods: {
			// 成员列表
			handleUserList() {
				let that = this
				that.$model.getUserList({
					type: 2
				}).then(res => {
					console.log("用户列表", res)
					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) {
				uni.navigateTo({
					url: "/pages/" + item.card_key + '/' + item.card_key + "?acd_id=" + item.acd_id
				})
			},
			// 手动添加
			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>