<template>
	<view class="dangerbig-details">
		<view class="fixedheader">
			<headers :themeType="true" :showBack="true">
				<view class="headerName">
					危大工程详情
				</view>
			</headers>
		</view>
		<view :style="{ 'padding-top': ((statusBarHeight * 2) + 45) * 1.5 + 'rpx' }">
			<view class="detail-content">
					<view class="list">
						<view class="list-info">
							工程名称：<text class="detail-data">{{detailData.engineeringName}}</text>
						</view>
						<view class="list-info">
							工程类别：<text class="detail-data">{{detailData.engineeringTypeName}}</text>
						</view>
						<view v-show="isShow">
							<view class="list-info">
								工程概况：<text class="detail-data">{{detailData.engineeringSurvey ? detailData.engineeringSurvey : "无"}}</text>
							</view>
							<view class="list-info">
								类别描述：<text class="detail-data">{{detailData.describeName ? detailData.describeName : "无"}}</text>
							</view>
							<view class="list-info">
								施工部位：<text class="detail-data">{{detailData.constructionLocation ? detailData.constructionLocation : "无"}}</text>
							</view>
							<view class="list-info">
								计划时间：<text class="detail-data">{{detailData.planStartTime}}~{{detailData.planEndTime}}</text>
							</view>
							<!-- <view class="list-info">
								施工时间：<text class="detail-data">{{detailData.buildStartTime}}~{{detailData.buildEndTime}}</text>
							</view> -->
							<view class="list-info">
								负责人：<text class="detail-data">{{detailData.personLiable ? detailData.personLiable : "无"}}</text>
							</view>
							<view class="list-info">
								责任分包：<text class="detail-data">{{detailData.responsibilityCompany ? detailData.responsibilityCompany : "无"}}</text>
							</view>
						</view>
						<view v-if="COMPANY != 'longguang'" class="more-btn" @click="isShow=!isShow">
							{{isShow ? "收起":"展开"}}
							<uni-icons2 :type="isShow ? 'arrowup':'arrowdown'"></uni-icons2>
						</view>
					</view>

					<view class="detail-nav" v-if="COMPANY != 'longguang'">
						<scroll-view class="scrollx-wrap" scroll-x>
							<view class="nav-list">
								<view class="nav-item"
									:class="{'active-nav': activeIndex == item.id}"
									v-for="(item,index) in navList" :key="index"
									@click="checkNav(item)">
									{{item.name}}
								</view>
							</view>
						</scroll-view>
						<view class="detail-wrap">
							<!-- <component ref="list" :is="componentName" :id="detailId" :info="detailData"></component> -->
							<safeList ref="list" v-if="componentName == 'safeList'" :detailId="detailId" :info="detailData">123123</safeList>
							<control ref="list" v-if="componentName == 'control'" :detailId="detailId" :info="detailData"></control>
							<planList ref="list" v-if="componentName == 'planList'" :detailId="detailId" :info="detailData"></planList>
							<constructionStation ref="list" v-if="componentName == 'constructionStation'" :detailId="detailId" :info="detailData"></constructionStation>
							<ordinaryAcceptance ref="list" v-if="componentName == 'ordinaryAcceptance'" :detailId="detailId" :info="detailData"></ordinaryAcceptance>
							<engineeringData ref="list" v-if="componentName == 'engineeringData'" :detailId="detailId" :info="detailData"></engineeringData>
							<verifyTableList ref="list" v-if="componentName == 'verifyTableList'" :detailId="detailId" :info="detailData"></verifyTableList>
							<finally-acceptance ref="list" v-if="componentName =='finallyAcceptance'" :detailId="detailId" :info="detailData" ></finally-acceptance>
						</view>
					</view>
					<!-- <view class="add-btn" v-if="activeIndex != 7 && activeIndex != 2 && !(activeIndex == 1 && detailData.engineeringState == 3) -->
					<view class="add-btn" v-if="activeIndex != 7 && activeIndex != 2 
					&& COMPANY != 'longguang' && detailData.finalAcceptanceStatus !== 2 && isShowBtn && btnAuth 
					&& userInfo.accountType != 6 || userInfo.userId == detailData.personLiableId"
					@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>
</template>

