<template>
	<view class="page">
		<view class="content">
			<text class=" text-xl ">出入信息填写</text>
			<view class="name">
				<view >
					<text>*</text>
					<text>您的姓名</text>
				</view>
				<view class="input">
					<input disabled=""  type="text" value="" v-model="member.name" placeholder="请输入您的姓名"/>
				</view>
			</view>
			
			<view class="cause">
				<view >
					<text >*</text>
					<text>出入原因</text>
				</view>
				<view class="input">
					<input  type="text" value="" v-model="reason" placeholder="请填写出入小区的原因"/>
				</view>
			</view>
			
			<view class="radio1 flex justify-between" >
				<view >
					<text >*</text>
					<text style="line-height: 56rpx;">体温是否异常（高于37.3摄氏度属于异常）</text>
				</view>
				<view class="switch">
					<switch style="transform: scale(.9);" class='blue' @change="switch1Change"  :checked="switch1Check" ></switch>
				</view>
			</view>
			
			<view class="radio1 flex justify-between" >
				<view >
					<text >*</text>
					<text style="line-height: 56rpx;">是否有咳嗽 / 乏力 / 呼吸困难 / 流鼻涕 / 腹泻等异常症状</text>
				</view>
				<view class="switch">
					<switch style="transform: scale(.9);" class='blue' @change="switch2Change"  :checked="switch2Check" ></switch>
				</view>
			</view>
		</view>
		<view @click="goList" class=" text-center margin-top-30">
			<u-icon name="order" color="#0081ff"></u-icon>
			<text class="text-blue text-df padding-left-10" >登记记录</text>
		</view>
		
		
		<button style="border-radius: 0;" v-if="$isEmpty(userInfo)" open-type="getUserInfo" @getuserinfo="getUserInfo" class=" footer-fixed" >
			<view class="cu-btn  flex  text-lg bg-red-btn" style="padding: 46rpx 0;">
				提交信息
			</view>
		</button>
		
		<view v-else @click="submit" class=" footer-fixed">
			<view class="cu-btn  flex  text-lg bg-red-btn" style="padding: 46rpx 0;">
				提交信息
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//出入小区
				residentialId:'',
				residplotName:'',
				
				member:{},
				//出入原因
				reason:'',
				//体温是否异常
				switch1Check:false,
				//是否咳嗽
				switch2Check:false,
				
				//获取用户信息
				userInfo:{},
			}
		},
		onLoad() {
			this.member=getApp().globalData.member
			this.residentialId=uni.getStorageSync("residentialId")
			this.plotName=uni.getStorageSync("plotName")
			if (this.$isEmpty(this.member)||this.$isEmpty(this.residentialId)) {
				uni.showModal({
					content:'系统异常',
					showCancel:false,
					success: (res) => {
						if (res.confirm) {
							uni.navigateBack({
								delta:1
							})
						}
					}
				})
				return
			}
			this.login()
			this.getRecordByCondition()
		},
		methods: {
			/**
			 * 通过member和当天时间查询当天是否填写了防疫通行记录
			 * 如果有记录，直接跳转到通行详情那去
			 */
			getRecordByCondition(){
				let that=this
				var date=new Date()
				let createDate= date .toLocaleDateString().replace(RegExp("/", "g"), "-")+" "+"00:00:00"
				let params={
					memberId:this.member.id,
					createDate:createDate,
					residentialId:this.residentialId
				}
				console.log(params);
				// let operation='pratique/getListByMemberId'
				that.$http.pratiqueList(params).then(res =>{
					if (!that.$isEmpty(res.data.list)) {
						getApp().globalData.pratiqueData=res.data.list[0]
						uni.reLaunch({
							url:"./detail"
						})
					}
					
				})
			},
			switch1Change(e){
				this.switch1Check=e.target.value
			},
			switch2Change(e){
				this.switch2Check=e.target.value
			},
			getUserInfo(e){
				if (this.$isEmpty(e.detail.userInfo)) {
					this.$u.toast('用户拒绝获取头像信息')
					return
				}
				this.userInfo=e.detail.userInfo
				uni.setStorage({
					key:"userInfo",
					data:this.userInfo
				})
				this.submit()
			},
			login(){
				let that=this
				uni.login({
				  success: function () {
				    uni.getUserInfo({
				      success: function (res) {
				        that.userInfo=res.userInfo
						uni.setStorage({
							key:"userInfo",
							data:that.userInfo
						})
				      }
				    });
				  }
				});
			},
			submit(){
				let that=this
				if (this.$isEmpty(this.reason)) {
					this.$u.toast('请输入出入原因')
					return
				}
				let params={
					memberId:this.member.id,
					reason:this.reason,
					residentialId:this.residentialId,
					residentialName:this.plotName,
					temparetureException:0,
					symptomException:0
				}
				if (this.switch1Check) {
					params.temparetureException=1
				}
				
				if (this.switch2Check) {
					params.symptomException=1
				}
				// let operation='pratique/addPratique'
				that.$http.addPratique(params).then(res =>{
					if (res.data.result_code==1) {
						getApp().globalData.pratiqueData=res.data.pratique
						uni.reLaunch({
							url:"./detail"
						})
					}
					
				})
			},
			goList(){
				uni.navigateTo({
					url:"/pages/tool-list/epidemic-pass/list"
				})
			}
		}
	}
</script>

<style lang="scss">
	.page{
		min-height: 100vh;
		background-color: #FFFFFF;
	}
	
	.content{
		padding: 40rpx;
		.name,.cause,.radio1,.radio2{
			padding-top: 40rpx;
			view:nth-child(1){
				display: flex;
				// *星号
				text:nth-child(1){
					font-weight: 800;
					font-size: 38rpx;
					color: #D43A39;
					padding-right: 10rpx;
				}
				//您的姓名
				text:nth-child(2){
					font-size: 30rpx;
				}
			}
			.input{
				padding: 20rpx 0 15rpx 25rpx;
				border-bottom: 1rpx solid #d6d6d6;
			}
		}
		switch{
			display: flex;
		}
		.radio1,.radio2{
			padding-bottom: 15rpx;
			border-bottom: 1rpx solid #d6d6d6;
			.switch{
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}
	}
	
	
</style>
