<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">
				</div>
				<div class="mui-media-body">
					{{detail.personName}}
					<p class='mui-ellipsis'><span class="color4fc5f7">加班</span>申请</p>
				</div>
				<button :style="getColor(detail.status)" v-text="detail.statusN" type="button" class="mui-btn mui-btn-primary mui-btn-outlined">
					
				</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.workOverTime"></span>
					</li>
					<li class="mui-table-view-cell mui-media">
						<div class="mui-media-body">加班时长</div>
						<span>{{detail.hours}}小时</span>
					</li>
					<li class="mui-table-view-cell mui-media">
						<div class="mui-media-body">加班原因</div>
						<span v-text="detail.reason"></span>
					</li>
					<li class="mui-table-view-cell mui-media">
						<div class="mui-media-body">申请时间</div>
						<span v-text="detail.dateTime"></span>
					</li>
				</ul>
			</div>

			<div class="vongi-slot mui-content-padded">
				<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>
					</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>

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

<script>
	import * as API_BusinessTravel from '@/apis/Master/business_travel'
	import * as API_ExtraWork from '@/apis/Master/extra_work'
	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: 'MasterExtraWorkVerifyInfo',
		components: {
			Common,
			Loading,
			TopHeader,
		},
		data() {
			return {
				pageTitle: '加班审批详情',

				isLoading: false,

				approvalPersonName: '',
				approvalPersonUrl: '',

				subForm: {
					ids: this.$route.query.id,
					status: '',
					approvalContent: '',
					nextApprovalId: '',
				},
				approvalPersonList: [],
				//补卡/加班1，外出2，出差3 ，请假4
				personForm: {
					type: '4'
				},
				approvalPerson: true,
				detail: {
					list: [],
				},
			}
		},
		created() {},
		methods: {
			//获取审核人列表
			getBusinessOutApprovalPerson() {
				this.isLoading = true;
				API_BusinessTravel.getBusinessOutApprovalPerson(this.personForm).then(response => {
					this.isLoading = false;

					var list = response.data;
					var approvalPersonList = [];
					for (var i = 0; i < list.length; i++) {
						approvalPersonList.push({
							value: list[i]['id'],
							text: list[i]['personName'],
							url: list[i]['faceImageUrl']


						})
					}
					if (approvalPersonList.length) {

						this.subForm.nextApprovalId = approvalPersonList[0]['value'];
						this.approvalPersonName = approvalPersonList[0]['text'];
						this.approvalPersonUrl = approvalPersonList[0]['url'];
					}
					this.approvalPersonList = approvalPersonList;

					this.approvalPerson = true;
				}).catch(error => {
					this.isLoading = false;
					mui.toast(error);
				})
			},
			//选择审核人
			selectPerson() {

				var _this = this;
				var picker = new mui.PopPicker();
				picker.setData(_this.approvalPersonList);
				picker.pickers[0].setSelectedValue(this.subForm.nextApprovalId);
				picker.show(function(selectItems) {
					_this.subForm.nextApprovalId = selectItems[0].value;
					_this.approvalPersonName = selectItems[0].text;
					_this.approvalPersonUrl = selectItems[0].url;

					picker.dispose();
				})
			},
			//获取详情
			getInfo() {
				this.isLoading = true;
				API_ExtraWork.workOverDetail(this.subForm.ids).then(response => {
					this.isLoading = false;

					this.detail = response;
				}).catch(error => {
					this.isLoading = false;
					mui.toast(error);
				})
			},
			//获取状态颜色
			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 + ';';
			},
			//显示内容表单
			openFrom(status) {
				if (!this.subForm.ids) {
					mui.toast('请选择要处理的信息');
				} else {
					this.subForm.status = status;
					this.subForm.approvalContent = status == 1 ? '同意' : '拒绝';
					//this.openFromVisible = true;
					//直接点击处理，不需要弹窗理由框
					this.doAction();
				}
			},
			//检测表单
			checkForm() {
				if (!this.approvalPerson) {
					mui.toast('加载下一级审批人失败，请刷新页面');
					return false;
				} else if (!this.subForm.ids) {
					mui.toast('请选择要处理的信息');
					return false;
				} else {
					return true;
				}
			},
			//同意拒绝
			doAction() {
				if (this.checkForm()) {
					this.isLoading = true;
					API_ExtraWork.approvalWorkOver(this.subForm).then(response => {
						this.isLoading = false;

						this.openFromVisible = false;
						this.getInfo();
					}).catch(error => {
						this.isLoading = false;
						mui.toast(error);
					})
				}
			},
			asynCallBack() {
				//获取详情
				this.getInfo();
			},
		},
		mounted() {
			this.isLoading = true;
		},
		destroyed() {},
		computed: {
			...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>
</style>
