<template>
	<view>
		<view class='wrap'>
			<view class="c-row">
				<view class="title">请假类型</view>
				<view class="con-list">
					<view @click='show=true'>{{detailData.leaveType}} ></view>
					<u-picker :range="leaveTypeList" range-key="leaveType"@confirm='ltCheck($event)' v-model="show" mode="selector">
					</u-picker>
				</view>
			</view>
			<view class="c-row">
				<view class="title">开始时间</view>
				<view class="con-list">
					<view @click='show1=true'>{{detailData.startDate}} ></view>
					<u-picker v-model="show1" mode="time" @confirm='dateChange($event)' :params="params">
					</u-picker>
				</view>
			</view>
			<view class="c-row">
				<view class="title">结束时间</view>
				<view class="con-list">
					<view @click='show2=true'>{{detailData.endDate}} ></view>
					<u-picker v-model="show2" mode="time" @confirm='dateChange1($event)' :params="params">
					</u-picker>
				</view>
			</view>
			<view class="c-row">
				<view class="title">时长</view>
				<view class="con-list">
					<input  v-model='detailData.leaveDuration' placeholder="请输入时长"></input>
				</view>
			</view>
			<view class="c-row">
				<view class="left">请假事由</view>
			</view>
			<view style='position:relative;' class="wrap no-boder">
				<u-input class='textarea' v-model="detailData.reasonForLeave" :type="type" :border="border"
					:height="height" :auto-height="autoHeight" />
				<view style='position:absolute;right:10px;bottom:20px;color:#AFB3BF;'>
					{{detailData.reasonForLeave.length}}/100个字
				</view>
			</view>
		</view>
		
		<!-- <view class="footer">
			<view @click='clockRecord' class="button">记录</view>
			<view @click='submit' class="button">提交</view>
		</view> -->
		<u-toast ref="uToast" />
		<view class="bottom-btn">
			<view style='margin:5px 0;'>
				<u-button type="primary" class="submit" hover-class="none" @click="submit">提交</u-button>
			</view>
			<view>
				<view style='width:100%;' class='flex flex-space-between'>
					<view @click='clocksubmit' style='width:50%;text-align:center;'>
						<image
						v-if='value==0'
							class="u-page__item__slot-icon"
							src="../../static/img/oa_office/leave/qingjia-check.png"
						></image>
						<image
						v-else
							class="u-page__item__slot-icon"
							src="../../static/img/oa_office/leave/qingjia.png"
						></image>
						<view :style='{"color":value==0?"#22C572":"#000"}'>请假</view>
					</view>
					<view @click='clockRecord' style='width:50%;text-align:center;'>
						<image
						v-if='value==1'
							class="u-page__item__slot-icon"
							src="../../static/img/oa_office/leave/jilu-check.png"
						></image>
						<image
						v-else
							class="u-page__item__slot-icon"
							src="../../static/img/oa_office/leave/jilu.png"
						></image>
						<view :style='{"color":value==1?"#22C572":"#000"}'>记录</view>
					</view>
				</view>
			</view>
			
			<!-- <u-button type="primary" class="submit" hover-class="none" @click="clockRecord">记录</u-button> -->
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
				show: false,
				show1: false,
				show2: false,
				detailData: {
					leaveType:'选择请假类型',
					reasonForLeave:"",
					startDate:'',
					endDate:'选择结束时间',
					leaveDuration:'',
				},
				params: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					
				},
				value:0,
				type: 'textarea',
				border: true,
				height: 150,
				autoHeight: true,
				// endDate1:"",
				// startDate1: "",
				leaveTypeList: [{
						leaveType: "事假"
					},
					{
						leaveType: "病假"
					},
				],

			}
		},
		onLoad(options) {
			let h 
			let m 
			let s
			let _day = new Date();
			_day.setTime(_day.getTime());
			if(_day.getHours() < 10 ){
				 h = "0" + _day.getHours()
			}
			else{
				h =  _day.getHours()
			}
			if(_day.getMinutes() < 10 ){
				 m = "0" + _day.getMinutes()
			}
			else{
				m = _day.getMinutes()
			}
			this.detailData.startDate = _day.getFullYear() + "-" + (_day.getMonth() + 1) + "-" + _day.getDate()
			+ " " + h + ":" + m;
		},
		methods: {
			calculate() {
				const query = uni.createSelectorQuery().in(this);
				query.selectAll('.left')
				console.log(query)
			},
			ltCheck(e) {
				this.detailData.leaveType = this.leaveTypeList[e].leaveType
				if(this.detailData.leaveType = "事假"){
					this.detailData.leaveTypeKey = "1"
				}
				else{
					this.detailData.leaveTypeKey = "3"
				}
			},
			dateChange(e) {
				this.detailData.startDate = e.year + "-" + e.month + "-" + e.day + " " + e.hour + ":" + e.minute
				// this.startDate1 = e.year + "-" + e.month + "-" + e.day + "-" + e.hour + "-" + e.minute + "-" + e.second
				 // + ":" + "00"
			},
			dateChange1(e) {
				this.detailData.endDate = e.year + "-" + e.month + "-" + e.day + " " + e.hour + ":" + e.minute
				var endtime=new Date(this.detailData.endDate)
				var starttime=new Date(this.detailData.startDate)
				console.log(endtime-starttime)
				this.detailData.leaveDuration=Math.floor((endtime-starttime)/(3600*1000))
				// this.endDate1 = e.year + "-" + e.month + "-" + e.day + "-" + e.hour + "-" + e.minute + "-" + e.second
			},
			submit() {
				if (!this.detailData.leaveType) {
					this.$api.msg('请假类型不能为空')
					return
				}
				if (!this.detailData.startDate) {
					this.$api.msg('请选择请假开始时间')
					return
				}
				if (!this.detailData.endDate) {
					this.$api.msg('请选择请假结束时间')
					return
				}
				if (!this.detailData.leaveDuration) {
					this.$api.msg('请输入请假时长')
					return
				}
				if (!this.detailData.reasonForLeave) {
					this.$api.msg('请假事由不能为空')
					return
				}
				var that = this
				uni.showModal({
					content: "确定提交请假信息？",
					showCancel: true,
					confirmText: '提交',
					success: function(res) {
						if (res.confirm) {
							that.detailData.compId = uni.getStorageSync('pcUserInfo').compId
							that.detailData.commonId = uni.getStorageSync('pcUserInfo').userId
							that.detailData.dept = uni.getStorageSync('pcUserInfo').deptName
							that.detailData.phone = uni.getStorageSync('pcUserInfo').userMobilePhone
							that.detailData.empName = uni.getStorageSync('userInfo').userName
							that.$api.doRequest('post', '/leaveInfo/api/addLeave', that.detailData)
								.then(res => {
									if (res.data.code == 200) {
										that.$api.msg('提交成功')
										uni.navigateTo({
											url: '/pages/leave/the_leave_record'
										})
									} else {
										that.$api.msg('提交失败')
									}
								})
						}
					}
				})
			},
			clockRecord() {
				uni.navigateTo({
					url: '/pages/leave/the_leave_record'
				})
			},
			clocksubmit() {
				uni.navigateTo({
					url: '/pages/leave/the_leave'
				})
			},
		},
	}
