<template>
	<view class="dangerbig-list" :class="{popupShow:popupShow}">
		<headers class="fixedheader" :themeType="true" :showBack="true">
			<view class="headerName">
				新动火作业
			</view>
			
		</headers>
		<view :style="{ 'padding-top': statusBarHeight + 45 + 'px' }">
			<view class="searchBox">
				<form>
					<view class="uni-form-item">
						<input class="uni-input" name="searchName" v-model="searchVal" placeholder="请输入动火地点和动火部位或姓名检索"
							@input="handleInput" />
						<view class="screen" @click="screenData">筛选</view>
						<view class="screen" style="margin-top: 3px; margin-left: 5px;">
							<image src="/static/screenIcon.png" style="width: 15px;height: 15px"></image>
						</view>
					</view>
				</form>
			</view>

			<view class="list" v-if="workList && workList.length>0">
				<view class="list-item" v-for="(item,index) in workList" :key="index" @click="checkItem(item)">
					<view class="list-title">
						<!-- 未销项 -->
						<view>
							<text class="tag" v-if="item.hiddenDangerNum > 0">未销项{{item.hiddenDangerNum}}</text>
							作业票编号：{{item.workTicketCode}}
						</view>
						<!-- <view :class="{'status2': item.engineeringState === 2,'status4': item.engineeringState === 4}"> -->
						<!-- <view :class="{'status2': item.engineeringState === 2 || item.engineeringState === 3,'status4': item.engineeringState === 4}"> -->
						<view :class="{'status2': item.engineeringState !== 4, 'status4': item.engineeringState === 4}">
							<!-- {{item.engineeringState === 2 ? "在施" : item.engineeringState === 4 ? "已完工" : ""}} -->
							<!-- {{item.engineeringState === 1 ? "在施" : item.engineeringState === 2 ? "在施" : item.engineeringState === 3 ? "在施" : item.engineeringState === 4 ? "已完工" : ""}} -->
							{{item.engineeringState === 4 ? "已完工" : "在施"}}
						</view>
						<!-- <view :class="{'status1': item.finalAcceptanceStatus == 1,'status2': item.finalAcceptanceStatus == 2}">
							{{item.finalAcceptanceStatus == 1 ? "在施" : item.finalAcceptanceStatus == 2 ? "已完工" : ""}}
						</view> -->
					</view>
					<view class="list-content">
						<view class="list-info">
							<!-- 类别：{{item.engineeringTypeName}} -->
							作业负责人：{{item.assignmentPersonInChargeName}}
							<!-- <view class="info-status" v-if="item.issuperdanger">超危</view> -->
						</view>
					</view>
					
					<view class="list-content">
						<view class="list-info">
							作业时间：{{item.hotWorkExecutionBeginTime}} - {{item.hotWorkExecutionEndTime}}
						</view>
					</view>
					<view class="list-content">
						<view class="list-info">
							作业地点和动火部位：{{item.fireLocationAndFirePart}}
						</view>
					</view>
				</view>
				<view class="loadMoreBox" v-if="isLoadMore">
					<uni-load-more :status="loadStatus" iconType="auto"></uni-load-more>
				</view>
			</view>
			<view class="no-data" v-else>
				<image class="img" src="/static/noData.png"></image>
				<text class="txt">暂无数据</text>
			</view>
		</view>
		<!-- 筛选条件弹框 -->
		<uni-popup class="screenDialog" ref="screenShow" :maskClick="true" @change="closeMenu" :show="popupShow">

			<view class="screenContent">
				<scroll-view style="height: 100%;" scroll-y>
					<view class="closeIcon" @click="closeBtn">
						×
					</view>
					<view class="screenTitle">
						筛选条件
					</view>

					<view class="titleItem">作业实施时间</view>
					<view class="screenItem">
						<view class="screenI" style="width: 140px;position: relative;">
							<dateTimePicker v-if="startTime===''" placeholder="开始时间" fields="minute"
								@change="pickerChange($event,'startTime')" class="dateTimePicker">
							</dateTimePicker>
							<view v-else>{{startTime}}</view>
							<view v-if="startTime !=''" @click="showTimePicker(1)"
								style="position: absolute;top: -1vh;left: 34vw;font-size: 16px;">×</view>
						</view>
						<span style="color: gray;margin:6% 5px">一</span>
						<view class="screenI" style="width: 140px;position: relative;">
							<dateTimePicker v-if="endTime===''" placeholder="结束时间"
								fields="minute" @change="pickerChange($event,'endTime')"
								class="dateTimePicker">
							</dateTimePicker>
							<view v-else>{{endTime}}</view>
							<view v-if="endTime !=''" @click="showTimePicker(2)"
								style="position: absolute;top: -1vh;left: 34vw;font-size: 16px;">×</view>

						</view>
					</view>
					<view class="line"></view>

					<view class="footerBtn">
						<view class="foterLeft" @click="resettingBtn">
							重置
						</view>
						<view class="foterRight" @click="closeRed">
							确定
						</view>
					</view>
				</scroll-view>
			</view>

		</uni-popup>
	</view>
