<template>
	<div class="content my-content main-content">
		<!-- 轮播图 -->
		<div class="banner my-banner">
			<img src="../../../assets/images/user/banner.jpg" alt="" />
			<div class="my-photo">
				<span>
					<img v-if="userData.avatar" :src="host + userData.avatar" />
					<img v-else src="../../../assets/images/user/photo.png" />
				</span>
				<p v-if="userData.nick_name">{{ userData.nick_name }}</p>
				<p v-else>未填写个人信息</p>
			</div>
		</div>
		<!-- 免费咨询卡 -->
		<div class="user-receive" @click="toPage()" v-if="!isExpire">
			<img src="../../../assets/images/user/card.png" />
			<div class="receive-txt">
				<span class="use-btn" v-if="consult_amount == 1">立即使用</span>
				<span class="receive-btn" v-if="consult_amount == 0">立即领取</span>
				<p v-if="consult_amount == 1 && startTime">有效期：{{startTime}}-{{endTime}}</p>
			</div>
		</div>
		<div class="line" v-if="consult_amount == 1"></div>
		<ul class="student-information">
			<li>
				<span><img src="../../../assets/images/user/icon-phone.png" /></span>
				<p>
					手机号<em>{{ userData.mobile }}</em>
				</p>
			</li>
			<li @click="goPage('/info')">
				<span><img src="../../../assets/images/user/icon-student.png" /></span>
				<p>考生信息</p>
				<img src="../../../assets/images/home/expert/arrow-right.png" />
			</li>
		</ul>
		<div class="feedback" @click="goPage('/feedback')">
			<span><img src="../../../assets/images/user/icon-feedback.png" /></span>
			<p>意见和反馈</p>
			<img src="../../../assets/images/home/expert/arrow-right.png" />
		</div>
		<div :class="{ 'my-report': true, 'open': isOpen }" @click="isOpen = !isOpen">
			<span><img src="../../../assets/images/user/icon-report.png" alt="" /></span>
			<p>我的报告</p>
			<img src="../../../assets/images/home/expert/arrow-right.png" alt="" />
		</div>
		<ul :class="{'report-list': true, 'open': isOpen}">
			<li v-for="(item,index) in reportData" :key="index" @click="goReport(item.id)">
				<p>{{item.title}}</p>
				<span>{{item.done_at}}</span>
			</li>
		</ul>
		<div class="feedback-btn" @click="outLogin()">退出登录</div>
		<tabbar :current="4"></tabbar>
	</div>
</template>

<script>
	import tabbar from "../../../components/tabbar.vue";
	export default {
		name: "expert",
		components: {
			tabbar,
		},
		data() {
			return {
				centerUserData: {
					mobile: "",
				},
				isExpire: false, //是否失效
				consult_amount: 0,
				reportData: [],
				isUse: 0, //是否使用
				isOpen: false,
				userData: {
					avatar: "",
					consult_amount: 0,
					create_time: "",
					ding_code: "",
					expert_id: 0,
					gender: 0,
					id: 31,
					im_uid: "",
					lat: "",
					lng: "",
					login_time: "",
					mobile: "",
					nick_name: "",
					open_id: "",
					real_name: "",
					tags: "",
					tel: "",
					type: 0,
					unionid: "",
					update_time: "",
					user_code: "",
				},
				student_first_complete:'' ,//领取咨询卡时间
				startTime: '', //有效期开始时间
				endTime: '', //有效期结束
			};
		},
		created() {
			this.getUserData();
			this.getevaluationList()
			this.consult_amount = (JSON.parse(localStorage.getItem("centerUserData"))).consult_amount;
		},
		mounted() {
			this.getDate();
		},
		methods: {
			// 获取报告列表
			getevaluationList() {
				let that = this
				this.axios.post(this.HOME + "/api/evaluation/evaluation-list", {
					page: "1",
					size: "100",
					status: "done"
				}).then(function(res) {
					that.reportData = res.data.data.list;
					console.log(that.reportData,555)
				});
			},

			// 判断跳转方式
			toPage() {
				if (this.consult_amount == 1) {
					this.$router.push("/expert");
				} else if (this.consult_amount == 0) {
					this.$router.push("/information");
				} else {
					return false;
				}
			},

			// 页面跳转
			goPage(path) {
				this.$router.push(path)
			},

			// 查看报告
			goReport(id) {
				this.$router.push({
					path: "/report",
					query: {
						id: id
					},
				});
			},

			// 获取用户信息
			getUserData() {
				let that = this;
				this.axios.post(this.HOME + "/api/user/center-info").then(function(res) {
					that.userData = res.data.data;
					localStorage.centerUserData = JSON.stringify(res.data.data);
				});
			},
			
			// 获取有效时期
			getDate() {
				let starTime = (JSON.parse(localStorage.getItem("centerUserData"))).student.student_first_complete;
				
				let date = new Date(starTime.replace(/-/g, '/'));
				this.startTime = date.getFullYear()+"."+(date.getMonth()+1)+"."+date.getDate(); //有效期开始时间
				console.log(this.startTime,2222222)
				let date1 = new Date(starTime.replace(/-/g, '/'));
				date1.setDate(date.getDate()+7);
				this.endTime = date1.getFullYear()+"."+(date1.getMonth()+1)+"."+date1.getDate(); //有效期结束时间
				
				// 获取当前时间
				let date2 = new Date();
				if(date1.setDate(date.getDate()+7) <= date2.setDate(date.getDate())){
					this.isExpire = true;
				}
			},

			// 退出登录
			outLogin(){
				localStorage.clear();
				this.$router.push('/login');
			},
		},
	};
</script>

<style scoped>
	.banner,
	.banner img {
		width: 100%;
	}
</style>
