<template>
	<view class="hzIndex">
		<hzHeader title="填报详情"></hzHeader>
		<view class="container hzContent">
			<view class="details">
				<view class="detail_msg">
					<view class="info-item status">
						<text class="label">服务状态</text>
						<text v-if="item.reply_flag =='0'" class="infoSpan" style="color: #FB8107;">未审核</text>
						<text v-if="item.reply_flag =='1'" class="infoSpan" style="color: red;">已拒绝</text>
						<text v-if="item.reply_flag =='2'" class="infoSpan">已通过</text>
					</view>
				</view>
			</view>
			<view class="details">
				<view class="detail_msg">
					<view class="dateTit" style="padding: 24upx 0;">
						<view class="leftIcon">

						</view>
						<text style="font-size:32upx;color:#333;font-weight: 600;">报修信息</text>
					</view>
					<view class="info-item">
						<text class="label" v-if="item.is_inspection==2">维保项目</text>
						<text class="label" v-if="item.is_inspection==3">服务项目</text>
						<text class="infoSpan">{{ item.repair_option_name }}</text>
					</view>
					<view class="info-item">
						<text class="label" v-if="item.is_inspection==2">维保区域</text>
						<text class="label" v-if="item.is_inspection==3">服务区域</text>
						<text class="infoSpan">{{ item.repair_place }}</text>
					</view>
					<view v-if="item.repair_option_sub_name" class="info-item">
						<text class="label" v-if="item.is_inspection==2">维保小项</text>
						<text class="label" v-if="item.is_inspection==3">服务小项</text>
						<text class="infoSpan">{{ item.repair_option_sub_name }}</text>
					</view>
					<view v-if="item.fault_proposal" class="info-item">
						<text class="label">更换配件</text>
						<text class="infoSpan">{{ item.fault_proposal }}</text>
					</view>
					<view v-if="item.elevator_no" class="info-item">
						<text class="label">设备编号</text>
						<text class="infoSpan">{{ item.elevator_no }}</text>
					</view>
					<view v-if="item.repair_floor" class="info-item">
						<text class="label">设备位置</text>
						<text class="infoSpan">{{ item.repair_floor }}</text>
					</view>


					<view class="info-item">
						<text class="label" v-if="item.is_inspection==2">维保类型</text>
						<text class="label" v-if="item.is_inspection==3">服务类型</text>
						<text class="infoSpan">{{ item.wb_types }}</text>
					</view>
					<view class="info-item" v-if="item.wb_types=='维修'">
						<text class="label">到场时间</text>
						<text class="infoSpan">{{ item.arrival_time }}</text>
					</view>
					<!-- <view class="info-item">
					<text class="label">维保位置</text>
					<text class="infoSpan">{{item.repair_place+" "+(item.repair_floor||'')+""+(item.repair_room_no?"-"+item.repair_room_no+'':'')}}</text>
				</view> -->
					<view v-if="item.fault_detail" class="info-item">
						<text class="label" v-if="item.is_inspection==2">维保内容</text>
						<text class="label" v-if="item.is_inspection==3">服务内容</text>
						<text class="infoSpan">{{item.fault_detail}}</text>
					</view>

					<view class="info-item">
						<text class="label" v-if="item.is_inspection==2">维保时间</text>
						<text class="label" v-if="item.is_inspection==3">服务时间</text>
						<text class="infoSpan">{{item.repair_time}}</text>
					</view>
					<view class="info-item">
						<text class="label" v-if="item.is_inspection==2">维保人员</text>
						<text class="label" v-if="item.is_inspection==3">服务人员</text>
						<text class="infoSpan">{{item.repair_person_name}}</text>
					</view>
					<view class="info-item box box-between" v-if="item.ufList">
						<view class="label box">附　　件</view>
						<view class="infoSpan box">
							<view class="box box-column" style="color: #aaaaaa;font-size: 26upx;">
								<view v-for="(item, i) in item.ufList" :key="i"
									style="margin: 8upx 0upx;font-size: 28upx;color: #00C277;padding-right: 20upx;">
									<view @tap="onOpenDoc(item)">{{item.file_name+"."+item.file_type}}</view>
									<!-- <view style="height: 42upx;width: 42upx;text-align: center;" @click="onDown(item)">
									下载
								</view> -->
								</view>

							</view>
						</view>
					</view>
					<view style="font-size: 28rpx;font-weight: 600;color: red;border-bottom: 1px solid #eee;">互联网信息系统严禁存储、传输、处理涉及国家秘密企业秘密以及敏感信息，违者将严肃问责追责!</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 class="details" v-if="item.reply_flag!='0'" v-for="(reply,replyIndex) in item.replyList" :key="replyIndex">
			<view class="detail_msg" >
				<view class="info-item" v-if="item.reply_content">
					<text class="label">回复内容</text>	
					<text class="infoSpan">{{reply.reply_content}}</text>
				</view>
				<view  class="info-item" >
					<text class="label">回复时间</text>	
					<text class="infoSpan">{{ formatDate(reply.reply_date,'dateTime')}}</text>
				</view>
				<view class="img-box" >
					<image v-for="(itemImg,imgIndex) in reply.replyPictures" :key="imgIndex" :src="itemImg" mode="" @click="vbPicture(new Array(itemImg))"></image>
				</view>
			</view>
		</view> -->
			<view class="details" style="padding: 24upx;">
				<view class="dateTit" style="padding: 24upx 0;">
					<view class="leftIcon">

					</view>
					<text style="font-size:32upx;color:#333;font-weight: 600;">审核反馈</text>
				</view>
				<view class="details" style="background-color: #F2F6FA;margin: unset;margin-top: 24upx;"
					v-if="item.reply_flag!='0'" v-for="(reply,replyIndex) in item.replyList" :key="replyIndex">
					<view class="detail_msg">
						<view class="info-item">
							<text class="label">审核人员</text>
							<text class="infoSpan">{{reply.real_name}}</text>
						</view>
						<view class="info-item">
							<text class="label">审核时间</text>
							<text class="infoSpan">{{ formatDate(reply.reply_date,'dateTime')}}</text>
						</view>
						<view class="info-item" v-if="item.reply_flag==1">
							<text class="label">拒绝理由</text>
							<text class="infoSpan">{{reply.reply_content}}</text>
						</view>
						<view class="img-box">
							<image v-for="(itemImg,imgIndex) in reply.replyPictures" :key="imgIndex"
								:src="formatImgUrl(itemImg)" mode=""
								@click="vbPicture(new Array(formatImgUrl(itemImg)))">
							</image>
						</view>
					</view>
				</view>
			</view>
			<l-file ref="lFile" @up-success="onSuccess"></l-file>
			<!-- <view style="clear: both;"></view>
		<view class="occupied"></view> -->
			<!-- <view class="footer-btn" v-if="role=='1' && first_status=='0'">
			<view class="btn">取消</view>
		</view> -->
			<!-- <view class="footer-btn footer-btn-two" v-if="item.statusCode == '10'">
			<view class="btn btn-col" @click="submit(2)">拒绝</view>
			<view class="btn btn-col1" @click="submit(1)">接受</view>
		</view> -->
		</view>
	</view>