</template>

<script>
	import dateTimePicker from '@/components/dateTimePicker/index.vue'
	export default {
		components: {
			dateTimePicker,
		},
		data() {
			return {
				statusBarHeight: 0,
				searchVal: '',
				pageNo: 1,
				pageSize: 10,
				projectSn: "",
				listData:[],
				isLoadMore: false,
				loadStatus: 'more',
				workList: [],
				popupShow: false,
				startTime: '',
				endTime: '',
				statusBarHeight:{}
			}
		},
		onShow(){
			this.statusBarHeight = uni.getStorageSync('systemInfo').statusBarHeight;
			this.projectSn = JSON.parse(uni.getStorageSync('userInfo')).sn
			this.statusBarHeight = uni.getStorageSync('systemInfo').statusBarHeight;
		},
		onLoad(){
			this.projectSn = JSON.parse(uni.getStorageSync('userInfo')).sn
			// this.initData()
			this.getWorkList()
		},
		onReachBottom() {
			console.log(1)
			if(!this.isLoadMore){  //此处判断，上锁，防止重复请求
				this.isLoadMore=true
				this.pageNo+=1
				this.getWorkList()
			}
		},
		onPullDownRefresh() {
			console.log(2)
			this.pageNo=1
			this.listData=[]
			this.getWorkList()
		},
		methods:{
			getWorkList(isRefresh=false){
				let data = {
					pageNo: this.pageNo,
					pageSize: this.pageSize,
					projectSn: this.projectSn,
					hotWorkExecutionBeginTime_begin: this.startTime,
					hotWorkExecutionEndTime_end: this.endTime,
					keywords: this.searchVal	// todo
				}
				this.sendRequest({
					url:'xmgl/xzSpecialOperationFireSafetyNew/page',
					method:'get',
					data:data,
					success:res=>{
						uni.hideLoading()
						if(res.code==200){
						console.log("workList======================",res)
							// this.listData = res.result.records
							// this.workList=this.workList.concat(res.result)
							if(isRefresh){
								this.workList = res.result.records
							}else{
								this.workList=this.workList.concat(res.result.records)
							}
							if(res.result.records.length<this.pageSize){  //判断接口返回数据量小于请求数据量，则表示此为最后一页
								  this.isLoadMore=true                                             
								  this.loadStatus='nomore'
							}else{
								  this.isLoadMore=false
								  // that.loadStatus='more'
							}
							uni.stopPullDownRefresh()
						}
					}
				})
			},
			handleInput(e){
				this.searchVal = e.detail.value
				this.pageNo = 1
				this.workList = []
				this.getWorkList(true)
			},
			screenData(){
				this.$refs.screenShow.open()
				this.popupShow = true
			},
			//点击重新选择时间
			showTimePicker(type) {
				if (type == 1) {
					this.startTime = '';
				} else {
					this.endTime = '';
				}
			},
			pickerChange(e,type){
				console.log(e, '======')
				if(type==='startTime'){
					this.startTime = e.f3
				}else{
					this.endTime = e.f3
				}
			},
			closeMenu(e) {
				console.log("关闭！！！！",e)
				if(e.show == false){
					this.popupShow = false;
				}
			},
			closeRed() {
				this.$refs.screenShow.close()

				this.popupShow = false;
				this.getWorkList(true)
			},
			//关闭筛选
			closeBtn() {
				this.$refs.screenShow.close()

				this.popupShow = false;
				this.resettingBtn()
			},
			//重置
			resettingBtn() {
				this.startTime = ""
				this.endTime = ""
				this.searchVal = ''
				this.getWorkList(true)
			},
			checkItem(val){
				console.log(val)
				uni.navigateTo({
					url:'./newDetail?id='+val.id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.dangerbig-list{
	min-height: 100%;
	background: #F6F6F6;
	.fixedheader{
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		z-index: 2;
		.headerName{
			z-index: 1;
		}
	}
	
	.list{
		padding:20rpx 0;
		.list-item{
			background: #fff;
			margin-bottom: 20rpx;
			.list-title{
				padding: 20rpx;
				border-bottom: 2px solid #F6F6F6;
				display: flex;
				align-items: center;
				justify-content: space-between;
				.tag{
					background: #F0AD4E;
					color: #fff;
					padding: 4rpx 8rpx;
					font-size: 12px;
					margin-right: 20rpx;
					margin-left: -20rpx;
					height: 32rpx;
				}
				.status1{
					background: #2b8df3;
					color: #fff;
					padding: 4rpx 8rpx;
					font-size: 12px;
				}
				.status2{
					background: #F0AD4E;
					color: #fff;
					padding: 4rpx 8rpx;
					font-size: 12px;
				}
				.status3{
					background: #B22222;
					color: #fff;
					padding: 4rpx 8rpx;
					font-size: 12px;
				}
				.status4{
					background: #ccc;
					color: #fff;
					padding: 4rpx 8rpx;
					font-size: 12px;
				}
			}
			.list-info{
				display: flex;
				padding: 20rpx;
				font-size: 14px;
			}
			.info-status{
				padding:0 10rpx;
				border: 1px solid #DD524D;
				border-radius: 6rpx;
				color: #DD524D;
				margin-left: 10rpx;
			}
		}
	}
	.btn{
		height: 96rpx;
		width: 100%;
		line-height: 96rpx;
		text-align: center;
		background: #4181FE;
		color: #fff;
		position: fixed;
		bottom: 0;
		left: 0;
	}
	.no-data{
		text-align: center;
		.img{
			display: block;
			height: 200rpx;
			width: 200rpx;
			margin: 0 auto;
			margin-top: 560rpx;
			margin-bottom: 60rpx;
		}
		.txt{
			color: #CFC8CC;
		}
	}
}
.popupShow {
	overflow: hidden;
	position: fixed;
	width: 100%;
}
.searchBox {
	background-color: white;
}
.uni-form-item {
	position: relative;
	display: flex;
	font-size: 14px;
	/* .search-icon{
		position: absolute;
		top: 50%;
		right: 50rpx;
		transform: translateY(-50%);
	} */
}

.uni-input {
	border-radius: 20px;
	margin: 10px 10px;
	background-color: #f7f8fa;
	height: 35px;
	line-height: 30px;
	padding: 0 20px;
	font-size: 14px;
	width: 70%;
}

.screen {
	line-height: 50px;
	color: gray;
}
.screenDialog {
	position: absolute;
	// top: 11%;
	height: 95%;
	/* background: pink; */
	background: white;
	width: 100%;
	border-radius: 20px;
	margin-left: -4%;
	background-color: white;
	/* 设置为半透明的灰色 */
	z-index: 9;
	/* 设置一个较大的 z-index 值，保证遮罩层在最上层 */


	.closeIcon {
		float: right;
		font-size: 25px;
		color: gray;
		margin-right: 3%;
	}

	.screenTitle {
		text-align: center;
		margin-top: 4%;
		font-size: 18px;
		font-weight: 500;
	}

	.uni-popup__wrapper-box {
		height: 70vh;
		overflow: scroll;
		position: fixed;
		bottom: 0,
	}

	.screenContent {
		width: 100vw;
		height: 40%;
		// width: 90%;
		// margin: -65% 0%;
		overflow: scroll;
		// position: relative;
		// margin-top: 180%;
		border-radius: 20px 20px 0 0;
		// margin-left: -4%;
		background-color: white;
		padding-left: 10%;
		position: fixed;
		left: 0;
		bottom: 0;

		.titleItem {
			font-size: 14px;

			.regionText {
				display: inline-block;
				margin-left: 16%;
				width: 190px;
				white-space: nowrap;
				text-overflow: ellipsis;
				overflow: hidden;
			}
		}
	}

	.screenItem {
		display: flex;
		flex-wrap: wrap;

		.screenI {
			width: 100px;
			font-size: 12px;
			height: 30px;
			background: #f7f8fa;
			border-radius: 15px;
			text-align: center;
			line-height: 30px;
			color: gray;
			margin: 5% 0;
		}

		.screenText {
			width: 90px;
			font-size: 12px;
			height: 30px;
			background: #f7f8fa;
			border-radius: 15px;
			text-align: center;
			line-height: 30px;
			color: #000;
			margin: 5% 5% 5% 0%;
		}

		.active {
			width: 90px;
			font-size: 12px;
			height: 30px;
			background: #edf2fe;
			border-radius: 15px;
			text-align: center;
			line-height: 30px;
			color: #000;
			margin: 5% 5% 5% 0%;
			border: 1px solid #5181f6;
		}

		.screenTextClose {
			width: 90px;
			font-size: 12px;
			height: 30px;
			text-align: center;
			line-height: 30px;
			color: #000;
			margin: 5% 5% 5% 0%;
		}
	}

	.footerBtn {
		display: flex;
		text-align: center;
		line-height: 40px;
		margin-top: 2%;
		// margin-left: 6%;
		position: absolute;
		width: 100%;
		bottom: 20px;

		.foterLeft {
			width: 43%;
			background: #f6f7f8;
			height: 40px;
			border-top-left-radius: 20px;
			border-bottom-left-radius: 20px;
			color: #5181f6;
		}

		.foterRight {
			width: 43%;
			background: #5181f6;
			height: 40px;
			border-top-right-radius: 20px;
			border-bottom-right-radius: 20px;
			color: #fff;
		}
	}
	::v-deep .placeholder {
		padding-left: 40px;
	}
}
</style>
