<template>
	<view class="page_body">
		<!-- 头部 -->
		<nav-bar height="96" :title="state.pageTitle" :onlyTitle="true" :showHeaderborder="true" @GoBack="GoBack"></nav-bar>
		<view :class="['page_content',{'no_show_ft':state.pageFoot=='0'}]">
			<view class="row_item">
				<view class="row_label">荣誉类型：</view>
				<view class="row_value">{{state.reviewDetail?.honorTypeName}}</view>
			</view>
			<view class="row_item" v-for="item in (state.reviewDetail?.honorDataList || [])" :key="item.id">
				<view class="row_label">{{item?.honorDictLibName ?? ''}}：</view>
				<view class="row_value">{{item?.honorDictLibValue ?? ''}}</view>
			</view>
			<view class="row_item">
				<view class="row_label">荣誉证书：</view>
				<view class="row_value img_list">
					<!-- <view class="img_item" v-for="item in (state.reviewDetail?.honorDataCertList || [])" :key="item.id">
						<image class="pic" mode="aspectFit" :src="item.picUrl"></image>
					</view> -->
					<uv-upload :maxCount="state.reviewDetail?.honorDataCertList?.length || 0" :deletable="false" :fileList="state.reviewDetail?.honorDataCertList" width="240rpx" height="140rpx" multiple :previewFullImage="true">
					</uv-upload>
				</view>
			</view>
			<view class="row_item">
				<view class="row_label">佐证材料：</view>
				<view class="row_value document_list">
					<view class="document_item" v-for="item in (state.reviewDetail?.supportDocumentList || [])" :key="item.id">
						<image class="file" src="@/static/image/icon/file.png"></image>
						<view class="file_name">
							<view class="name">{{item.documentName}}</view>
							<view class="file_size_date">
								<view class="file_size">{{item.fileSize}}</view>
								<view class="file_date">{{item.createdAt}}</view>
							</view>
						</view>
						<view class="preview_btn">预览</view>
					</view>
				</view>
			</view>
		</view>
		<view class="page_foot" v-if="state.pageFoot=='1'">
			<button v-if="state.reviewDetail?.honorStatus != 2" class="btn btn_reject" type="primary" plain="true" :loading="state.loading" @click="HandleRejectHonor">驳回</button>
			<button v-if="state.reviewDetail?.honorStatus != 1" class="btn btn_pass" type="primary" :loading="state.loading" @click="HandlePassHonor">通过</button>
		</view>
		<customPopupDialog ref="popupDelDialogRef" title="驳回" dialogWidth="702" :isMaskClick="false" :showDialogClose="false" @DialogConfirm="DialogConfirm">
			<view class="dialog_content_input">
				<view class="dialog_desc">请填写驳回原因方便教师修改</view>
				<uni-easyinput type="textarea" v-model="state.rejectReason" :style="state.easyinputStyle" placeholderStyle="font-weight: 400;font-size: 28rpx;color: #999999;" placeholder="请输入驳回原因…"></uni-easyinput>
			</view>
		</customPopupDialog>
	</view>
</template>

<script setup>
	import navBar from '@/components/navBar.vue';
	import uvUpload from '@/uni_modules/uv-upload/components/uv-upload/uv-upload.vue';
	import customPopupDialog from '@/components/customPopupDialog.vue';
	import uniEasyinput from '@/uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue';
	import {queryReviewDetail,audioHonorData} from '@/reqApi/teacherHonor.js';
	import {
		reactive,
		ref,
		nextTick
	} from 'vue';
	import { onLoad } from '@dcloudio/uni-app';
	const state = reactive({
		id:'',//id
		pageTitle:'',
		pageFoot:'0',
		loading:false,
		reviewDetail:{},
		rejectReason:'',//驳回原因
		easyinputStyle:{
			color: '#303133',
			borderColor: '#E9E9E9'
		}
	})
	const popupDelDialogRef = ref(null);
	onLoad((option) => {
		state.id = option.id;
		state.pageTitle = option.pageTitle;
		state.pageFoot = option.pageFoot;//是否显示页脚
		uni.setStorageSync('isLoadHonorAuditList', false);
		GetReviewDetail();
	})
	//查询荣誉审核资质信息详情数据接口
	const GetReviewDetail = () => {
		queryReviewDetail(state.id).then(res=>{
			if(res.code == 200){
				const resdata = res.data || null;
				const honorDataCertList = resdata?.honorDataCertList || [];
				resdata.honorDataCertList = honorDataCertList.map(item=>({
					...item,
					url:item.picUrl
				}))
				state.reviewDetail = resdata;
			}
		})
	}
	//通过
	const HandlePassHonor = () => {
		HandleRejectOrPass(1)
	}
	//驳回
	const HandleRejectHonor = () => {
		popupDelDialogRef.value.OpenDialog();
	}
	//驳回 确定按钮
	const DialogConfirm = () => {
		if(state.rejectReason == '' || state.rejectReason == null){
			uni.showToast({
				title: '请填写驳回原因！',
				icon: 'none'
			})
			return false
		}
		HandleRejectOrPass(2)
	}
	const HandleRejectOrPass = (status) => {
		const params = {
			honorDataId: state.id,
			honorStatus: status
		}
		if(status == 2){
			params.content = state.rejectReason;
		}
		audioHonorData(params).then(res=>{
			if(res.code == 200){
				uni.showToast({
					title: status == 2?'驳回成功！':'审核通过！',
					icon: 'none'
				})
				uni.setStorageSync('isLoadHonorAuditList', true);//刷新荣誉审核列表
				GoBack();
			}
		})
	}
	const GoBack = () => {
		uni.navigateBack({
			delta: 1
		});
	}
