<template>
	<view class="content">
		<!-- 申请类型 -->
		<view class="request_type">
			<text class="type_title" v-if="department=='4'">临时人员</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">{{list.orgName}}
						<!-- <template v-if="list.orgName=='0'">其他</template>
						<template v-if="list.orgName=='1'">学生</template>
						<template v-if="list.orgName=='4'">教职工</template>
						<template v-if="list.orgName=='5'">校友</template>
						<template v-if="list.orgName=='6'">访客</template>
						<template v-if="list.orgName=='7'">临时人员</template> -->
					</view>
				</uni-forms-item>
				<view class="form-line"></view>
				<uni-forms-item label="提交人" name="companyName" required>
					<view class="uni-input">
						{{list.usersName}}
					</view>
				</uni-forms-item>
				<view class="form-line"></view>
				<uni-forms-item label="房间数量" name="companyName" required>
					<view class="uni-input">
						{{list.houseCount}}
					</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_remark" style="height: 100%;">
			<view class="submit-start" style="color: rgba(0, 0, 0, 1);">附件：</view>
			<view class="submit-start" style="color: rgba(0, 0, 0, 1);">
				<!-- {{item.imageUrl!=null&&item.imageUrl!=''}}3{{(item.imageUrl).split(',')}} -->
				<text v-if="list.imageUrl!=null&&list.imageUrl!=''">
					<image @click.stop="clickImg2(item2)" style="color: rgba(0, 97, 255, 1);width: 200rpx;height: 200rpx;margin-left: 20rpx;" :src="item2" v-for="(item2,index2) in (list.imageUrl).split(',')" :key="index2">
					</image>
				</text>
			</view>
		</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="">{{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: {
			//点击放大图片
			clickImg2(item2) {
				// console.log(item.srcUrl)
				uni.previewImage({
					urls: [item2], //需要预览的图片http链接列表，多张的时候，url直接写在后面就行了
					current: '', // 当前显示图片的http链接，默认是第一个
					success: function(res) {},
					fail: function(res) {},
					complete: function(res) {},
				})
			},
			//输入审批意见
			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) {
						_self.list=res.data
						_self.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('adminMenuId'),//
					"status": _self.agreestatu, //审批状态   1：同意 0：拒绝
					"adminId": localStorage.getItem('adminId'),//管理端id
					"remark": _self.option ,//审批备注
				}
				shenpiLinshi(data).then((res) => {
					if (res.success) {
						uni.showToast({
							title: '审批成功',
							icon: 'success',
							duration: 1500
						})
						setTimeout(function(){
							_self.getXiang()
						},1500);
					} else {
						uni.showToast({
							title: res.message,
							duration: 1500
						})
					}
				}).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('adminMenuId'),//1管理员，0不是管理员
					"status": _self.agreestatu, //审批状态   1：同意 0：拒绝
					"adminId": localStorage.getItem('adminId'),//管理端id
					"remark": _self.option ,//审批备注
				}
				shenpiTeacher(data).then((res) => {
					if (res.success) {
						uni.showToast({
							title: '审批成功',
							icon: 'success',
							duration: 1500
						})
						setTimeout(function(){
							_self.getXiang()
						},1500);
					} else {
						uni.showToast({
							title: res.message,
							duration: 1500
						})
					}
				}).catch((err) => {
					uni.showToast({
						title: err.message
					})
				});
			},
		}
	}
</script>

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