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

		<div class="mui-content vongi-wordcard">
			<div class="mui-content-padded vongi-wordcard-top">
				<div class="mui-media-object mui-pull-left">
					<img :src="detail.faceImageUrl" v-viewer>
				</div>
				<div class="mui-media-body">
					{{detail.personName}}
					<p class='mui-ellipsis'><span class="colorfe616c">{{detail.typeN}}</span>申请</p>
				</div>
				<!--补卡-->
				<button v-if="detail.type=='2'" 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>
				<!--外勤打卡-->
				<button v-if="detail.type=='1'" type="button" :class="'mui-btn mui-btn-success mui-btn-outlined '+(detail.remark?'status_a':'status_r')">
					{{detail.remark?'已审查':'未审查'}}
				</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-top">
                <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 class="mui-content-padded vongi-wordcard-center">
				<h5>审批意见</h5>
				<ul class="mui-table-view">
					<li class="mui-table-view-cell mui-media">
						审批人:
						<span v-text="detail.approvalPersonName"></span>
					</li>
					<li class="mui-table-view-cell mui-media">
						审批编号：
						<span v-text="detail.approvalNo"></span>
					</li>
					<li class="mui-table-view-cell mui-media">
						<span class="colorf8b155" v-text="detail.approvalContent"></span>
					</li>
				</ul>
			</div>
			-->
			
			<div v-if="detail.status && detail.status=='2' && detail.personId==person_data.id" class="fyy-scon-botton">
				<div class="examine-btn examine-btn1-blue" @click="resetApply">重新申请</div>
			</div>

			<div v-if="can_remark" class="fyy-scon-botton">
				<div class="examine-btn examine-btn1-blue" @click="openFromVisible=true">填写意见</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="remarkForm.remark" rows="3" placeholder="请输入"></textarea>
				</div>
			</div>
			<div class="mui-popup-buttons"><span class="mui-popup-button mui-popup-button-bold" @click="addRemark">提交</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: 'MasterAttendanceInfo',
		components: {
			Common,
			Loading,
			TopHeader
		},
		data() {
			return {
				pageTitle: '打卡详情',

				isLoading: false,

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

				can_remark: this.$route.query.remark,
				remarkForm: {
					id: this.$route.query.id,
					remark: ''
				},
				openFromVisible: false
			}
		},
		created() {

		},
		methods: {
			//重新申请
			resetApply(){
				this.$router.push({
					name: 'MasterAttendanceApply',
					query: {
						id: this.$route.query.applyId
					}
				})
			},
            //获取状态颜色
            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(this.subForm).then(response => {

					this.detail = response;

					this.remarkForm.remark = response.remark;

					this.isLoading = false;
				}).catch(error => {
					this.isLoading = false;
					mui.toast(error);
				})
			},
			//领导添加备注
			addRemark() {
				if (!this.remarkForm.remark) {
					mui.toast('请填写意见');
				} else {
					this.isLoading = true;
					API_Attendance.addRemark(this.remarkForm).then(response => {
						this.isLoading = false;

						this.openFromVisible = false;
						mui.toast('提交成功');
						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',
				person_data: 'person_data',
			})
		}
	}
</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;
	}

	.examine-btn1-blue {
		background-color: #3385FF;
	}
</style>