</script>

<style lang="scss" scoped>
	.page_body{
		height: 100%;
		min-height: auto;
	}
	.page_content{
		height: calc(100% - 290rpx);
		&.no_show_ft{
			height: calc(100% - 96rpx);
		}
		flex-direction: column;
		flex-wrap: initial;
		overflow: auto;
		.row_item{
			display: flex;
			width: 100%;
			padding: 32rpx 0;
			border-bottom: 2rpx solid #F3F3F3;
			.row_label{
				font-weight: 400;
				font-size: 28rpx;
				color: #666666;
				flex-shrink: 0;
				margin-right: 10rpx;
			}
			.row_value{
				flex: 1;
				font-weight: 400;
				font-size: 28rpx;
				color: #333333;
				text-align: right;
				display: flex;
				justify-content: flex-end;
				word-break: break-all;
				flex-wrap: wrap;
				&.img_list{
					// gap: 32rpx 24rpx;
					// .img_item{
					// 	width: 240rpx;
					// 	height: 140rpx;
					// 	background-color: #FFFFFF;
					// 	border-radius: 12rpx;
					// 	border: 2rpx solid #CED1D8;
					// 	display: inline-flex;
					// 	align-items: center;
					// 	justify-content: center;
					// 	.pic{
					// 		width: 240rpx;
					// 		height: 140rpx;
					// 	}
					// }
					:deep(.uv-upload__wrap){
						gap: 24rpx 32rpx;
						.uv-upload__wrap__preview{
							background-color: #FFFFFF;
							border-radius: 20rpx;
							border: 2rpx solid #CED1D8;
							box-sizing: border-box;
							margin: 0;
							.uv-upload__deletable{
								top:10rpx;
								right: 10rpx;
								background-color: transparent;
								height: 32rpx;
								width: 32rpx;
								border: 2rpx solid #999999;
								border-radius: 50%;
								.uvicon-close{
									color:#999999 !important;
									font-size: 11rpx !important;
								}
							}
							.uv-upload__deletable__icon{
								transform: scale(1);
								top:50%;
								right: 50%;
								transform: translate(50%, -50%);
							}
							.uv-upload__success{
								border-width: 20rpx;
							}
						}
					}
				}
				&.document_list{
					gap: 24rpx;
					.document_item{
						width: 100%;
						padding: 20rpx 0 18rpx 15rpx;
						display: flex;
						background-color: #FFFFFF;
						border-radius: 20rpx;
						border: 2rpx solid #EBEEF5;
						.file{
							width: 80rpx;
							height: 80rpx;
							margin-right: 16rpx;
						}
						.file_name{
							flex: 1;
							display: flex;
							flex-direction: column;
							.name{
								font-weight: 500;
								font-size: 28rpx;
								text-align: left;
								color: #333333;
							}
							.file_size_date{
								display: flex;
								width: 100%;
								text-align: left;
								font-weight: 400;
								font-size: 24rpx;
								color: #999999;
								margin-top: 8rpx;
								gap: 20rpx;
								.file_size{
									white-space: nowrap;
								}
								.file_date{
									white-space: nowrap;
								}
							}
						}
						.preview_btn{
							width: 96rpx;
							box-sizing: border-box;
							text-align: left;
							font-weight: 400;
							font-size: 28rpx;
							color: #2E64FA;
							padding:20rpx 0 0 16rpx;
						}
					}
				}
			}
		}
	}
	.page_foot{
		position: fixed;
		left:0;
		right: 0;
		bottom: 0;
		padding: 40rpx 24rpx 38rpx 24rpx;
		box-shadow: inset 0px 2rpx 0px 0px #F3F3F3;
		background-color:#FFFFFF;
		gap: 30rpx;
		display: flex;
		.btn{
			height: 90rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			border-radius: 8rpx;
			font-weight: 500;
			font-size: 28rpx;
			flex: 1;
			box-sizing: border-box;
		}
		.btn_reject{
			border: 2rpx solid #F56C6C;
			color: #F56C6C;
		}
		.btn_pass{
			background-color: #2E64FA !important;
			color: #FFFFFF;
		}
	}
	.dialog_content_input{
		width: 100%;
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		.dialog_desc{
			font-weight: 400;
			font-size: 32rpx;
			color: #303133;
		}
		:deep(.uni-easyinput){
			margin-top: 20rpx;
			font-size: 28rpx;
			.is-input-border{
				border-radius: 8rpx;
				border-color: #E9E9E9 !important;
			}
			.uni-easyinput__content-textarea{
				height: 400rpx;
				min-height: 400rpx;
				font-size: 28rpx;
				margin:20rpx 24rpx 20rpx 14rpx;
			}
			.input-padding{
				padding-left: 10rpx;
			}
		}
	}
</style>