</template>

<script>
	import {
		getFaultRepairInfoById
	} from '@/common/api.js';
	import {
		callbackRequest,
		getStorage,
		alertTip,
		formatDate,
		sureAlterTip,
		vbPicture,
		formatImgUrl
	} from '@/common/util.js';
	import lFile from '@/components/l-file/l-file.vue'
	export default {
		components: {
			lFile
		},
		data() {
			return {
				vbPicture: vbPicture,
				formatImgUrl: formatImgUrl,
				userInfo: '',
				formatDate: formatDate,
				item: {},
				id: 0,
				userId: getStorage('userInfo').id,
				localPath: ''
			}
		},
		onLoad(option) {
			this.userInfo = getStorage('userInfo');
			this.id = option.id || 0;
			this.getFaultRepairInfoById();
		},
		methods: {
			onOpenDoc(item) {
				let url = this.getIcon(item);
				/* 下载返回临时路径（退出应用失效） */
				this.$refs.lFile.download(url)
					.then(path => {
						/* 预览 */
						this.$refs.lFile.open(path);
					});
			},
			onDown(item) {
				let url = this.getIcon(item);
				this.createDownload(url);
				// this.$refs.lFile.download(url,'local')
				// .then(path=>{
				// 	this.localPath = path;
				// }); 
			},
			getIcon(item) {
				return "http://hz.witrear.logplat.top:27003/appImageDir/zhhq_sj/" + item.id + "." + item.file_type;
			},
			checkDownload() {
				plus.io.requestFileSystem(plus.io.PUBLIC_DOWNLOADS, function(fs) {
					var directoryReader = fs.root.createReader();
					directoryReader.readEntries(function(entries) {
						var i;
						for (i = 0; i < entries.length; i++) {
							console.log(entries[i].name);
							entries[i].name = i
						}
					}, function(e) {
						console.log("Read entries failed: " + e.message);
					});
				});
			},
			// 创建下载任务  
			createDownload(url) {
				var dtask = plus.downloader.createDownload(url, {
					filename: "_download/"
				}, function(d, status) {
					// 下载完成 下载的文件会保存在 PUBLIC_DOWNLOADS 目录下，只要不主动删除都会存在  
					if (status == 200) {
						console.log("Download success: ");
						console.log(d);
						checkDownload()
					} else {
						console.log("Download failed: " + status);
					}
				});;
				dtask.start();
			},
			onSuccess(res) {
				console.log('上传成功回调', JSON.stringify(res));
				uni.showToast({
					title: JSON.stringify(res),
					icon: 'none'
				})
			},
			getFaultRepairInfoById() {
				let params = {
					method: getFaultRepairInfoById,
					data: {
						userId: this.userId,
						id: this.id
					}
				};
				callbackRequest(params).then(res => {
					res = res.data;
					if (res.returnCode == 1) {
						this.item = res.returnData;
					} else {
						alertTip(res.returnMsg);
					}
				});
			},
			submit(type) {
				if (type != 1 && type != 2) {
					return
				}
				// 1 同意 2 拒绝
				let params = {
					"method": doHitch,
					"data": {
						userId: this.userInfo.id,
						type: type,
						id: this.item.id
					}
				};
				console.log("params:", params);
				callbackRequest(params).then(res => {
					res = res.data;
					console.log("return:", res);
					alertTip(res.returnMsg);
					if (res.returnCode === "1") {
						// 跳回列表页
						uni.navigateTo({
							url: '/pages/repair-record/repair-record'
						})
					}
				})
			}

		}
	}
