<template>
	<div>
		<common @asynCallBack="asynCallBack"></common>
		<top-header :pageTitle="(detail.typeN?detail.typeN:'')+pageTitle"></top-header>

		<div class="mui-content vongi-wordcard">
			<div class="mui-content-padded vongi-wordcard-top">
				<div v-show="detail.faceImageUrl" class="mui-media-object mui-pull-left">
					<img :src="detail.faceImageUrl" v-viewer>
				</div>
				<div v-show="detail.personName" class="mui-media-body">
					<font v-text="detail.personName"></font>
					<p class='mui-ellipsis'><span class="colorfe616c" v-text="detail.typeN"></span>申请</p>
				</div>
				<button type="button" :class="'mui-btn mui-btn-success mui-btn-outlined '+(detail.status>0?(detail.status==1?'status_a':'status_r'):'')">
					{{detail.status>0?(detail.status==1?'已同意':'已拒绝'):'未审核'}}
				</button>
			</div>

			<div class="mui-content-padded vongi-wordcard-center">
				<ul class="mui-table-view">
					<li class="mui-table-view-cell mui-media">
						<div class="mui-media-body">申请类型</div>
						<span v-text="detail.typeN"></span>
					</li>
					<li class="mui-table-view-cell mui-media">
						<div class="mui-media-body">所在部门</div>
						<span v-text="detail.companyName"></span>
					</li>
					<li class="mui-table-view-cell mui-media">
						<div class="mui-media-body">申请班次</div>
						<span class="colorf6f448" v-text="detail.fillAttendanceDayAndTime"></span>
					</li>
					<li v-if="detail.address" class="mui-table-view-cell mui-media">
						<div class="mui-media-body">打卡地点</div>
						<span v-text="detail.address"></span>
					</li>
					<li class="mui-table-view-cell mui-media">
						<div class="mui-media-body">申请时间</div>
						<span v-text="detail.createTime"></span>
					</li>
					<li class="mui-table-view-cell mui-media">
						<div class="mui-media-body">申请理由</div>
						<span class="colorf8b155" v-text="detail.content"></span>
					</li>
					<li class="mui-table-view-cell mui-media">
						<div class="mui-media-body">相关照片</div>
					</li>
					<li class="mui-table-view-cell mui-media fyy-upphoto">
						<div class="mui-col-xs-3" v-for="(item,index) in picList">
							<img :src="item" v-viewer />
						</div>
					</li>
				</ul>
			</div>

            <div class="vongi-slot mui-content-padded vongi-wordcard-center">
                <div v-for="(item,index) in detail.list" class="vongi-slot-block">
                    <div class="vongi-slot-img"><img :src="item.faceImageUrl"></div>
                    <div class="vongi-slot-content">
                        <h4>审批人{{index+1}}<span class="mui-pull-right mui-h5 color999" v-text="item.time"></span></h4>
                        <p>{{item.name}} <span class="color55f868" :style="getColor(item.status)" v-text="item.statusN"></span></p>
						<p v-if="item.approvalContent" v-text="item.approvalContent"></p>
					</div>
                </div>
            </div>


            <div v-if="detail.status=='0' && detail.approvalEnable" 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>

		<!-- 审批弹窗 -->
		<div v-show="openFromVisible" class="mui-popup mui-popup-in vongi-mui-pop">
			<div class="mui-popup-inner vongi-pop-inner">
				<div class="mui-popup-title">填写意见</div>
				<div class="mui-popup-input">
					<textarea  v-model="subForm.content" rows="3" placeholder="请输入"></textarea>
				</div>
			</div>
			<div class="mui-popup-buttons"><span class="mui-popup-button mui-popup-button-bold" @click="doAction">提交</span></div>
		</div>
		<div v-show="openFromVisible" @click="openFromVisible=false"  class="mui-popup-backdrop mui-active"></div>

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

<script>
	import * as API_Attendance from '@/apis/Master/attendance'
	import Common from '$project/components/Common.vue'
	import Loading from '$project/components/Loading.vue'
	import TopHeader from '$project/components/TopHeader.vue'
	import {
		mapGetters,
		mapMutations
	} from 'vuex'
	export default {
		name: 'MasterAttendanceVerifyInfo',
		components: {
			Common,
			Loading,
			TopHeader
		},
		data() {
			return {
				pageTitle: '申请详情',

				isLoading: false,

				id: this.$route.query.id,
				detail: {},

				//审批内容弹窗显示
				openFromVisible: false,
				selectIdList: [],
				subForm: {
					ids: '',
					content: '',
					status: ''
				},
			}
		},
		created() {

		},
		methods: {
            //获取状态颜色
            getColor(status) {
                var color = '';
                if (status == '0') {
                    color = '#4fc5f7';
                } else if (status == '1') {
                    color = '#55f868';
                } else if (status == '2') {
                    color = '#fe616c';
                }
                return 'color:' + color + ';border-color:' + color + ';';
            },
			//获取详情
			getDetail() {
				this.isLoading = true;
				API_Attendance.getApplyInfo({
					id: this.id
				}).then(response => {

					this.detail = response;

					this.isLoading = false;
				}).catch(error => {
					this.isLoading = false;
					mui.toast(error);
				})
			},
			//显示内容表单
			openFrom(status) {
				this.selectIdList = [this.id];
				if (!this.selectIdList.length) {
					mui.toast('请选择要处理的信息');
				} else {
					this.subForm.status = status;
					this.subForm.content = status == 1 ? '同意' : '拒绝';
					this.openFromVisible = true;
					//直接点击处理，不需要弹窗理由框,又需要弹窗理由框了
					//this.doAction();
				}
			},
			//检测表单
			checkForm() {
				if (!this.subForm.ids) {
					mui.toast('请选择要处理的信息');
					return false;
				} else {
					return true;
				}
			},
			//同意拒绝
			doAction() {
				this.subForm.ids = this.selectIdList.join(',');
				if (this.checkForm()) {
					this.isLoading = true;
					API_Attendance.doVerify(this.subForm).then(response => {
						this.isLoading = false;

						this.openFromVisible = false;
						this.getDetail();
					}).catch(error => {
						this.isLoading = false;
						mui.toast(error);
					})
				}
			},
			asynCallBack() {

			},
		},
		mounted() {
			//获取详情
			this.getDetail();
		},
		destroyed() {},
		computed: {
			picList: {
				// getter
				get: function() {
					if (this.detail && this.detail.fillAttendanceFilesUrl) {
						return this.detail.fillAttendanceFilesUrl.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 src="$project/assets/css/iconfont.css"></style>
<style scoped>
	.status_r {
		color: #fe616c !important;
		border: 1px solid #fe616c !important;
	}

	.status_a {
		color: #05c8af !important;
		border: 1px solid #05c8af !important;
	}
</style>
