<template>
	<view class="container">
		<image class="cbg" :src="base.imgHost('book-bg.png')"></image>
		<image class="schoolmate" @click="toUrl(2)" :src="base.imgHost('book-schoolmate.png')"></image>
		
		<image class="book" @click="toUrl(1)" :src="base.imgHost('book-book.png')"></image>
		<tabbar :currentPage="2"></tabbar>
	</view>
</template>

<script>
	import tabbar from '@/components/tabbar/tabbar.vue';
	export default {
		components: {
			tabbar
		},
		data() {
			return {
				user: {},
				can_appointment: false,
				is_schoolmate: 0,
				door_appointments: false, // 当前是否有预约
			}
		},
		onShareAppMessage() {
			return{
				title:"苏州科技商学院",
				imageUrl:"/static/share.jpg"
			}
		},
		onShareTimeline() {
			return{
				title:"苏州科技商学院",
				imageUrl:"/static/share.jpg"
			}
		},
		onShow() {
			this.getUser()
		},
		onLoad() {
		},
		methods: {
			getUser() {
				this.$u.api.user().then(res => {
					console.log("res", res)
					this.is_schoolmate = res.user.is_schoolmate
					if (res.user.appointment_total - res.user.pass_appointments > 0) {
						this.can_appointment = true
					} else {
						this.can_appointment = false
					}
					this.door_appointments = res.door_appointments ? true : false
					this.$u.vuex('vuex_user', res.user)
				})
			},
			toUrl(type) {
				if (type === 1) {
					if (!this.can_appointment) {
						this.base.toast("您当前没有可预约次数")
						return
					}
					if (this.door_appointments) {
						this.base.toast("您当前已有预约")
						return
					}
					uni.navigateTo({
						url: '/packages/booksubmit/appointment'
					})

				} else if (type === 2) {
					if (this.is_schoolmate) {
						uni.navigateTo({
							url: '/packages/schoolmate/index'
						})
					} else {
						this.base.toast("您还不是校友，无权查看")
					}

				}
			}
		},

	}
</script>

<style scoped lang="scss">
	.container {
		width: 100%;
		height: 100vh;
		padding-bottom: 200rpx;

		.cbg {
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 100vh;
		}
		.schoolmate{
			width:367rpx;
			height:186rpx;
			position: absolute;
			top: 300rpx;
			left: 30rpx;
		}
		.book{
			width:367rpx;
			height:186rpx;
			position: absolute;
			bottom: 300rpx;
			right: 30rpx;
		}


		

	}
</style>