<template>
	<view class="hzIndex">
		<hzHeader title="门禁卡审批详情"></hzHeader>
		<view class="hzContent" style="padding-top: 200upx;">
		<view class="details">
			<view class="detail_msg">
				<view class="info-item">
					<text class="label">办卡类型： </text>
					<text class="infoSpan">{{item.TYPE_NAME}}</text>
				</view> 
				<view class="info-item">
					<text class="label">门卡类型： </text>
					<text class="infoSpan">{{item.CARD_TYPE}}</text>
				</view> 
				<view class="info-item" v-if="item.TYPE==1 || item.TYPE==3">
					<text class="label">人员部门： </text>
					<text class="infoSpan">{{item.UNIT}}</text>
				</view> 
				<view class="info-item" v-if="item.TYPE==2">
					<text class="label">单位： </text>
					<text class="infoSpan">{{item.UNIT}}</text>
				</view> 
				<view class="info-item">
					<text class="label">人员姓名： </text>
					<text class="infoSpan">{{item.PERSONNEL}}</text>
				</view>
				<view class="info-item">
					<text class="label">联系电话： </text>
					<text class="infoSpan">{{item.PERSONNEL_PHONE}}</text>
				</view>
				<view v-if="item.TYPE!='2'">
					<view class="info-item">
						<text class="label">出入区域： </text>
						<uni-table ref="table" border emptyText="" style="margin-top: 30upx;">
								<uni-tr></uni-tr>
								<uni-tr v-for="(item, index) in accessArea" :key="index">
									<uni-td align="center" width="80">{{ item.address }}</uni-td>
									<uni-td align="center">{{ item.area }}</uni-td>
								</uni-tr>
						</uni-table>
					</view>
					
				</view>
				<view v-if="item.TYPE=='2'">
					<view class="info-item">
						<text class="label">出入区域： </text>
						<uni-table ref="table" border emptyText="暂无更多数据" style="margin-top: 30upx;">
								<uni-tr></uni-tr>
								<uni-tr v-for="(item, index) in accessArea" :key="index">
									<uni-td align="center" width="80">{{ item }}</uni-td>
								</uni-tr>
						</uni-table>
					</view>
				</view>
				<view class="info-item" v-if="item.PHOTO">
					<text class="label">登记照片： </text>
					<br/>
					<image class="info-item" v-for="(item, index) in photos" :key="index" :src="item" :width="100" style="margin-right: 5px;"></image>
				</view>
				<view class="info-item" v-if="item.ID_PHOTO!='null'">
					<text class="label">身份证图片： </text>
					<br/>
					<image class="info-item" v-for="(item, index) in idPhotos" :key="index" :src="item" :width="100" style="margin-right: 5px;"></image>
				</view>
				<view class="info-item" v-if="item.DOCUMENTATION!='null'">
					<text class="label">证明文件： </text>
					<br/>
					<image class="info-item" v-for="(item, index) in documentPhotos" :key="index" :src="item" :width="100" style="margin-right: 5px;"></image>
				</view>
				
				<view class="info-item" v-if="item.TYPE==2">
					<text class="label">日期限制： </text>	
					<text class="infoSpan">{{item.START_TIME}} - {{item.END_TIME}}</text>
				</view>
				
				<view class="info-item">
					<text class="label">申请人： </text>
					<text class="infoSpan">{{item.USER_NAME}}</text>
				</view>
				<view class="info-item">
					<text class="label">申请时间： </text>	
					<text class="infoSpan">{{item.APPLY_TIME}}</text>
				</view>
				<view class="info-item" v-if="item.TYPE==2">
					<text class="label">申请事由： </text>
					<text class="infoSpan">{{item.MATTER}}</text>
				</view>
				<!-- <view class="info-item">
					<view style="color: #333;font-size: 30upx;font-weight: bold;padding: 10upx 0px;">
						<text>部门审批意见：</text>
					</view>
					<view style="width: 100%;border: 1px solid #E5E5E5;margin-top: 20upx;padding: 20upx;height: 250upx;color: #666;border-radius: 10upx;">
						<textarea class="textarea"  v-model="item.FEEDBACK"  placeholder="请输入审批意见" disabled="true"  maxlength="150"/>
					</view>
				</view> -->
				
			<!-- 	<view class="info-item">
					<view style="color: #333;font-size: 30upx;font-weight: bold;padding: 10upx 0px;">
						<text>物业审批意见：</text>
					</view>
					<view style="width: 100%;border: 1px solid #E5E5E5;margin-top: 20upx;padding: 20upx;height: 250upx;color: #666;border-radius: 10upx;">
						<textarea class="textarea"  v-model="item.FEEDBACK"  placeholder="请输入审批意见" disabled="true"  maxlength="150"/>
					</view>
				</view> -->
				
				<view class="img-box" >
					<image v-for="(itemImg,imgIndex) in item.pictures" :key="imgIndex" :src="formatImgUrl(itemImg)" mode="" @click="vbPicture(new Array(formatImgUrl(itemImg)))"></image>
				</view>
			</view> 
		</view>
		
		
		<view >
			<view class="details">
				<YSteps :lineNum='lineNum' color='#fff' backgroundColor='#4db4ea' :infoList='process'></YSteps>
			</view>
		</view>
		<view  class="occupied" style="height: 180upx;"></view>
		<view v-if="queryType==1 && examineButton && (item.EXAMINE_BATCH==1||item.EXAMINE_BATCH==2)" style="position: fixed;bottom:0upx;height: 50upx;width: 100%;z-index: 9999;">
			<view>
				<view class="footer-btn footer-btn-two batchBtn" >
					<view  class="btn btn-col btn1" @click="circulation()">拒绝</view>
					<view  class="btn btn-col1 btn2" @click="submit(1)">通过</view>
				</view>
			</view>
		</view>
		<view class="footer-btn" v-if="queryType==1 && examineButton && item.EXAMINE_BATCH==3" @click="submit(1)">
			<view class="btn">制卡完成</view>
		</view>
		
		<uni-popup ref="popup" @change="show(arguments)" type="center" style="">
			<view style="background: white;width: 80%;height: 540upx;width: 600upx;position: relative;border-radius: 10upx;padding: 14upx;">
				<view style="color: #333;font-size: 30upx;font-weight: bold;padding: 10upx 0px;">
					<text>拒绝原因：</text>
				</view>
				<view style="width: 100%;border: 1px solid #E5E5E5;margin-top: 20upx;padding: 20upx;height: 300upx;color: #666;border-radius: 10upx;">
					<textarea style="width: 100%;height: 100%;" v-model="replyContent"  placeholder="请输入拒绝原因"/>
				</view>
				<view class="footer-btn footer-btn-two" style="position: absolute;margin-bottom: 20upx;">
					<view class="btn btn-col" style="width:40%;margin-left:7%;margin-right: 6%;border-radius: 10upx;" @click="closeCirculation()">取消</view>
					<view class="btn btn-col1" style="width:40%;border-radius: 10upx" @click="submit(2)">确定</view>
				</view>
			</view>
		</uni-popup>
		
		</view>
	</view>
