<template name="index">
	<view class="index">
		<view class="temp">
			<view class="btnList">
				<button class="btnStaff" type="primary" @click="staff" v-show="flag">员工填报</button>
				<button class="btnSecurity" type="primary" @click="fillInDay" v-show="!flag">每日填报</button>
				<button class="btnSecurity" type="primary" @click="security">安保测温</button>
				<!-- <image class="img" src="../../static/22.jpg" mode="" @click="fillInDay"></image> -->
				<image class="img" :src="imgSrc" mode="widthFix" @click="modalName = 'Image'">
				<view class="tips">入园请向门卫出示健康码</view>
			</view>
		</view>
		<view class="cu-modal" :class="modalName=='Image'?'show':''" @tap="modalName=''">
			<view class="cu-dialog">
				<view class="bg-img">
					<view class="cu-bar justify-end text-black">
						<view class="action" @tap="modalName = ''">
							<text class="cuIcon-close"></text>
						</view>
					</view>
				</view>
				<image :src="imgSrc" mode="widthFix"></image>
				<view class="cu-bar bg-white">
					<view class="action margin-0 flex-sub  solid-left text-right" @tap="modalName = ''"></view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		components: {},
		name: "home",
		data() {
			return {
				imgSrc:'',
				modalName:'',
				flag:true,
				option:{
					userId:''
				}
			};
		},
		onLoad: function(option) {
			const scene = decodeURIComponent(option.scene)
			console.log(scene)
			this.option = option
			let that = this
			// #ifdef MP-WEIXIN 
			wx.login({
				success(res) {
					if (res.code) {
						let code = res.code
						that.getUserInfo(code)
					} else {
						console.log('登录失败!' + res.errMsg)
					}
				}
			})
			// #endif 
		},
		onShow() {
			if(this.$store.state.user.userInfo.idCard){
				this.getUserInfo(code)
			}
		},
		methods: {
			getImg(){
				this.$http.get(`/sict-ncov/user/qrcode`).then(res => {
					const d = res.data
					if (d.code == 1) {
						this.imgSrc = d.object
					}
				}).catch(err => {
					console.log(err)
				})
			},
			// 员工跳转
			staff() {
				uni.navigateTo({
					url: `/pages/fillIn/fillIn`
				})
			},
			
			// 安保跳转
			security() {
				uni.navigateTo({
					url: `/pages/security/security`
				})
			},
			fillInDay() {
				console.log(232)
				uni.navigateTo({
					url:`/pages/fillInDay/fillInDay`
				})
			},
			// 获取用户信息
			getUserInfo(code) {
				this.$http.post(`/sict-ncov/user/auth?code=${code}`).then(res => {
					const d = res.data
					if (d.code == 1) {
						let userInfo = d.object
						if(userInfo.idCard){
							this.flag=false
						}
						let obj = Object.assign({}, this.$store.getters.userInfo)
						if (obj.avatarUrl) {
							userInfo.avatarUrl = obj.avatarUrl
						}
						this.$store.dispatch('user/setInfo', Object.assign(obj, userInfo))
						this.$store.dispatch('user/setToken', d.result)
						this.getImg()
					}
				}).catch(err => {
					console.log(err)
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.temp {
		font-size: 40px;
		text-align: center;
		height: 100vh;
		width: 100vw;
		background-repeat: no-repeat;
		background-size: cover; 
		background-image: url('http://139.9.163.126/gastric/static/background.jpg');
		.btnList{
			padding-top: 395upx;
			.btnStaff,.btnSecurity{
				background-color: #92d0f1;
				color: #FFFFFF;
				border-radius: 60upx;
				width: 52%;
				text-align: center;
			}
			.btnSecurity{
				margin-top:45upx;
			}
			.img{
				margin-top:45upx;
				width: 200upx;
				height: 200upx;
			}
			.tips{
				margin-top:25upx;
				font-weight: bold;
				font-size: 28upx;
				color:#FFFFFF;
			}
		}
	}
</style>