<template>
	<div>
		<common @asynCallBack="asynCallBack"></common>
		<top-header :pageTitle="pageTitle"></top-header>

		<div class="mui-content vongi-qingjiadt">
			<div class="vongi-qingjiadt-head flew-sp">
				<div class="flew-items">
					<div class="flew"><img :src="detail.picUrl" width="50" /></div>
					<h4 v-text="detail.name+' 申请请假 '+detail.leaveTypeN"></h4>
				</div>
				<button class="mui-btn   mui-btn-outlined" :class="statusColor[detail.status]" v-text="status[detail.status]">已批准</button>
				<!-- <div class="examine-refuse">已拒绝</div> -->
			</div>
			<form class="mui-input-group">
				<div class="mui-input-row">
					<label>身份证号</label>
					<span v-text="detail.idCard">420400200002020101</span>
				</div>
				<div class="mui-input-row">
					<label>工号</label>
					<span v-text="detail.jobNumber">0201022121001</span>
				</div>
				<div class="mui-input-row">
					<label>部门</label>
					<span v-text="detail.department">信息工程中心</span>
				</div>
				<div class="mui-input-row">
					<label>请假时间</label>
					<span>自{{detail.startTime}}<br />至{{detail.endTime}}</span>
				</div>
				<div class="mui-input-row">
					<label>请假事由</label>
					<span v-text="detail.reason">家中有事，需要会老家一趟家中有事，需要会老家一趟家中有事，需要会老家一趟家中有事，需要会老家一趟。</span>
				</div>
				<div class="mui-input-row">
					<label>上传图片</label>
					<span class="vongi-qingjiadt-photo">
						<template v-for="(item,index) in picList">
							<img :src="item" v-image-preview />

						</template>
					</span>
				</div>
				<div class="mui-input-row">
					<label>申请时间</label>
					<span v-text="detail.createTime">2020-04-27 12:00:00</span>
				</div>
			</form>

			<div v-if="detail.status==0" class="fyy-scon-botton">
				<div class="examine-btn examine-btn1" @click="openFrom('2','拒绝')">拒绝</div>
				<div class="examine-btn examine-btn2" @click="openFrom('1','同意')">通过</div>
			</div>

			<div v-if="detail.status>0">
				<div class="mui-content-padded">
					<h5>审核记录</h5>
				</div>
				<form class="mui-input-group">
					<div class="mui-input-row">
						<label>审批人</label>
						<span>{{detail.approvedName}}</span>
					</div>
					<div class="mui-input-row">
						<label>审核意见</label>
						<span>{{detail.approvalExplain}}</span>
					</div>
					<div class="mui-input-row">
						<label>审核时间</label>
						<span>{{detail.approvedTime}}</span>
					</div>
				</form>
			</div>
		</div>

		<!-- 审批弹窗 -->
		<div v-show="openFromVisible" @click="openFromVisible=false" class="mui-backdrop mui-active"></div>
		<div v-show="openFromVisible" class="mui-card fyy-popup">
			<div class="mui-card-header mui-h3">审批意见</div>
			<div class="mui-card-content">
				<div class="mui-input-row">
					<textarea v-model="subForm.approvalExplain" rows="5" placeholder="请输入"></textarea>
				</div>
			</div>
			<div class="vongi-btn">
				<button class="mui-btn mui-btn-primary" @click="doAction">提交</button>
			</div>
		</div>

		<loading :visible="isLoading"></loading>
	</div>
</template>

<script>
	import * as API_Leave from '@/apis/Master/leave'
	import Common from '$project/components/Common.vue'
	import Loading from '$project/components/Loading.vue'
	import TopHeader from '$project/components/TopHeader.vue'
	import isReachBottom from '$project/utils/isReachBottom'
	import {
		mapGetters,
		mapMutations
	} from 'vuex'
	export default {
		name: 'MasterAttendanceLeaveInfo',
		components: {
			Common,
			Loading,
			TopHeader
		},
		data() {
			return {
				pageTitle: '请假详情',

				isLoading: false,
				id: this.$route.query.id,
				detail: {},
				status: ['待审核', '已批准', '已拒绝'],
				statusColor: ['', 'mui-btn-success', 'mui-btn-danger'],

				selectIndex: [],
				//审批内容弹窗显示
				openFromVisible: false,
				subForm: {
					id: 0,
					status: 0,
					approvalExplain: '', //说明
				},
			}
		},
		created() {

		},
		methods: {
			//info
			getDetail() {
				this.isLoading = true;
				API_Leave.detail({
					id: this.id
				}).then(response => {
					this.detail = response;
					this.isLoading = false;
				}).catch(error => {
					this.isLoading = false;
					mui.toast(error);
				})
			},

			//显示内容表单
			openFrom(status, val) {
				this.selectIndex = [this.id];
				if (!this.selectIndex.length) {
					mui.toast('请选择要处理的信息');
				} else {
					this.subForm.status = status;
					this.subForm.approvalExplain = val;
					this.openFromVisible = true;
				}
			},
			//同意拒绝
			doAction() {
				console.log(this.selectIndex)
				if (this.checkForm()) {
					this.isLoading = true;
					this.subForm.id = this.selectIndex.toString();
					API_Leave.approved(this.subForm).then(response => {
						this.isLoading = false;

						this.openFromVisible = false;
						this.getDetail();
					}).catch(error => {
						this.isLoading = false;
						mui.toast(error);
					})
				}
			},
			//检测表单
			checkForm() {
				if (!this.subForm.approvalExplain) {
					mui.toast('请填写审核意见');
					return false;
				} else {
					return true;
				}
			},

			asynCallBack() {

			},
		},
		mounted() {
			this.getDetail();

		},
		destroyed() {},
		computed: {
			picList: {
				// getter
				get: function() {
					if (this.detail && this.detail.imageUrl) {
						return this.detail.imageUrl.split(',');
					} else {
						return [];
					}
				},
				// setter
				set: function(newValue) {
					console.log(newValue)
				}
			},
			...mapGetters({
				openId: 'wx_openid',
				token: 'token',
			})
		},

	}
</script>

<style scoped src="$project/assets/css/xpwyfyy.css"></style>
<style>
</style>