</script>

<style lang="scss">
	@import '@/static/css/common.scss';

	.box {
		display: flex;
		display: -webkit-flex;
	}

	.box-row-reverse {
		flex-direction: row;
	}

	/*水平排列*/
	.box-column {
		flex-direction: column;
	}

	/*上下排列*/
	.box-left {
		justify-content: flex-start;
	}

	/*居右*/
	.box-right {
		justify-content: flex-end;
	}

	/*居左*/
	.box-center {
		justify-content: center;
	}

	.box-between {
		justify-content: space-between;
	}

	.box-align-center {
		align-items: center;
	}

	.box-wrap {
		flex-wrap: wrap;
		margin-left: 28upx;
	}

	.container {
		.details {
			font-size: 28upx;
			color: #555555;
			// height: 550upx;
			background: white;
			margin: 15upx;
			border-radius: 15upx;

			.detail_msg {
				margin-left: 24upx;
				border-radius: 10upx;

				.info-item {
					border-bottom: 1px solid #f8f8f8;
					line-height: 96upx;

					.label {
						display: inline-block;
						width: 188upx;
						font-size: 28upx;
						color: #333;
						font-weight: 400;
					}
				}

				.status {
					.infoSpan {
						color: #00c277;
					}

					.infoSpan2 {
						color: #FB8107;
					}
				}

				.img-box {

					// background: #fff;
					image {
						width: 200upx;
						height: 200upx;
						margin: 20upx 20upx 0 0;
					}
				}
			}
		}

		.interviewee {
			background: #FFFFFF;
			width: 625rpx;
			height: 270rpx;
			border-radius: 10rpx;

			.p-title {
				background: #DCDFE6;
				text-align: center;
				border-radius: 10rpx;
				font-size: 30rpx;
				width: 100%;
				height: 70rpx;
				line-height: 70rpx;
			}

			.center {
				padding: 26upx;
				display: flex;
				align-items: center;
				position: relative;
				border-bottom: 1px solid #eee;

				.input_left {
					font-size: 30rpx;
					font-weight: bold;
				}

				.arrow {
					float: right;
					width: 16upx;
					height: 29upx;
					margin-top: 10upx;
				}

				.picker {
					margin-right: 40upx;
					margin-left: 10upx;
					font-size: 28upx;
					line-height: 50upx;
					color: #666;
					width: 72%;
				}
			}

			.bu {
				margin: 10rpx;

				.cancel {
					width: 45%;
					height: 80rpx;
					margin-left: 10rpx;
					background: #cc;
				}

				.confirm {
					width: 45%;
					height: 80rpx;
					margin-right: 10rpx;
					margin-top: -80rpx;
					background: #00c277;
				}
			}
		}
	}

	.dateTit {
		width: 100%;
		display: flex;
		align-items: center;
		// margin-left: 16upx;

		image {
			width: 35upx;
			height: 35upx;
			margin-right: 10upx;
		}

		.leftIcon {
			width: 8upx;
			height: 30upx;
			background-image: linear-gradient(to bottom, #82E7B3, #94B8EF);
			border-radius: 5px;
			margin-right: 10upx;
		}
	}
</style>