<!-- 审批表格 -->
<template>
	<div class='approvalDialog'>
		<el-dialog title="" :show-close="false" :append-to-body="true" :close-on-click-modal="false" :close-on-press-escape="false" :lock-scroll="true" :visible.sync="dialogApprovalVisible">
			<div slot="title" class="header-title">
				<span class="dialogHeader">新增请假申请</span>
				<img @click="closeDialog('approvalForm')" class="dialogHeaderClose" src="../assets/images/dialogClose.png" />
			</div>
			<div class="">
				<div class="approvalDiv">
					<el-form :model="approvalForm" :rules="rules" ref="approvalForm" label-width="130px" class="demo-ruleForm">
						<el-form-item label="请假类型" prop="type">
							<el-radio-group v-model="approvalForm.type">
								<el-radio style="margin-right: 60px" label="事假"></el-radio>
								<el-radio style="margin-right: 60px" label="病假"></el-radio>
								<el-radio style="margin-right: 60px" label="公出"></el-radio>
								<el-radio style="margin-right: 60px" label="出差"></el-radio>
								<el-radio label="调休"></el-radio>
							</el-radio-group>
						</el-form-item>
						<el-row :gutter="20">
							<el-col :span="5">
								<el-form-item label="申请人">
									<div class="nameAppUser">{{userDetail.username}}</div>
									<!--<el-input v-model="approvalForm.name"></el-input>-->
								</el-form-item>
							</el-col>
							<el-col :span="8">
								<el-form-item label="部门" prop="department">
									<el-select v-model="approvalForm.department" placeholder="请选择部门">
										<el-option
														v-for="item in departData"
														:key="item.id"
														:label="item.name"
														:value="item.id">
										</el-option>
									</el-select>
								</el-form-item>
							</el-col>
							<el-col :span="11">
								<!--<el-form-item label="天数" prop="day">-->
									<!--<el-input v-model="approvalForm.day"></el-input>-->
								<!--</el-form-item>-->
								<el-form-item label="请假时间" prop="time">
									<el-date-picker
													style="width: 90%"
													v-model="approvalForm.time"
													type="datetimerange"
													align="right"
													:editable="false"
													:clearable="false"
													value-format="yyyy-MM-dd HH:mm:ss"
													start-placeholder="开始日期"
													end-placeholder="结束日期"
													:default-time="['09:00:00', '17:00:00']">
									</el-date-picker>
								</el-form-item>
							</el-col>
						</el-row>
						<el-form-item class="first" label="请假事由" prop="des">
							<el-input type="textarea" :rows="10" v-model="approvalForm.des"></el-input>
						</el-form-item>
					</el-form>
				</div>
				<div class="dialogBtns">
					<el-button class="mrgt" type="primary" @click="approvalSubmit('approvalForm')">确定</el-button>
				</div>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
	//例如：import 《组件名称》 from '《组件路径》';

	export default {
		name: "approvalDialog",
//import引入的组件需要注入到对象中才能使用
		components: {},
		props: ['showApprovalDialog', 'depart'],
		data () {
//这里存放数据
			return {
				dialogApprovalVisible: false,
				approvalForm: {
					type: '',
					des: '',
					department: '',
					time: '',
				},
				departData: [],
				rules:{
					department: [
						{ required: true, message: '请选择部门', trigger: 'change' }
					],
					time: [
						{ required: true, message: '请选择请假时间', trigger: 'change' }
					],
					type: [
						{ required: true, message: '请选择请假类型', trigger: 'change' }
					],
					des: [
						{ required: true, message: '请填写请假事由', trigger: 'blur' }
					]
				},
				userDetail: '',
			};
		},
//监听属性 类似于data概念
		computed: {},
//监控data中的数据变化
		watch: {
			showApprovalDialog: {
				immediate: true,
				handler(showApprovalDialog) {
					this.dialogApprovalVisible = showApprovalDialog;
				}
			},
			depart: {
				immediate: true,
				handler(val) {
					console.log(val)
					this.departData = val;
				}
			}
		},
//方法集合
		methods: {
			closeDialog(formName) {
				this.$refs[formName].resetFields();
				this.$emit('close', 'add');
			},
			approvalSubmit(formName) {
				this.$refs[formName].validate((valid) => {
					if (valid) {
						let obj = {
							"applyTime": null,
							"approvalLevel": null,
							"approvalOne": null,
							"approvalStatus": null,
							"approvalTwo": null,
							"approvalType": this.approvalForm.type,
							"approvalUserIdOne": null,
							"approvalUserIdOneName": null,
							"approvalUserIdTwo": null,
							"departmentId": this.approvalForm.department,
							"description": this.approvalForm.des,
							"id": null,
							"leaveEndTime": this.approvalForm.time[1],
							"leaveStartTime": this.approvalForm.time[0],
							"userName": this.userDetail.username,
							"reason": null,
							"status": null,
							"title": null,
							"userId": this.userDetail.id
						}
						console.log(obj)
						this.$axios.postSubmitApproval(obj).then((res) => {
							console.log(res)
							if (res.status === 200) {
								this.$message({
									message: `新增${this.approvalForm.type}申请成功！`,
									type: 'success'
								});
								this.closeDialog('approvalForm');
							}
						})
					} else {
						console.log('error submit!!');
						return false;
					}
				});
			}
		},
//生命周期 - 创建完成（可以访问当前this实例）
		created () {

		},
//生命周期 - 挂载完成（可以访问DOM元素）
		mounted () {
			this.userDetail = JSON.parse(this.$Base64.decode(localStorage.getItem('login')));
			console.log(this.userDetail);
		},
		beforeCreate () {
		}, //生命周期 - 创建之前
		beforeMount () {
		}, //生命周期 - 挂载之前
		beforeUpdate () {
		}, //生命周期 - 更新之前
		updated () {
		}, //生命周期 - 更新之后
		beforeDestroy () {
		}, //生命周期 - 销毁之前
		destroyed () {
		}, //生命周期 - 销毁完成
		activated () {
		}, //如果页面有keep-alive缓存功能，这个函数会触发
	}