<script>
	import safeList from './safeList.vue'
	import control from './control.vue'
	import planList from './planList.vue'
	import constructionStation from './constructionStation.vue'
	import ordinaryAcceptance from './ordinaryAcceptance.vue'
	import engineeringData from './engineeringData.vue'
	import verifyTableList from './verifyTableList.vue'
	import finallyAcceptance from './finallyAcceptance.vue'
	export default {
		components:{
			safeList,
			control,
			planList,
			constructionStation,
			ordinaryAcceptance,
			engineeringData,
			verifyTableList,
			finallyAcceptance
		},
		data(){
			return{
				statusBarHeight: 0,
				isShow: true,
				componentName: "planList",
				navList:[{
					id: 1,
					name: "当前进度"
				},{
					id: 2,
					name: "工程资料"
				},/*{
					id: 3,
					name: "一般验收"
				},{
					id: 4,
					name: "验收表验收"
				},*/{
					id: 5,
					name: "安全检查"
				},{
					id: 6,
					name: "施工旁站"
				},{
					id: 7,
					name: "管控要点"
				},
				{
					id: 8,
					name: "最终验收"
				}
				],
				activeIndex: 1,
				detailId: "",
				detailData:{},
				isShowBtn: null,
				btnAuth: true,
				userInfo:{},
			}
		},
		onReachBottom() {
			console.log(1,this.$refs['list'])
		},
		onPullDownRefresh() {
			console.log(2)
		},
		onShow(){
			this.statusBarHeight = uni.getStorageSync('systemInfo').statusBarHeight;
			this.initData()
			let that = this;
			setTimeout(function(){
				// console.log(that.$refs,777)
				// console.log(that.$refs.list,777)
				if(that.$refs['list'] && that.$refs['list'].initData){
					that.$refs['list'].initData()
				}
			},200)
		},
		onLoad(val){
			this.btnAuth = this.checkBtnPermission({key: 'wdgc_add', menuPath: '/project/dangerousBigProject/parameter'})
			this.detailId = val.id
			// if(val.)
			// this.initData()
		},
		mounted() {
			this.userInfo = JSON.parse(uni.getStorageSync('userInfo'))
		},
		methods:{
			initData(){
				this.sendRequest({
					url:'xmgl/dangerousEngineeringRecord/queryById',
					method:'post',
					data:{id:this.detailId},
					success:res=>{
						uni.hideLoading()
						// if(res.code==200){
						// 	this.listData = res.result.records
						// }
						this.detailData =  res.result
						let str = '';
						if(res.result.chooseTypeDescribeList){
							this.detailData.describeName
							res.result.chooseTypeDescribeList.map((item,index) => {
								if(index == res.result.chooseTypeDescribeList.length - 1){
									str = str + item.describeName
								} else {
									str = str + item.describeName + ','
								}
							})
							console.log(str,123456789)
							this.detailData.describeName = str;
						}
						console.log(this.detailData)
						this.getApply()
					}
				})
			},
			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:1
					},
					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 = "planList"
				} else if(val.id == 2){
					this.componentName = "engineeringData"
				} else if(val.id == 3){
					this.componentName = "ordinaryAcceptance"
				} else if(val.id == 4){
					this.componentName = "verifyTableList"
				} else if(val.id == 5){
					this.componentName = "safeList"
				} else if(val.id == 6){
					this.componentName = "constructionStation"
				} else if(val.id == 7){
					this.componentName = "control"
				}else if(val.id == 8){
					this.componentName = "finallyAcceptance"
				}
			},
			addForm(){
				if(this.activeIndex == 1){
					uni.navigateTo({
						url:'./addPlan?id='+this.detailId
					})
				} else if(this.activeIndex == 3){
					uni.navigateTo({
						url:'./addOrdinaryAcceptance?id='+this.detailId
					})
				}	else if(this.activeIndex == 4){
					uni.navigateTo({
						url:'./addVerifyForm?id='+this.detailId
					})
				} else if(this.activeIndex == 5){
					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=1&engineeringId='+this.detailId + '&moduleType=safeCheck'
					})
				} else if(this.activeIndex == 6){
					uni.navigateTo({
						url:'./addConstructionStation?id='+this.detailId
					})
				}
				else if(this.activeIndex == 8){
					if(this.isShowBtn){
						uni.navigateTo({
							url:'./addFinallyAcceptance?id='+this.detailId+'&name='+this.detailData.engineeringName
						})
					}else{
						uni.showToast({
							title: '请勿重复操作',
							icon: "none",
							duration: 2000
						});
					}
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
.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;
	}
	.list-info{
		background: #fff;
		border-bottom: 1px solid #F6F6F6;
		font-size: 28rpx;
		padding: 20rpx;
	}
	.more-btn{
		text-align: center;
		font-size: 28rpx;
		height: 50rpx;
		background: #F1F7FE;
		line-height: 50rpx;
	}
	.nav-list{
		display: flex;
		height: 80rpx;
		align-items: center;
		padding: 0 20rpx;
		.nav-item{
			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: 90rpx;
			    color: #fff;
		}
	}
}
</style>
