<template>
	<view class="content">
		<!-- 申请类型 -->
		<view class="request_type">
			<text class="type_title" v-if="department=='7'">临时人员</text>
			<text class="type_title" v-if="department=='4'">教师换课</text>
			<view class="type_time">{{list.submissionTime}}</view>
			<view class="type_zhuang2" v-if="list.status==0">已拒绝</view>
			<view class="type_zhuang3" v-if="list.status==1">待审批</view>
			<view class="type_zhuang3" v-if="list.status==2">处理中</view>
			<view class="type_zhuang" v-if="list.status==3">审批通过</view>
		</view>
		<!-- 申请内容 -->
		<view class="request_detail">
			<uni-forms ref="valiForm">
				<uni-forms-item label="类型" name="companyName" required>
						<view class="uni-input">
							<template v-if="list.department=='0'">其他</template>
							<template v-if="list.department=='1'">学生</template>
							<template v-if="list.department=='4'">教职工</template>
							<template v-if="list.department=='5'">校友</template>
							<template v-if="list.department=='6'">访客</template>
							<template v-if="list.department=='7'">临时人员</template>
						</view>
				</uni-forms-item>
				<view class="form-line"></view>
				<uni-forms-item label="开始时间" name="companyName" required>
					<view class="uni-input">
						{{list.startTime}}
					</view>
				</uni-forms-item>
				<view class="form-line"></view>
				<uni-forms-item label="结束时间" name="companyName" required>
					<view class="uni-input">
						{{list.endTime}}
					</view>
				</uni-forms-item>
				<view class="form-line"></view>
				<uni-forms-item label="申请部门" name="companyName" required>
					<view class="uni-input">
						<template v-if="list.department=='0'">其他</template>
						<template v-if="list.department=='1'">学生</template>
						<template v-if="list.department=='4'">教职工</template>
						<template v-if="list.department=='5'">校友</template>
						<template v-if="list.department=='6'">访客</template>
						<template v-if="list.department=='7'">临时人员</template>
					</view>
				</uni-forms-item>
				<view class="form-line" v-if="department=='4'"></view>
				<uni-forms-item label="换课老师" name="companyName" required v-if="department=='4'">
					<view class="uni-input">
						{{list.changeUsersName}}
					</view>
				</uni-forms-item>
			</uni-forms>
		</view>
		<!-- 申请备注 -->
		<view class="request_remark">
			<uni-forms-item label="备注" name="companyName" required>
			</uni-forms-item>
			<view class="liyou">{{list.reasonApplication}}</view>
			<text class="textsrea-txt">{{zishunum}}</text>
		</view>
		<!-- 审批记录 -->
		<view class="request_list" v-if="list.status==0 || list.status==3">
			<view class="list_title">审批记录</view>
			<!-- 几级审批 -->
			<view style="position: absolute;margin-top: 110rpx;background: rgba(255, 255, 255, 1);height: 30%;">
			<view>
				<image class="item_image"></image>
				<view class="item_title">提交申请</view>
				<view class="item_name">{{list.usersName}}</view>
				<view class="item_time">{{list.submissionTime}}</view>
				<view class="item_line" v-if="list.approverName || list.secondaryApproverName"></view>
			</view>
			<view v-if="list.secondaryApproverName">
				<image class="item_image"></image>
				<view class="item_title">{{list.secondaryExamineAndApproveRemark}}</view>
				<view class="item_name">{{list.secondaryApproverName}}</view>
				<view class="item_time">{{list.secondaryExamineAndApproveTime}}</view>
				<view class="item_line" v-if="list.approverName"></view>
			</view>
			<view v-if="list.approverName">
				<image class="item_image"></image>
				<view class="item_title">{{list.examineAndApproveRemark}}</view>
				<view class="item_name">{{list.approverName}}</view>
				<view class="item_time">{{list.examineAndApproveTime}}</view>
			</view>
			</view>
		</view>
		<!-- 审批意见 -->
		<view class="option_title" v-if="list.status==1 || list.status==2">审批意见</view>
		<view class="request_list" v-if="list.status==1 || list.status==2">
			<uni-easyinput type="textarea" v-model="option" placeholder="请输入审批意见" @input="input"></uni-easyinput>
			<text class="textsrea-txt" style="margin-left: 337px;">{{textNum}}/800</text>
		</view>
		<view class="submit-disagree" v-if="list.status==1 || list.status==2" @click="disagree()">驳回</view>
		<view class="submit-agree" v-if="list.status==1 || list.status==2" @click="agree()">同意</view>
	</view>
