<template>
	<view class="dangerbig-details">
		<view class="fixedheader">
			<headers :themeType="true" :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.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 class="more-btn" @click="isShow=!isShow">
							{{isShow ? "收起":"展开"}}
							<uni-icons2 :type="isShow ? 'arrowup':'arrowdown'"></uni-icons2>
						</view>
					</view>
					
					<view class="detail-nav">
						<view class="nav-list">
							<view class="nav-item" @click="changeNav(1)">
								<view :class="{'active-nav': activeIndex == 1}">我的</view>
							</view>
							<view class="nav-item" @click="changeNav(2)">
								<view :class="{'active-nav': activeIndex == 2}">全部</view>
							</view>
						</view>
						<view class="detail-wrap">
							<!-- <component :is="componentName" :status="status" :engineeringId="detailId" :type="componentType" :isEdit="isEdit ? '1':'0'" :taskId="taskId" @upTableData="queryMyCheck" :myCheckAllresult="myCheckAllresult" :allTableData="allTableData" :tableData="tableData" :checkData="checkData"></component> -->
							<myDangerBigCheck v-if="componentName == 'myDangerBigCheck'" :status="status" :engineeringId="detailId" :type="componentType" :isEdit="isEdit ? '1':'0'" :taskId="taskId" @upTableData="queryMyCheck" :myCheckAllresult="myCheckAllresult" :allTableData="allTableData" :tableData="tableData" :checkData="checkData"></myDangerBigCheck>
							<dangerBigCheckDetail v-if="componentName == 'dangerBigCheckDetail'" :status="status" :engineeringId="detailId" :type="componentType" :isEdit="isEdit ? '1':'0'" :taskId="taskId" @upTableData="queryMyCheck" :myCheckAllresult="myCheckAllresult" :allTableData="allTableData" :tableData="tableData" :checkData="checkData"></dangerBigCheckDetail>
							<allDangerBigCheck v-if="componentName == 'allDangerBigCheck'" :status="status" :engineeringId="detailId" :type="componentType" :isEdit="isEdit ? '1':'0'" :taskId="taskId" @upTableData="queryMyCheck" :myCheckAllresult="myCheckAllresult" :allTableData="allTableData" :tableData="tableData" :checkData="checkData"></allDangerBigCheck>
						</view>
					</view>
			</view>
		</view>
	</view>
</template>

<script>
	import myDangerBigCheck from './myDangerBigCheck.vue'
	import dangerBigCheckDetail from './dangerBigCheckDetail.vue'
	import allDangerBigCheck from './allDangerBigCheck.vue'
	export default {
		data(){
			return{
				statusBarHeight: 0,
				isShow: false,
				detailId: "",
				detailData:{},
				componentName: "",
				activeIndex: 1,
				taskId: "",
				userId: "",
				checkData: [],
				tableData: [],
				allTableData: [],
				myCheckAllresult:[],
				componentType: "",
				status: ""
			}
		},
		components:{
			myDangerBigCheck,
			allDangerBigCheck,
			dangerBigCheckDetail
		},
		onShow(){
			this.statusBarHeight = uni.getStorageSync('systemInfo').statusBarHeight;
			this.userId = JSON.parse(uni.getStorageSync('userInfo')).userId
			this.initData()
			this.queryMyCheck()
			// this.queryAllResult()
		},
		onLoad(val){
			this.detailId = val.id
			// this.status = val.status
			this.taskId = val.taskId
			this.status = val.status
			if(val.type == 1){
				this.isEdit = false
			} else if(val.type == 2){
				this.isEdit = true
			}
			
			console.log(val.type)
			// this.initData()
		},
		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)
					}
				})
			},
			changeNav(val){
				this.activeIndex = val
				console.log(this.checkType)
				if(this.activeIndex == 1){
					if(this.checkType){
						if(this.checkType == 2){
							this.componentName = "dangerBigCheckDetail"
						} else if(this.checkType == 1){
							this.componentName="myDangerBigCheck"
						}
					} else{
						this.componentName = "dangerBigCheckDetail"
					}
				} else if(this.activeIndex == 2){
					this.componentName="allDangerBigCheck"
				}
			},
			queryAllResult(){
				this.sendRequest({
					url:'xmgl/acceptanceTableCheckTask/selectTaskCheckItemResultSummaryList',
					method:'post',
					data:{taskId: this.taskId},
					success:res=>{
						uni.hideLoading()
						
						console.log(res)
						
					}
				})
			},
			queryMyCheck(){
				this.sendRequest({
					url:'xmgl/acceptanceTableCheckTask/getAcceptanceTableCheckTaskInfo',
					method:'post',
					data:{taskId: this.taskId, userId: this.userId},
					success:res=>{
						uni.hideLoading()
						if(JSON.stringify(res.result.myCheckrecord) != "{}"){
							this.tableData = res.result.myCheckrecord.list
							this.tableData.forEach(item=>{
								item.isShow = true
								item.children.forEach(item2=>{
									item2.chooseType = '0'
									item2.children.forEach(item3=>{
										// console.log(item3.chooseType)
										if(item3.chooseType != '0'){
											item2.chooseType = ''
											return;
										}
									})
								})
							})
							this.tableData.forEach(item=>{
								item.chooseType = '0'
								item.children.forEach(item2=>{
									if(item2.chooseType != '0'){
										item.chooseType = ''
										return;
									}
								})
							})
							this.myCheckAllresult = JSON.parse(res.result.myCheckrecord.acceptanceTableUserCheckRecord.chooseResult)
							this.checkType = res.result.myCheckrecord.acceptanceTableUserCheckRecord.checkType
							 // 是否完成验收 1，未完成 2，完成
							this.checkData = JSON.parse(res.result.myCheckrecord.acceptanceTableUserCheckRecord.chooseValue)
							console.log(this.checkData)
						} else {
							this.componentType == 0
						}
						// console.log(this.tableData)
						this.allTableData = res.result.allList
						
						console.log(this.allTableData)
						this.changeNav(1)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.dangerbig-details{
	min-height: 100%;
	background: #ededed;
	.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: 90rpx;
		align-items: center;
		background: #fff;
		.nav-item{
			flex: 1;
			white-space: nowrap;
			height: 90rpx;
			text-align: center;
			box-sizing: border-box;
			line-height: 90rpx;
			font-size: 28rpx;
		}
		.active-nav{
			border-bottom: 4rpx solid #4396E7;
			height: calc(100% - 4rpx);
			color: #4396E7;
			width: 200rpx;
			margin: 0 auto;
		}
	}
	.detail-nav{
		width: 100%;
	}
}
</style>