<template>
	<view class="content">
		<view class="top">
			<view class="avater">
				<image :src="userInfo.avatar" class="avater-img" mode=""></image>
			</view>
			<view class="name-box">
				<view class="name-top">
					{{userInfo.nickname}}
				</view>
			</view>
		</view>
		<view class="nav-box">
			<view class="nav-item" @click="tohelp">
				<view class="tt-icon1">
					<image src="../../static/icon/icon-05.png" class="img1" mode=""></image>
				</view>
				<view class="tt-txt">
					求救记录
				</view>
				<image src="../../static/icon/next.png" class="next-icon" mode=""></image>
			</view>
			<view class="nav-item" @click="torreco">
				<view class="tt-icon1">
					<image src="../../static/icon/icon-06.png" class="img1" mode=""></image>
				</view>
				<view class="tt-txt">
					救援记录
				</view>
				<image src="../../static/icon/next.png" class="next-icon" mode=""></image>
			</view>
			<view class="nav-item" @click="commonaddress">
				<view class="tt-icon1">
					<image src="../../static/icon/icon-07.png" class="img1" mode=""></image>
				</view>
				<view class="tt-txt">
					常用地址
				</view>
				<image src="../../static/icon/next.png" class="next-icon" mode=""></image>
			</view>
			<view class="nav-item" @click="tocertificates">
				<view class="tt-icon1">
					<image src="../../static/icon/icon-08.png" class="img1" mode=""></image>
				</view>
				<view class="tt-txt">
					我的证书
				</view>
				<image src="../../static/icon/next.png" class="next-icon" mode=""></image>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import {
		saveUrl,
		interceptor
	} from '@/utils/loginUtils.js';
	import { detail_training } from '@/api/train.js';
	import {
		userinfo
	} from '@/api/user.js';
	// #ifdef H5
	import {
		weixindata
	} from '@/utils/wxAuthorized';
	// #endif
	export default {
		data() {
			return {
				common_address:'',
				name:'',
				signDate:'',
				id:0,
				is_over:0
			}
		},
		onShow() {
			console.log(this);
			//	判断是否已经登录
			if (this.hasLogin) {
				this.loadBaseData();
			} else {
				saveUrl();
				uni.showModal({
					title: '登录',
					content: '您未登录，是否马上登陆?',
					success: e => {
						if (e.confirm) {
							interceptor();
						}
					},
					fail: e => {
						console.log(e);
					}
				});
			}
			this.type = this.userInfo.type;
			this.common_address = this.userInfo.common_address
			console.log('点前保存的地址',this.common_address)
			// 保存当前页面
		},
		onReady() {
			console.log(99999)
			detail_training({
				id:this.id,
			}).then(({data}) => {
				console.log(999,data)
				this.name = data.name
				this.signDate = data.add_time
				this.is_over = data.is_over
			})
		},
		computed: {
			...mapState('user', ['hasLogin', 'userInfo'])
		},
		methods: {
			...mapMutations('user', ['setUserInfo']),
			loadBaseData() {
				userinfo({}).then(({
					data
				}) => {
					this.setUserInfo(data);
				});
				// #ifdef H5
				weixindata();
				// #endif
				detail_training({
					id:this.id,
				}).then(({data}) => {
					console.log(9,data)
					this.name = data.name
					this.signDate = data.add_time
					this.is_over = data.is_over
				})
			},
		
			torreco() {
				uni.navigateTo({
					url: '/pages/applic/rescuerecords'
				})
			},
			tohelp() {
				uni.navigateTo({
					url: '/pages/applic/helprecords'
				})
			},
			commonaddress() {
				uni.navigateTo({
					url: '/pages/applic/commonaddress?add=' + this.common_address
				})
			},
			tocertificates() {
				uni.navigateTo({
					// pages/form/certificatesList
					// url: '/pages/form/certificates?name=' + this.name + '&signDate=' + this.signDate
					url: '/pages/form/certificatesList' 
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
		background-color: #fff;
	}
	.content {
		line-height: 1;
		background-color: #fff;
		.top {
			width: 750rpx;
			height: 399rpx;
			// background-color: #CB131B;
			background: url(../../static/images/bgi2.png)no-repeat top left;
			// background-image: url();
			background-size: 750rpx 399rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			padding-left: 55rpx;
			align-items: center;
			justify-content: center;
			.avater {
				width: 150rpx;
				height: 150rpx;
				margin-right: 28rpx;

				.avater-img {
					width: 100%;
					height: 100%;
					border-radius: 50%;
					background-color: #fff;
				}
			}

			.name-box {
				// flex: 1;
				padding-top: 25rpx;
				.name-top {
					font-size: 42rpx;
					font-weight: 400;
					color: #FFFFFF;
					margin-bottom: 15rpx;
				}
				.name-bottom{
					margin-top: 16rpx;
					display: flex;
					align-items: center;
					// justify-content: center;
					
					.nameInfo{
						color: #FFFFFF;
						padding: 6rpx 16rpx;
						border: 1rpx solid #FFFFFF;
						border-radius: 12rpx;
						// background-color: pink;
					}
				}

				.name-footbox {
					.name-foot {
						text-align: center;
						font-size: 22rpx;
						font-weight: 400;
						color: #FFFFFF;
						background: rgba(255, 255, 255, 0.2);
						border: 1px solid #FFFFFF;
						border-radius: 20rpx;
						padding: 3rpx 13rpx;
					}
				}

			}
		}

		.center-box {
			width: 687rpx;
			// height: 235px;
			background: #FFE8E8;
			border-radius: 16rpx;
			margin: -90rpx auto 0;

			.center-top {
				width: 687rpx;
				height: 80rpx;
				background: #FFFFFF;
				border-radius: 16rpx 16rpx 0 0;
				display: flex;
				align-items: center;
				padding-left: 30rpx;

				.top-left {
					width: 126rpx;
					line-height: 32rpx;
					text-align: center;
					background: linear-gradient(0deg, #C90F1B, #F14D33);
					font-size: 22rpx;
					font-weight: 400;
					color: #FFFFFF;
					border-radius: 20rpx;
					margin-right: 10rpx;
				}

				.top-right {
					font-size: 22rpx;
					font-weight: 400;
					color: #CB151D;
				}
			}

			.center-foot {
				height: 155rpx;
				display: flex;

				.foot-list {
					flex: 1;
					text-align: center;
					padding-top: 20rpx;

					.list-top {
						font-size: 39rpx;
						font-weight: 400;
						color: #CB141D;
						line-height: 58rpx;
					}

					.list-foot {
						font-size: 39rpx;
						font-weight: 400;
						color: #666666;
						line-height: 58rpx;
					}
				}
			}
		}
	}
	.nav-box {
		width: 670rpx;
		height: 360rpx;
		background: #FFFFFF;
		box-shadow: 0px 0px 16rpx 0px rgba(0, 0, 0, 0.04);
		border-radius: 20rpx;
		margin: 0 auto;
		padding-top: 40rpx;
		.nav-item {
			height: 40rpx;
			display: flex;
			padding: 0 25rpx 0 32rpx;
			position: relative;
			margin-bottom: 43rpx;
			.tt-icon1 {
				display: inline-block;
				width: 40rpx;
				height: 40rpx;
				display: flex;
				justify-content: space-around;
				margin-right: 23rpx;
				.img1 {
					width: 36rpx;
					height: 40rpx;
				}
				.img2 {
					width: 40rpx;
					height: 40rpx;
				}
				.img3 {
					width: 34rpx;
					height: 40rpx;
				}
				.img4 {
					width: 38rpx;
					height: 40rpx;
				}
			}
			.tt-txt {
				display: inline-block;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #333333;
				line-height: 40rpx;
			}
			.next-icon {
				display: inline-block;
				width: 40rpx;
				height: 40rpx;
				position: absolute;
				right: 40rpx;
			}
		}
	}
</style>