</template>

<script>
	import {
		getCard,updateCard
	} from '@/common/api.js';
	import YSteps from '@/components/Y-Steps/Y-Steps.vue';
	import UniPopup from "@/components/uni-popup/uni-popup.vue";
	import {
		callbackRequest,
		getStorage,
		alertTip,
		formatDate,
		sureAlterTip,
		vbPicture,
		formatImgUrl
	} from '@/common/util.js';
	export default {
		components: {
			UniPopup,
			YSteps
		},
		data() {
			return {
				vbPicture:vbPicture,
				formatImgUrl:formatImgUrl,
				userInfo:getStorage('userInfo'),
				userId:getStorage('userInfo').userId,
				formatDate:formatDate,
				item: {},
				id:0,
				feedback:'',
				submitFlag:true,
				queryType:0,
				replyContent:'',
				examineButton:true,
				process: [],
				lineNum:0,
				photo: '',
				photos: [],
				idPhoto: '',
				idPhotos: [],
				documentPhoto: '',
				documentPhotos: [],
				accessArea:[]
			}
		},
		onLoad(option) {
			this.item = JSON.parse(option.item);
			this.id = this.item.ID;
			this.queryType = option.queryType||0;
			this.examineBatch = option.examineBatch || 1;
			this.getCard();
			
		},
		methods: {
			getCard(){
				let params =  {
						method: getCard,
						data: {
							userId:this.userId,
							id:this.id
						}
					};
				callbackRequest(params).then(res => {
					res = res.data;
					if (res.returnCode == 1) {
						let _this = this;
						_this.item = res.returnData[0];
						if(_this.item.PHOTO){
							_this.photos = _this.item.PHOTO.split(',');
						}
						if(_this.item.ID_PHOTO&&_this.item.ID_PHOTO!='null'){
							_this.idPhotos = _this.item.ID_PHOTO.split(',');
						}
						if(_this.item.DOCUMENTATION){
							_this.documentPhotos = _this.item.DOCUMENTATION.split(',');
						}
						if(_this.item.ACCESS_AREA){
							if(this.item.TYPE=='2'){
								_this.accessArea = _this.item.ACCESS_AREA.split(',')
							}else{
								_this.accessArea = JSON.parse(_this.item.ACCESS_AREA)
							}
						}
						let details = res.returnData[0].detail||[]
						for(let i=0;i<details.length;i++){
							let obj = details[i];
							if(_this.examineBatch == obj.EXAMINE_BATCH){
								setTimeout(()=>{_this.examineButton = false;},400)
								// _this.examineButton = false;
							}
						}
						_this.process=[];
						if(_this.process.length==0){
							let pObj0 = {
								date: '经办人',
								info: _this.item.USER_NAME+' 发起申请',
								time: formatDate( _this.item.APPLY_TIME,'dateTime')
							}
							_this.process.push(pObj0);
						}
						if(details.length>0){
							for(let i=0;i<details.length;i++){
								let pObj = {
									date: details[i].BATCH_DESCRIPTION,
									info: details[i].USER_NAME+"　"+(details[i].EXAMINE_STATE==1?"同意":"拒绝　"+(details[i].EXAMINE_OPINION||'')),
									time: formatDate(details[i].EXAMINE_TIME,'dateTime')
								}
								if(details[i].EXAMINE_BATCH=='3'){
									pObj = {
										date: details[i].BATCH_DESCRIPTION,
										info: details[i].USER_NAME+"　"+(details[i].EXAMINE_STATE==1?"制作完成":"拒绝　"+(details[i].EXAMINE_OPINION||'')),
										time: formatDate(details[i].EXAMINE_TIME,'dateTime')
									}
								}
								_this.process.push(pObj);
							}
						}
					} else {
						alertTip(res.returnMsg);
					}
				});
			},
			circulation(){
				this.$refs.popup.open();
				
			},
			show(val){
				this.examineButton = !val[0].show;
				// console.log(this.examineButton)
			},
			closeCirculation(){
				this.$refs.popup.close()
				// this.examineButton = true;
			},
			submit(examineState){
				//examineState  1通过，2不通过
				let params = {
					"method": updateCard,
					"data":{
						id: this.item.ID,
						userId:getStorage('userInfo').id,
						userName:getStorage('userInfo').userName,
						examineState:examineState+'',
						examineOpinion:this.replyContent,
						examineBatch:this.examineBatch+''
					}
				};
				callbackRequest(params).then(res => {
					res = res.data;
					if (res.returnCode == 1) {
						alertTip(res.returnMsg);
						this.closeCirculation();
						this.getCard();
						// uni.navigateBack({
						//     delta: 1
						// });
					} else {
						alertTip(res.returnMsg);
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	@import '@/static/css/common.scss';
	.batchBtn{
		position: absolute;
		display: flex;
		justify-content: space-between;
		padding: 10upx 40upx;
		.btn1{
			background: #C1EFEA;
			color: #09AFA5;
			width: 40%;
			border-radius: 50upx;
		}
		.btn2{
			background: linear-gradient( 90deg, #50CBA1 0%, #06AEA6 100%), #C1EFEA;
			color: #fff;
			width: 40%;
			border-radius: 50upx;
		}
	}
 
	.details{
		// height: 550upx;
		background: white;
		margin: 20upx;
		border-radius: 15upx;
		padding-bottom:15rpx;
		position: relative;
		font-size: 26upx;
		.detail_header {
			border-bottom: #f8f8f8 5upx solid;
			height: 90upx;
			line-height: 90upx;
			margin: 15upx;
			border-radius: 10upx;
			.blueSign {
				height: 28upx;
				width: 5upx;
				background: #00c277;
				display: inline-block;
				margin-left: 20upx;
			}
			.font-tilte {
				font-weight:bold;
				margin-left: 20upx;
			}
		}
		.form-box {
			background: #fff;
			.form-item {
				overflow: hidden;
				border-bottom: 1px solid #eee;
				padding: 30upx 20upx;
				.label {
					float: left;
					width: 180upx;
					font-size: 28upx;
					color: #333;
					font-weight: bold;
					line-height: 50upx;
				}
				.ipt-box {
					margin-left: 160upx;
					input {
						width: 90%;
						height: 50upx;
						line-height: 50upx;
						font-size: 26upx;
						color: #666;
					}
				}
				.select {
					.arrow {
						float: right;
						width: 16upx;
						height: 29upx;
						margin-top: 10upx;
					}
					.picker {
						height: 50upx;
						line-height: 50upx;
						font-size: 26upx;
						color: #666;
						margin-left: 10upx;
					}
				}
			}
		}
		.detail_msg {
			margin-left: 20upx;
			border-radius: 10upx;
			.info-item{
				border-bottom:1px solid #f8f8f8;
				padding:20upx 10upx;
				line-height: 50upx;
				.label{
					float: left;
					width: 180upx;
					font-size: 28upx;
					color: #333;
					font-weight: bold;
					line-height: 50upx;
				}
			}
			.status {
				.infoSpan{
					color: #00c277;
				}
				.infoSpan2{
					color: red;
				}
			}
			.img-box {
				// background: #fff;
				image{
					width: 200upx;
					height: 200upx;
					margin:20upx 20upx 0 0;
				}
			}
		}
	}

</style>