</template>

<script>
	import {
			shenpiLinshi,
			shenpiTeacher,
			getlistXiang
		} from '../../../utils/api_hotel.js'
	export default {
		data() {
			return {
				list:[],
				id:'',
				department:'',//身份
				zishunum:0,
				textNum:0,
				option:'',
				agreestatu:'',
			}
		},
		onLoad(option) {
			this.id=option.id
			this.department=option.department
			this.getXiang()
		},
		mounted() {
		},
		methods: {
			//输入审批意见
			input(e){
				this.option=e
				this.textNum=e.length
			},
			//详情
			getXiang(){
				let _self = this
				// adminMenuId身份类型，4为教职工，7为临时人员localStorage.getItem('department')
				// 状态，0:已拒绝，1:待审批，2:处理中，3:已同意
				var data="?department="+_self.department+"&id="+_self.id
				getlistXiang(data).then((res) => {
					if (res.success) {
						this.list=res.data
						this.zishunum=res.data.reasonApplication.length
						return;
					} else {
						uni.showToast({
							title: '获取记录详情失败'
						})
					}
				}).catch((err) => {
					uni.showToast({
						title: err.message
					})
				});
			},
			//驳回
			disagree(){
				this.agreestatu='0'
				if(this.department=='7'){
					this.shenpiLinshi()
				}else if(this.department=='4'){
					this.shenpiTeacher()
				}
			},
			//同意
			agree(){
				this.agreestatu='1'
				if(this.department=='7'){
					this.shenpiLinshi()
				}else if(this.department=='4'){
					this.shenpiTeacher()
				}
			},
			// 审批临时人员
			shenpiLinshi(){
				let _self = this
				this.$axios.defaults.headers.common['token'] = localStorage.getItem('token');
				this.$axios.defaults.headers.common['request_token'] = this.submitToken;
				this.$axios.defaults.headers.common['Content-Type'] ='application/json'
				var data={
					"id": _self.id, //审批表id
					"adminMenuId": localStorage.getItem('manager'),//1管理员，0不是管理员
					"status": _self.agreestatu, //审批状态   1：同意 0：拒绝
					"adminId": localStorage.getItem('usersId'),//管理端id
					"remark": _self.option ,//审批备注
				}
				shenpiLinshi(data).then((res) => {
					if (res.success) {
						uni.showToast({
							title: '审批成功',
							icon: 'success',
							duration: 1000
						})
						_self.getXiang()
					} else {
					}
				}).catch((err) => {
					uni.showToast({
						title: err.message
					})
				});
			},
			// 审批教师换课
			shenpiTeacher(){
				let _self = this
				this.$axios.defaults.headers.common['token'] = localStorage.getItem('token');
				this.$axios.defaults.headers.common['request_token'] = this.submitToken;
				this.$axios.defaults.headers.common['Content-Type'] ='application/json'
				var data={
					"id": _self.id, //审批表id
					"adminMenuId": localStorage.getItem('manager'),//1管理员，0不是管理员
					"status": _self.agreestatu, //审批状态   1：同意 0：拒绝
					"adminId": localStorage.getItem('usersId'),//管理端id
					"remark": _self.option ,//审批备注
				}
				shenpiTeacher(data).then((res) => {
					if (res.success) {
						uni.showToast({
							title: '审批成功',
							icon: 'success',
							duration: 1000
						})
						_self.getXiang()
					} else {
					}
				}).catch((err) => {
					uni.showToast({
						title: err.message
					})
				});
			},
		}
	}
</script>

<style>
	@import url("./teach_detail.css");
</style>