<template>
	<view class="dangerbig-details">
		<view class="fixedheader">
			<headers :showBack="true">
				<view class="headerName">
					查看明细
				</view>
			</headers>
		</view>
		<view :style="{ 'padding-top': (statusBarHeight + 45) * 1.5 + 'rpx' }">
			<view class="detail-content">
				<view class="list">
					<view class="list-info">
						样板工程名称：<text class="detail-data">{{detailData.exampleProjectName}}</text>
					</view>
					<view class="list-info">
						装置/单元工程：<text class="detail-data">{{detailData.deviceUnitName}}</text>
					</view>
					<view class="list-info">
						装置/单元号：<text class="detail-data">{{detailData.deviceUnitNo}}</text>
					</view>
					<view class="list-info">
						承包方式：<text
							class="detail-data">{{detailData.contractingType ? contractingTypeList[detailData.contractingType - 1].contractingName : '--'}}</text>
					</view>
					<view class="list-info">
						区域项目组：<text class="detail-data">{{detailData.projectGroupName }}</text>
					</view>
					<view class="list-info">
						工程监理单位：<text class="detail-data">{{detailData.supervisingUnitName}}</text>
					</view>
					<view class="list-info">
						EPC承包商：<text class="detail-data">{{detailData.epcContractorName}}</text>
					</view>
					<view class="list-info">
						施工单位：<text class="detail-data">{{detailData.constructionUnitName}}</text>
					</view>
					<view class="list-info">
						涉及技术专业：<text
							class="detail-data">{{detailData.technicalOperation ? technicalOperationList[detailData.technicalOperation - 1].operationName : '--'}}</text>
					</view>
					<view class="list-info">
						技术负责人：<text class="detail-data">{{detailData.technicalDirectorName}}</text>
					</view>
					<view class="list-info">
						实施日期：<text class="detail-data">{{detailData.implementationDate}}</text>
					</view>
					<view class="list-info">
						实施验证结果：<text class="detail-data">{{detailData.implementationVerificationResult}}</text>
					</view>
					<view class="" v-if="isShow">
						<view class="list-info">
							专业EPC承包商技术负责人：<text class="detail-data">{{detailData.professionalEpcContractorName}}</text>
						</view>
						<view class="list-info">
							专业EPC承包商技术负责人日期：<text class="detail-data">{{detailData.professionalEpcContractorDate}}</text>
						</view>
						<view class="list-info">
							施工承包商技术负责人：<text class="detail-data">{{detailData.constructionContractorName}}</text>
						</view>
						<view class="list-info">
							施工承包商技术负责人日期：<text class="detail-data">{{detailData.constructionContractorDate}}</text>
						</view>
						<!-- <view class="list-info">
							监理工程师审查意见：<text class="detail-data">{{detailData.supervisingEngineerOpinion}}</text>
						</view> -->
						<view class="list-info">
							监理工程师：<text class="detail-data">{{detailData.supervisingEngineerName}}</text>
						</view>
						<view class="list-info">
							监理工程师日期：<text class="detail-data">{{detailData.supervisingEngineerDate}}</text>
						</view>
						<!-- <view class="list-info">
							项目组专业工程师审查意见：<text class="detail-data">{{detailData.professionalEngineerOpinion}}</text>
						</view> -->
						<view class="list-info">
							项目组专业工程师：<text class="detail-data">{{detailData.professionalEngineerName}}</text>
						</view>
						<view class="list-info">
							项目组专业工程师日期：<text class="detail-data">{{detailData.professionalEngineerDate}}</text>
						</view>
						<!-- <view class="list-info">
							施工管理部专业组长意见：<text class="detail-data">{{detailData.professionalTeamLeaderOpinion}}</text>
						</view> -->
						<view class="list-info">
							施工管理部专业组长：<text class="detail-data">{{detailData.professionalTeamLeaderName}}</text>
						</view>
						<view class="list-info">
							施工管理部专业组长日期：<text class="detail-data">{{detailData.professionalTeamLeaderDate}}</text>
						</view>
					</view>

					<view v-if="COMPANY != 'longguang'" class="more-btn" @click="isShow=!isShow">
						<text>{{isShow ? "收起详情":"展开详情"}}</text>
						<image class="detail_icon_up" :class="{'detail_icon_down': isShow}"
							src="/static/bthgIcon/detail_icon.png"></image>
					</view>
				</view>
				<view class="detail-nav">
					<view class="nav_main">
						<view class="nav_title">附件</view>
						<view class="fileItem" v-for="(item,index) in detailData.firstExampleFile" :key="index">
							<view class="left">
								<!-- <image class="fileIcon" :src="setFileImg(item)"></image> -->
								<image class="fileIcon" src="@/static/bthgIcon/attachment.png"></image>
								<text class="left_text" @click.stop="downloadFn(item)">{{item.name}}</text>
							</view>
							<!-- <image v-if="!item.isDir" @click.stop="downloadFn(item)" class="ellipsis"
									src="../../static/ellipsis.png"></image> -->
							<!-- <view class="rules-text2">
								<text @click="downloadFile(item)">预览</text>
								<text @click.stop="downloadFn(item)">下载</text>
							</view> -->
						</view>
					</view>
					<view class="nav_main1">
						<view class="nav_title">动画</view>
						<view class="fileItem" v-for="(item,index) in detailData.firstExampleVideo" :key="index">
							<view class="left">
								<!-- <image class="fileIcon" :src="setFileImg(item)"></image> -->
								<image class="fileIcon" src="@/static/bthgIcon/attachment.png"></image>
								<text class="left_text" @click.stop="downloadFn(item)">{{item.name}}</text>
							</view>
							<!-- <image v-if="!item.isDir" @click.stop="downloadFn(item)" class="ellipsis"
								src="../../static/ellipsis.png"></image> -->
							<!-- <view class="rules-text2">
							<text @click="downloadFile(item)">预览</text>
							<text @click.stop="downloadFn(item)">下载</text>
						</view> -->
						</view>
					</view>
				</view>
				<!-- <view class="add-btn" v-if="activeIndex != 7 && activeIndex != 2 && !(activeIndex == 1 && detailData.engineeringState == 3) -->
				<!-- v-if="activeIndex != 7 && userInfo.userId === detailData.assignmentPersonInCharge
					&& COMPANY != 'longguang' && detailData.finalAcceptanceStatus !== 2 && isShowBtn && btnAuth" -->
				<!-- <view class="add-btn" @click="addForm">
					<uni-icons2 v-if="activeIndex == 5" type="camera" size="30" color="#fff"></uni-icons2>
					<uni-icons2 v-else type="plusempty" size="30" color="#fff"></uni-icons2>
					<span>+</span>
				</view> -->
			</view>
		</view>
		<view class="fixed" :class="{show:showIframe}" v-if="show" @click="show=false">
			<view class="iframeMain" @click.stop="show=true">
				<video v-if="getType(iframeUrl) == 'video'" class="iframe" :src="iframeUrl"></video>
				<image v-else-if="getType(iframeUrl) == 'image'" class="iframe" :src="iframeUrl" mode="aspectFit">
				</image>
				<iframe v-else class="iframe" ref="iframe" :src="iframeUrl" frameborder="0"></iframe>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		isVideoLink,
		isImageLink,
		openOutsideFile,
		openLocalFile,
		removeNetWorkFileTemp,
		isJSON
	} from '@/utils/tool.js'
	export default {
		data() {
			return {
				statusBarHeight: 0,
				isShow: true,
				componentName: "plan",
				navList: [{
					id: 1,
					name: "相关附件"
				}, {
					id: 3,
					name: "安全检查"
				}],
				activeIndex: 1,
				detailId: "",
				detailData: {},
				isShowBtn: null,
				userInfo: {},
				btnAuth: true,
				showIframe: false,
				show: false,
				iframeUrl: "",
				equipmentToolList: [], // 相关附件
				technicalOperationList: [{
					id: 1,
					operationName: "土建",
				}, {
					id: 2,
					operationName: "动设备",
				}, {
					id: 3,
					operationName: "静设备",
				}, {
					id: 4,
					operationName: "管道",
				}, {
					id: 5,
					operationName: "电气",
				}, {
					id: 6,
					operationName: "仪表",
				}, {
					id: 7,
					operationName: "其它",
				}], // 技术操作
				contractingTypeList: [{
					id: 1,
					contractingName: "EPC",
				}, {
					id: 2,
					contractingName: "E+P+C",
				}], // 承包方式
			}
		},
		onReachBottom() {
			console.log(1, this.$refs['list'])
		},
		onPullDownRefresh() {
			console.log(2)
		},
		onShow() {
			this.userInfo = JSON.parse(uni.getStorageSync('userInfo'))
			this.statusBarHeight = uni.getStorageSync('systemInfo').statusBarHeight;
			// this.initData()
			this.getWork()
			let that = this;
			setTimeout(function() {
				console.log(that.$refs, 777)
				console.log(that.$refs.listBox, 777)
				if (that.$refs['list'] && that.$refs['list'].initData) {
					console.log(777888)
					that.$refs['list'].initData()
				}
			}, 200);
			// this.getEquipmentToolList();
		},
		onLoad(val) {
			this.btnAuth = this.checkBtnPermission({
				key: 'towerOverWork_add',
				menuPath: '/project/specialWork/towerOverWork'
			})
			this.detailId = val.id;
		},
		onUnload() {
			removeNetWorkFileTemp();
		},
		mounted() {},
		methods: {
			getType(url) {
				if (isImageLink(url)) {
					return "image"
				} else if (isVideoLink(url)) {
					return "video"
				} else {
					return ''
				}
			},
			downloadFile(url) {
				// 下载所有的文件
				let name = url.substring(url.lastIndexOf('/') + 1);
				console.log(name, "文件名称");
				if (isVideoLink(url) || isImageLink(url)) {
					// 是图片和视频
					this.show = true;
					this.showIframe = true;
					this.iframeUrl = this.url_config + 'image/' + url;
				} else {
					// openOutsideFile(`${this.url_config}image/${url}`)
					openLocalFile(name, `${this.url_config}image/${url}`)
				}

				return;
			},
			//预览图片
			previewImage(url) {
				uni.previewImage({
					urls: [url]
				})
			},
			getWork() {
				this.sendRequest({
					url: 'xmgl/firstExampleManage/queryById',
					method: 'get',
					data: {
						id: this.detailId
					},
					success: res => {
						uni.hideLoading()
						// if(res.code==200){
						// 	this.listData = res.result.records
						// }
						this.detailData = {
							...res.result,
							firstExampleFile: isJSON(res.result.firstExampleFile) ? JSON.parse(res.result
								.firstExampleFile) : [],
							firstExampleVideo: isJSON(res.result.firstExampleVideo) ? JSON.parse(res.result
								.firstExampleVideo) : [],

						};
						this.getApply()
					}
				})
			},
			goSafeMesure() {
				uni.navigateTo({
					url: "./safeMesure?detailId=" + this.detailId
				})
			},
			getEquipmentToolList() {
				this.sendRequest({
					url: 'xmgl/constructionEquipmentToolFile/list',
					method: 'get',
					data: {
						constructionEquipmentToolId: this.detailId,
						projectSn: JSON.parse(uni.getStorageSync('projectDetail')).projectSn
					},
					success: res => {
						uni.hideLoading()
						console.log("xmgl/constructionEquipmentToolFile/list", res);
						let result = res.result
						if (res.result.length > 0) {
							this.equipmentToolList = res.result;
						}
					}
				})
			},
			getApply() {
				console.log("=====================================================detail");
				console.log(this.detailData);
				this.sendRequest({
					url: 'xmgl/xzDangerousEngineeringAcceptance/list',
					method: 'get',
					data: {
						engineeringId: this.detailData.id,
						projectSn: JSON.parse(uni.getStorageSync('projectDetail')).projectSn,
						type: 10
					},
					success: res => {
						uni.hideLoading()
						console.log("xmgl/xzDangerousEngineeringAcceptance/list", res);
						let result = res.result
						if (res.result.length > 0) {
							if (res.result[0].acceptanceResult === null) this.isShowBtn = false
							if (res.result[0].acceptanceResult === 1) this.isShowBtn = false
							if (res.result[0].acceptanceResult === 2) this.isShowBtn = true
						} else {
							this.isShowBtn = true
						}
					}
				})
			},
			checkNav(val) {
				this.activeIndex = val.id
				if (val.id == 1) {
					this.componentName = "plan";
					this.getEquipmentToolList();
				} else if (val.id == 2) {
					this.componentName = "safe"
				} else if (val.id == 3) {
					this.componentName = "side";
				} else if (val.id == 4) {
					this.componentName = "workFinally"
				}
			},
			addForm() {
				uni.navigateTo({
					url: './addSide?id=' + this.detailId
				})
				// if(this.activeIndex == 1){
				// 	uni.navigateTo({
				// 		url:'./addPlan?id='+this.detailId
				// 	})
				// } else if(this.activeIndex == 2){
				// 	if(uni.getStorageSync('dangerData')){
				// 		uni.removeStorageSync('dangerData');
				// 	}
				// 	if(uni.getStorageSync('detailData')){
				// 		uni.removeStorageSync('detailData');
				// 	}
				// 	uni.navigateTo({
				// 		// url:'../safeManage/addExamine?type=1&engineeringId='+this.detailId + '&moduleType=safeCheck'
				// 		url:'../../safeSame/addIssue?type=5&engineeringId='+this.detailId + '&moduleType=safeCheck'
				// 	})
				// } else if(this.activeIndex == 3){
				// 	uni.navigateTo({
				// 		url:'./addSide?id='+this.detailId
				// 	})
				// } else if(this.activeIndex == 4){
				// 	if(this.isShowBtn){
				// 		uni.navigateTo({
				// 			url:'./addWorkFinally?id='+this.detailId+'&workTicketCode='+this.detailData.workTicketCode
				// 		})
				// 	}else{
				// 		uni.showToast({
				// 			title: '请勿重复操作',
				// 			icon: "none",
				// 			duration: 2000
				// 		});
				// 	}
				// }
			},
			downloadFile(url) {
				const newUrl = url.url.includes('http://') ? url.url : this.url_config + 'image/' + url.url;
				console.log(url)
				const typeImageList = ['png', 'jpg', 'jpeg'];
				if (typeImageList.includes(url.name)) {
					uni.previewImage({
						urls: [newUrl]
					})
				} else {
					// //#ifdef H5
					// uni.showToast({
					// 	title: '暂不支持预览！',
					// 	icon: "none",
					// 	duration: 2000
					// });
					// return;
					// //#endif
					uni.downloadFile({
						url: newUrl,
						success: function(res) {
							var filePath = res.tempFilePath;
							uni.openDocument({
								filePath: filePath,
								success: function(res) {
									console.log('打开文档成功');
								}
							});
						}
					});
				}
			},
			downloadFn(item) {
				var that = this
				uni.showModal({
					title: '提示',
					content: item.name,
					confirmText: '下载',
					success: function(res) {
						if (res.confirm) {
							uni.downloadFile({
								url: item.url.includes("http://") ? item.url : that.url_config + 'image/' + item.url, //仅为示例，并非真实的资源
								success: (res) => {
									console.log(res)
									if (res.statusCode === 200) {
										// uni.showToast({
										// 	title:'下载成功'
										// })
										var filePath = res.tempFilePath;
										if (!filePath) return
										uni.openDocument({
											filePath: filePath,
											success: function(res) {
												console.log(res);
												console.log('打开文档成功');
												uni.showToast({
													title: '打开文档成功'
												})
											}
										});
									} else {
										uni.showToast({
											title: '下载失败'
										})
									}
								}
							});
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.detail-nav {
		width: 100%;
		padding-bottom: 40rpx;

		.nav_title {
			padding: 28rpx 40rpx;
			font-size: 30rpx;
		}
	}

	.uni-form-item {
		position: relative;

		.search-icon {
			position: absolute;
			top: 50%;
			right: 50rpx;
			transform: translateY(-50%);
		}
	}

	.rules-text2 {
		display: flex;
		justify-content: center;
		align-items: center;
		color: #3592F3;
		font-size: 26rpx;
		white-space: nowrap;

		>text:first-child {
			margin-right: 20rpx;
		}
	}
	.detail-nav >.fileItem:not(:last-child){
		margin-bottom: 20rpx;
	}
	.fileItem {
		// flex: 1;
		font-size: 30rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 22rpx 40rpx;
		margin: 0 40rpx;
		// color: $uni-text-color;
		color: #3592F3;
		background-color: #F4F7FE;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
		-o-text-overflow: ellipsis;

		.left {
			display: flex;
			align-items: center;
			width: 90%;

			.left_text {
				flex: 1;
				color: #5181F6;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
				-o-text-overflow: ellipsis;
			}
		}

		.fileIcon {
			width: 40rpx;
			height: 44rpx;
			margin-right: 20rpx;
		}

		.ellipsis {
			width: 40rpx;
			height: 10rpx;
		}
	}

	.nav_main .fileItem:not(:first-child) {
		margin-top: 20rpx;
	}
	
	.nav_main1 .fileItem:not(:first-child) {
		margin-top: 20rpx;
	}

	.uni-form-item {
		position: relative;

		.search-icon {
			position: absolute;
			top: 50%;
			right: 50rpx;
			transform: translateY(-50%);
		}
	}

	.fixed {
		position: fixed;
		z-index: 9999;
		left: 0;
		top: 0;
		right: 0;
		bottom: 0;
		background-color: rgba(0, 0, 0, .3);
		display: none;

		&.show {
			display: initial;
		}
	}

	.iframeMain {
		position: absolute;
		left: 50%;
		top: 50%;
		transform: translate(-50%, -50%);
		width: 650rpx;
		font-size: 0;

		.iframe {
			width: 100%;
			height: 500rpx;
		}
	}

	.other-safe {
		background-color: #fff;
		// margin-top: 50rpx;
		padding: 15rpx 15rpx;
		line-height: 40rpx;

		.other-head {
			display: flex;

			.other-icon {
				width: 10rpx;
				height: 40rpx;
				background-color: #2b8df3;
				border-radius: 100rpx;
			}

			.other-text {
				margin-left: 20rpx;
			}
		}

		.other-content {
			font-size: 22rpx;
			width: auto;
			min-height: 50rpx;
			// background-color: darkred;
			// border: 1rpx solid black;
			margin: 0 30rpx;
			margin-top: 15rpx;
			display: flex;

			.content-1 {
				width: 22%;
			}

			.content-2 {
				width: 24%;
			}

			.content-3 {
				width: 23%;
				// margin-left: 10%;
			}

			.content-4 {
				width: 26%;
			}
		}

	}

	.safe-mesure {
		width: 100%;
		height: 100rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: #fff;

		.safe-btn {
			text-align: center;
			width: 80%;
			line-height: 70rpx;
			// background-color: darkred;
			border: 4rpx solid #2b8df3;
			color: #2b8df3;
			border-radius: 20rpx;
			font-weight: bold;
		}
	}

	.table-info {
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: #fff;

		.teble-list {
			display: flex;
			justify-content: flex-start;
			width: 100%;
			font-size: 18rpx;
			background-color: gainsboro;

			.teble-item {
				width: 24.8%;
				line-height: 40rpx;

				// border: 1rpx solid black;
				// background-color: darkred;
				.item-col {
					// margin: 0 5rpx;
					margin-left: 5rpx;
					margin-top: 5rpx;
					padding: 3rpx;
					text-align: center;
					background-color: #fff;
				}
			}
		}

		.u-td {
			height: auto;
		}
	}

	.dangerbig-details {
		min-height: 100%;
		// background: #F6F6F6;

		.fixedheader {
			position: fixed;
			top: 0;
			left: 0;
			width: 100%;
			z-index: 2;
		}

		.detail-content {
			padding-top: 20rpx;
		}

		.list {
			margin-bottom: 20rpx;
			// margin: 0 20rpx 20rpx;
		}

		.list-info {
			background: #fff;
			// border-bottom: 1px solid #F6F6F6;
			font-size: 26rpx;
			padding: 20rpx 30rpx;
			// display: flex;
			// align-items: center;
		}

		.list-info {
			.source-box {
				display: flex;
				flex-direction: column;

				text {
					color: #8F8FF7;
					text-decoration: underline;
					margin-top: 20rpx;
				}
			}
		}

		.list-info ul {
			list-style: none;
			padding: 0;
			display: flex;
			flex-wrap: wrap;
			align-items: center;
			margin-top: 20rpx;
		}

		.list-info ul li {
			width: 30%;
			height: 100px;
			margin: 0 10rpx;
			margin-bottom: 20rpx;
		}

		.list-info ul li image {
			width: 100%;
			height: 100%;
		}

		.more-btn {
			text-align: center;
			font-size: 28rpx;
			// height: 50rpx;
			background: #F1F7FE;
			line-height: 50rpx;
			border-top: 2rpx dashed #CCCCCC;
			border-bottom: 2rpx dashed #CCCCCC;
			padding: 14rpx 0;
			color: #3190F3;
		}

		.nav-list {
			display: flex;
			height: 80rpx;
			align-items: center;
			padding: 0 20rpx;

			.nav-item {
				width: 25%;
				text-align: center;
				white-space: nowrap;
				padding: 0 20rpx;
				height: 80rpx;
				box-sizing: border-box;
				line-height: 80rpx;
				font-size: 28rpx;
			}

			.active-nav {
				border-bottom: 4rpx solid #4396E7;
			}
		}

		.detail-nav {
			width: 100%;
		}

		.scrollx-wrap {
			width: 100%;
			background: #fff;
		}

		.add-btn {
			background: #4181FE;
			width: 96rpx;
			height: 96rpx;
			border-radius: 50%;
			text-align: center;
			line-height: 96rpx;
			position: fixed;
			bottom: 40rpx;
			right: 40rpx;

			span {
				font-size: 60rpx;
				line-height: 86rpx;
				color: #fff;
			}
		}
	}
</style>