<template>
	<view class="sign_success" v-if="flag">
		<view class="top-img">
			<image :src="meetingInfo.image" style="width: 100%;height: 100%;"></image>
		</view>
		<view class="main tn-pt-xl">
			<view class="warn">
				<view class="icon tn-flex tn-flex-center-center">
					<tn-icon name="success-circle-fill" color="#19be6b" size="160"></tn-icon>
				</view>
				<view class="text tn-text-xl tn-text-bold tn-text-center tn-mt">
					签到成功
				</view>
			</view>

			<view class="welcome tn-mt">
				<view class="tn-text-center tn-text-bold tn-text-lg">欢迎您</view>
				<view class="text tn-text-center">
					<view class="tn-text-lg tn-pt-sm">
						{{userInfo.company}}
					</view>
					<view class="tn-text-lg tn-pt-sm">
						{{userInfo.position+' '+userInfo.name}}
					</view>
				</view>
				<view class="seat tn-pt-sm" v-if="userInfo.row && userInfo.column">
					<view class="tn-text-center tn-text-lg">
						您的座次是
					</view>
					<view class="tn-text-center tn-text-bold tn-red-dark_text tn-text-xl">
						{{userInfo.row + '排' + userInfo.column + '列'}}
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script lang="ts" setup>
	import { onMounted, reactive, ref } from 'vue';
	import { onLoad } from "@dcloudio/uni-app";
	import request from '@/utils/request';
	
	const flag = ref()
	const meetingId = ref()
	const meetingInfo = reactive<{
		image?:string
	}>({})
	const userInfo = reactive<{
		avatar?:string,
		name?:string,
		company?:string,
		position?:string,
		row?:string,
		column?:string
	}>({})
	
	
	const getUserInfo = () =>{
		let user = uni.getStorageSync('user')
		request({
			url: '/sign/signInfo',
			method:'GET',
			data:{'meetingId':meetingId.value,openid:user.openid}
		}).then(res=>{
			if(res.data.code === 0){
				meetingInfo.image = res.data.data.meeting.image
				userInfo.avatar = user.avatar
				userInfo.name = res.data.data.name
				userInfo.company = res.data.data.company
				userInfo.position = res.data.data.position
				userInfo.row = res.data.data.row
				userInfo.column = res.data.data.column
				flag.value = true
				uni.setNavigationBarTitle({
					title:'签到成功'
				})
			}else{
				uni.showToast({
					title:'请登记个人信息',
					icon:'none',
					success: () => {
						uni.navigateTo({
							url:'/pages/attendance/register?id=' + meetingId.value 
						})
					}
				})
			}
		})
	}
	
	onLoad((options) => {
		meetingId.value = options.id
	})
	
	onMounted(() => {
		getUserInfo()
	}) 
</script>

<style lang="scss" scoped>
	.sign_success{
		height: 100vh;
		background-color: #f5f5f5;
		.top-img{
			width: 100%;
			height: 360rpx;
		}
		.main{
			background-color: #fff;
			height: calc(100vh - 360rpx);
		}
	}
</style>