</script>
<style scoped>
	/deep/ .el-form-item__label {
		text-align: center;
		vertical-align: middle;
		float: none;
		font-size: 18px;
		color: #606266;
		line-height: 40px;
		padding: 0 12px 0 0;
		-webkit-box-sizing: border-box;
		box-sizing: border-box;
	}

	/deep/ .el-form-item__content {
		line-height: 40px;
		position: relative;
		font-size: 14px;
		font-weight: bold;
		margin-left: 0 !important;
	}

	.approvalDiv{
		width: 90%;
		margin: 30px auto;
		text-align: left;
	}

	.dialogBtns{
		position: fixed;
		bottom: 0;
		left: 10%;
		width: 80%;
		margin: 80px auto;
		text-align: center;
		border-top: 2px solid #5059D5;
	}

	.mrgt{
		margin-top: 20px;
	}

	/deep/ .el-textarea__inner {
		display: block;
		resize: vertical;
		padding: 5px 15px;
		line-height: 1.5;
		-webkit-box-sizing: border-box;
		box-sizing: border-box;
		width: 100%;
		font-size: 18px;
		color: #606266;
		background-color: #EFF2FA;
		background-image: none;
		border: 1px solid #DCDFE6; /*no*/
		border-radius: 4px;
		-webkit-transition: border-color .2s cubic-bezier(.645,.045,.355,1);
		transition: border-color .2s cubic-bezier(.645,.045,.355,1);
	}

	.nameAppUser{
		font-size: 18px;
	}

	/deep/ .el-date-editor .el-range-separator {
		padding: 0 5px; /*no*/
		line-height: 40px;
		width: 10%;
		color: #303133;
		margin-top: -9px;
	}

	/deep/ .el-date-editor .el-range__icon {
		font-size: 14px;
		margin-left: -5px; /*no*/
		color: #C0C4CC;
		float: left;
		line-height: 40px;
		margin-top: -8px;
	}
</style>
