<template>
	<view class="cardContent">
		<view class="cardList">
			<view class="caritem" @click="handleNavTol('/pageTwo/charts/charts')">
				<image src="/static/q5.png"></image>
				<view>{{$t('titleCharts')}}</view>
			</view>
			<view class="caritem" @click="handleNavTol('/pageTwo/compk/contrast')">
				<image src="/static/q3.png"></image>
				<view>{{$t('titleContrast')}}</view>
			</view>
			<view class="caritem" @click="handlerRecord">
				<image src="/static/q7.png"></image>
				<view>{{$t('addRecord')}}</view>
			</view>
			<view class="caritem" @click="handleNavTol('/pageTwo/history/history')">
				<image src="/static/q8.png"></image>
				<view>{{$t('HistoricalRcord')}}</view>
			</view>
		</view>

		<view class="cardListchosen">
			<view class="item" v-for="(ite,ind) in cardList.chosen_fixed" @click="handleNavTol(ite.page_jump)">
				<view class="info">
					<image :src="ite.icon"></image>
					<text>{{ite.name}}</text>
				</view>
			</view>
			<view class="item" v-for="(ite,ind) in cardList.chosen_yes" @click="handleNavItem(ite)">
				<view class="info">
					<image :src="ite.icon"></image>
					<text>{{ite.name}}</text>
				</view>
			</view>
		</view>
		<!-- 通用卡片新增数据 -->
		<view class="wrapper" v-if="isPublicCard">
			<view class="bg" @click="onTap">
				<view class="edit" @click.stop>
					<view class="title">{{name}}</view>
					<!-- 项目内容 -->
					<view class="editem">
						<view class="left">{{$t('TimeSpent')}}</view>
						<view class="right">
							<input type="number" v-model="number" :placeholder="$t('verifyRecord')">
							<text style="width: 60px;">{{$t('minutes')}}</text>
						</view>
					</view>
					<view class="btn close" @click="onTap()">{{$t('btnSancellation')}}</view>
					<view class="btn" @click="handlepublicmeasure">{{$t('btnConfirm')}}</view>
				</view>
			</view>
		</view>
		<record></record>
	</view>
</template>

<script>
	import {
		mapState
	} from "vuex";
	import record from '@/components/cardIndex/record.vue';
	export default {
		data() {
			return {
				name: "",
				isPublicCard: false,
				number: "",
				key_word: ""
			}
		},
		components: {
			record,
		},
		computed: {
			...mapState(['user', "CardList"]),
			endDate() {
				return this.$tools.getDate("start")
			},
			startDate() {
				return this.$tools.GetDateStr(-90);
			},
			cardList() {
				return this.CardList
			}
		},
		onLoad() {
			let that = this
			uni.setNavigationBarTitle({
				title: this.$t('titleExercise'),
			})
		},
		methods: {
			// 手动
			handlerRecord() {
				this.$store.commit('changeTsPublicRecord', true)
			},
			handleNavItem(ite) {
				if (ite.page_jump) {
					uni.navigateTo({
						url: ite.page_jump
					})
				} else {
					this.name = ite.name
					this.key_word = ite.id
					this.isPublicCard = true
				}
			},
			handleNavTol(url) {
				uni.navigateTo({
					url: url
				})
			},
			handlepublicmeasure() {
				let that = this
				if (!that.number) {
					that.$tools.msg(that.$t('verifyTime'))
					return
				}
				that.$model.getpublicmeasurecard({
					aud_id: that.user.aud_id,
					card_id: that.key_word,
					time_m: that.number
				}).then(res => {
					if (res.code != 0) return
					that.$tools.msg(res.msg)
					that.number = ""
					that.key_word = ""
					that.isPublicCard = false
				})
			},
			onTap() {
				let that = this
				that.name = ""
				that.number = ""
				that.key_word = ""
				that.isPublicCard = false
			},
			handleSetCard() {
				uni.navigateTo({
					url: "/pageTwo/cardList/card"
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.cardContent {
		min-height: 100vh;
		background: #F7F7F7;
		padding: 5px 0 15PX;
	}

	.cardList {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		background: #fff;
		margin: 10px 15px;
		padding: 10px;
		border-radius: 10px;

		.caritem {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;

			image {
				width: 40px;
				height: 40px;
			}
		}
	}

	.cardListchosen {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		margin: 15px;

		.item {
			width: 48%;
			background-color: #fff;
			margin-bottom: 15px;
			position: relative;
			height: 60px;
			line-height: 60px;
			border-radius: 5px;

			.info {
				width: calc(100% - 20px);
				padding: 0 10px;
				display: flex;
				align-items: center;

				image {
					width: 30px;
					height: 30px;
					background-color: #f2f2f2;
					border-radius: 50%;
					float: left;
					margin-right: 10px;
				}

				text {
					width: calc(100% - 35px);
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}
			}
		}
	}

	.btn {
		width: 40%;
		float: right;
		margin-top: 15px;
		background: $maincolor !important;
	}

	.close {
		background: #dfdfdf !important;
		float: left;
	}

	.setCard {
		color: $maincolor;
		margin: 15px;
		text-align: center;
		border: 1px solid $maincolor;
		border-radius: 10px;
		height: 40px;
		line-height: 40px;
		background: #fff;
	}
</style>