<template>
	<view>
		<view class="basemsg-box">
			<view >
				<text>基本信息</text>
			</view>
			<view class="basemsg">
				<label >
					<view class="label-name">
						创建人
					</view>
					<view class="label-data" >
						<input disabled type="text" v-model="form.CreateMan">
					</view>
				</label>
				<label >
					<view class="label-name">
						申请人
					</view>
					<view class="label-data">
						<input type="text" placeholder="申请人" v-model="form.ApplyMan">
						<!-- <uni-data-select
						  v-model="valueApplyMan"
						  :localdata="rangeApplyMan"
						  @change="changeApplyMan"
						style="z-index: 999;"></uni-data-select> -->
					</view>
				</label>
				<label >
					<view class="label-name">
						组织
					</view>
					<view class="label-data">
						<!-- <input type="text" placeholder="组织" v-model="form.organization"> -->
						<uni-data-select
						  v-model="value"
						  :localdata="range"
						  @change="change"
						></uni-data-select>
					</view>
				</label>
				<label >
					<view class="label-name">
						申请日期
					</view>
					<view class="label-data">
						<input type="text" @click="open" v-model="form.ApplyTime" placeholder="请选择申请日期">
						<uni-calendar 
						ref="calendar"
						:insert="false"
						@confirm="confirm"
						 />
					</view>
				</label>
				<label >
					<view class="label-name">
						隔离日期
					</view>
					<view class="label-data">
						<input type="text" @click="openQuarantine" v-model="form.IsolationTime" placeholder="请选择隔离日期">
						<uni-calendar 
						ref="calendarQuarantine"
						:insert="false"
						@confirm="confirmQuarantine"/>
					</view>
				</label>
			</view>
		</view>
		<view class="register-box">
			<view class="">
				<text>人员信息登记</text>
			</view>
			<view >
				<textarea v-model="form.PersonMsg" class="register-textarea" name="" id="" cols="60" rows="10" ></textarea>
			</view>
		</view>
		<view class="button-box">
			<button class="button-msg" @click="submitF()">提交</button>
			<button class="button-msg" @click="back()">取消</button>
		</view>
	</view>
</template>

<script>
	import {applyadmission,getApplyManList} from "../../api/sampling.js"
	export default {
		data() {
			return {
				form:{
					ApplyTime:'',
					IsolationTime:'',
					CreateMan:'原动力',
					ApplyMan:'',
					OrganizationName:'',
					PersonMsg:''
				},
				range: [
					{ value: 1, text: "养猪组织" },
					{ value: 2, text: "养鱼组织" },
					{ value: 3, text: "养花组织" },
					{ value: 4, text: "养羊组织" },
				],
				value: 0,
				rangeApplyMan: [
					{ value: 1, text: "猪组织" },
					{ value: 2, text: "鱼组织" },
					{ value: 3, text: "花组织" },
					{ value: 4, text: "羊组织" },
				],
				valueApplyMan: 0
			};
		},
		methods:{
			changeApplyMan(e) {
			  console.log("e:", e);
			  this.form.ApplyMan = e
			},
			change(e) {
			  // console.log("e:", e);
			  this.form.OrganizationName = e
			},
			open(){
				this.$refs.calendar.open();
			},
			confirm(e) {
				// console.log(e);
				this.form.ApplyTime = e.fulldate
			},
			openQuarantine(){
				this.$refs.calendarQuarantine.open();
			},
			confirmQuarantine(e) {
				this.form.IsolationTime = e.fulldate
			},
			submitF(){
				const data = this.form
				if(this.form.ApplyMan === ""){
					uni.showToast({
						title: '请选择申请人',
						icon:'none',
						duration: 1000
					});
					return
				}
				if(this.form.OrganizationName === ""){
					uni.showToast({
						title: '请选择组织',
						icon:'none',
						duration: 1000
					});
					return
				}
				if(this.form.ApplyTime === ""){
					uni.showToast({
						title: '请选择申请时间',
						icon:'none',
						duration: 1000
					});
					return
				}
				if(this.form.IsolationTime === ""){
					uni.showToast({
						title: '请选择隔离时间',
						icon:'none',
						duration: 1000
					});
					return
				}
				// console.log(data) 
				applyadmission(data).then((res)=>{
					console.log(res) 
					if(res=="添加成功"){
						uni.showToast({
							title: '提交成功',
							icon:'none',
							duration: 1000
						});
						uni.navigateBack({
							delta: 1
						});
					}else{
						uni.showToast({
							title: '提交失败',
							icon:'none',
							duration: 1000
						});
					}
					
				})
			},
			back(){
				uni.navigateBack({
					delta: 1
				});
			}
		},
		onShow(){
			// getApplyManList().then(res=>{
			// 	console.log(res)
			// 	const newArr = res.map(item=>{
			// 		return { 'value':item.code, 'text': item.PersonName}
			// 	})
			// 	this.rangeApplyMan = newArr
			// })
		}
	}
</script>

<style lang="scss" scoped>
page{
	background-color: #f8f8f8;
}
.register-box{
	margin: 30rpx;
}
.register-textarea{
	margin-top: 15rpx;
	background-color: white;
	border:2px solid #f8f8f8;
	padding: 20rpx;
}
.basemsg-box{
	margin: 30rpx;
	.basemsg{
		background-color: #ffffff;
		margin-top: 15rpx;
	}
}
.label-name,.label-data{
	display: inline-block;
	
}
.label-name{
	width: 20%;
	line-height: 80rpx;
	font-weight: 700;
	word-wrap: break-word;
	// text-align: center;
	padding-left: 20rpx;
}
.label-data{
	// text-align: center;
	padding-left: 50rpx;
	width: 65%;
	line-height: 80rpx;
	word-wrap: break-word;
	vertical-align: middle
}
.button-box{
	display: flex;
	justify-content:space-around;
}
.button-msg{
	width: 25%;
	border-radius: 30rpx;
	background-color: #1296db;
	color: #ffffff;
	font-size: 30rpx;
}
/deep/ .uni-select{
	border: none;
	// z-index: 99;
}
/deep/ .uni-select__selector{
	z-index: 99;
}
</style>