</script>

<style lang='scss' scoped>
	page {
		background: #F5F6FA;
	}

	.title_b {
		margin: 20rpx 20rpx 0rpx 20rpx;
		padding: 20rpx 10rpx 20rpx 10rpx;
		font-size: 18px;
		font-weight: 550;
	}

	.c-row {
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
		-webkit-box-align: center;
		-webkit-align-items: center;
		align-items: center;
		padding: 20rpx 30rpx;
		position: relative;
	}

	.con-list {
		-webkit-box-flex: 1;
		-webkit-flex: 1;
		flex: 1;
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
		-webkit-box-orient: vertical;
		-webkit-box-direction: normal;
		-webkit-flex-direction: column;
		flex-direction: column;
		color: #303133;
		line-height: 40rpx;
		text-align: right;
		padding-right: 20rpx;
	}

	.wrap {
		padding-bottom: 10px;
		font-size: 14px;
		background: #fff;
		margin: 10px;
		border-radius: 10px;

		input {
			font-size: 14px;
		}

		>.title {
			padding: 10px 16px;
		}

	}

/* 	.footer {
		background: #fff;
		position: fixed;
		bottom: 0;
		width: 100%;
		padding: 20px 10px;
		z-index: 10;

		.button {
			background: #22C572;
			width: 90%;
			margin: 20rpx auto;
			padding: 10px;
			color: #fff;
			text-align: center;
			border-radius: 30px;
		}
	} */
	.submit {
		width: 40%;
		background: #22C572;
		border-radius: 10rpx;
	}
	.bottom-btn {
		padding: 30rpx;
		background: #FFFFFF;
		width: 100%;
		position: fixed;
		bottom: 0rpx;
		z-index: 9999;
	}

	.buns_item {
		display: flex;
		padding: 80rpx 0 50rpx 0;
		justify-content: space-around;
	}

	.but_css {
		background: #22C572;
		width: 40%;
		padding: 20rpx;
		color: #fff;
		text-align: center;
		border-radius: 20rpx;
	}

	/deep/.u-radio-group {
		flex-direction: row-reverse;
	}
	.no-boder {
		border: 0;
	}
	.textarea {
		background: #F9F9FA;
		border: 1px solid #EEEEEE;
	}
	.u-page__item__slot-icon{
		width:20px;
		height:20px;
	}
</style>
