<template>
	<view class="dangerbig-list">
		<view class="fixedheader">
			<headers :showBack="true">
				<view class="headerName">
					试压包管理
				</view>
				<!-- <view class="right" @click="screenData()">
					<image class="scancode" src="@/static/bthgIcon/screen.png" mode=""></image>
				</view> -->
			</headers>
			<view class="searchBox">
				<view class="uni-form-item">
					<input class="uni-input" name="searchName" @input="handleInput" v-model="searchName"
						placeholder="请搜索试压包名称" />
					<!-- <button  class="mini-btn" type="primary" size="mini"  @click="loadData">搜索</button> -->
					<!-- <view class="screen" @click="screenData">筛选</view>
					<view class="screen" style="margin-top: 6rpx;
						margin-left: 10rpx; margin-right: 10rpx;">
						<image src="/static/screenIcon.png" style="width: 30rpx;height: 30rpx">
						</image>
					</view> -->
				</view>
			</view>
		</view>
		<view :style="{ 'padding-top': statusBarHeight + (100 * 2)+ 'rpx' }">
			<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.testPressurePackageName}}
						</view>
						<!-- <view :class="{'status2': item.engineeringState !== 4, 'status4': item.engineeringState === 4}">
							{{item.engineeringState === 4 ? "已完工" : "在施"}}
						</view> -->
					</view>
					<view class="list-content">
						<view class="list-info">
							<view>
								试压包编号：
							</view>
							<view>
								{{item.testPressurePackageNumber}}
							</view>
						</view>
						<view class="list-info">
							<view>
								试验压力：
							</view>
							<view>
								{{item.testPressure}}
							</view>
						</view>
						<view class="list-info">
							<view>
								设计压力：
							</view>
							<view>
								{{item.designPressure}}
							</view>
						</view>
						<view class="list-info">
							<view>
								试压时间：
							</view>
							<view>
								{{item.pressureApplicationTime}}
							</view>
						</view>
						<!-- <view class="list-info">
							图片：<view class="download" v-for="item in item.image" :key="item.id">
								<image :src="item.url.includes('http://') ? item.url : url_config+'image/'+item.url"
									class="img"
									@click="previewImage(item.url.includes('http://') ? item.url : url_config+'image/'+item.url)">
								</image>
							</view>	
						</view> -->
						<!-- <view class="info-status" v-if="item.issuperdanger">超危</view> -->
					</view>
					<view class="btn_detail">查看明细</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>

			<!-- 筛选条件弹框 -->
			<uni-popup class="screenDialog" mask-background-color="rgba(0,0,0,0)" type="right" 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> -->
					<scroll-view class="g-picker-list" scroll-y="true">
						<view class="g-picker-item" v-for="(col, inx) in listData" :key="inx"
							@click="checkItemCheck(col, inx)">
							<view :class="['g-picker-item_label', col._check ? 'g-picker-item--actived' : '']"
								:style="{'background-color': col._check ? '#E7F2FF' : 'white'}">{{ col.deviceUnitName }}
							</view>
							<!-- <u-icon class="g-picker-item_icon" v-show="col._check" name="checkbox-mark"
									color="#E7F2FF"></u-icon> -->
						</view>
					</scroll-view>
					<!-- <view class="footerBtn">
							<view class="foterLeft" @click="closeBtn">
								取消
							</view>
							<view class="foterRight" @click="closeRed">
								确认
							</view>
						</view> -->
					<!-- </scroll-view> -->
				</view>

			</uni-popup>
		</view>

	</view>
</template>

<script>
	import tkiTree from "@/components/tki-tree_up/tki-tree.vue"
	import {
		isJSON
	} from '@/utils/tool.js'
	export default {
		components: {
			tkiTree
		},
		data() {
			return {
				statusBarHeight: 0,
				pageNo: 1,
				pageSize: 10,
				projectSn: "",
				oldListData: [],
				listData: [],
				isLoadMore: false,
				loadStatus: 'more',
				workList: [],
				levelList: [{
					id: 1,
					workCategoryName: "一级"
				}, {
					id: 2,
					workCategoryName: "二级"
				}, {
					id: 3,
					workCategoryName: "三级"
				}, {
					id: 4,
					workCategoryName: "普通"
				}],
				searchName: "",
				popupShow: false,
				deviceUnitId: "",
				schemeTypeList: [{
					id: 1,
					title: "施工组织设计",
				}, {
					id: 2,
					title: "施工技术方案",
				}, {
					id: 3,
					title: "施工技术措施",
				}], // 方案类型
			}
		},
		onShow() {
			this.statusBarHeight = uni.getStorageSync('systemInfo').statusBarHeight;
			this.projectSn = JSON.parse(uni.getStorageSync('userInfo')).sn
		},
		onLoad(option) {
			this.detailId = option.detailId;
			this.deviceUnitId = option.deviceUnitId;
			this.projectSn = JSON.parse(uni.getStorageSync('userInfo')).sn
			// this.initData()
			this.getWorkList()
			this.getConstructionTree();
		},
		onReachBottom() {
			console.log(1)
			if (!this.isLoadMore) { //此处判断，上锁，防止重复请求
				this.isLoadMore = true
				this.pageNo += 1
				this.getWorkList()
			}
		},
		onPullDownRefresh() {
			console.log(2)
			this.pageNo = 1
			this.getWorkList();
		},
		methods: {
			checkItemCheck(col, inx) {
				this.listData.forEach(item => {
					if (item.id == col.id) {
						col._check = !col._check;
						this.deviceUnitId = col.id;
						this.handleInput();
					} else {
						item._check = false;
					}
				});
			},
			//点击打开筛选
			screenData() {
				this.$refs.screenShow.open();

				this.popupShow = true
			},

			closeMenu(e) {
				console.log("关闭！！！！", e)
				if (e.show == false) {
					// this.$refs.screenShow.close()
					this.popupShow = false;
					// this.resettingBtn()
				}
			},
			//关闭筛选
			closeBtn() {
				this.$refs.screenShow.close()
				this.popupShow = false;
			},
			closeRed() {
				this.$refs.locationTree._confirm()
				this.$refs.screenShow.close()
				this.popupShow = false;
			},
			//预览图片
			previewImage(url) {
				uni.previewImage({
					urls: [url]
				})
			},
			handleInput() {
				this.pageNo = 1;
				this.workList = [];
				this.getWorkList();
			},
			getConstructionTree() {
				let data = {
					projectSn: this.projectSn,
					pageNo: 1,
					pageSize: -1,
					seeI: 1,
				}
				this.sendRequest({
					url: 'xmgl/deviceUnit/page',
					method: 'get',
					data: data,
					success: res => {
						uni.hideLoading()
						if (res.code == 200) {
							console.log("workList======================", res)
							this.listData = [{
									id: "",
									deviceUnitName: "全部",
									deviceUnitNo: "",
									_check: true,
								},
								...res.result.records
							].map(item => {
								if (!item._check) {
									this.$set(item, '_check', false)
								}

								return {
									...item,
								}
							});
						}
					}
				})
			},
			getWorkList() {
				let data = {
					pageNo: this.pageNo,
					pageSize: this.pageSize,
					projectSn: this.projectSn,
					search: this.searchName,
					// deviceUnitId: this.deviceUnitId,
					deviceUnitId: this.deviceUnitId,
					pipelineInformationId: this.detailId,
					// isWinter: 0
				}
				this.sendRequest({
					url: 'xmgl/pipelinePressureTestBag/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)
							const newResult = res.result.records.map(item => {
								return {
									...item,
									image: isJSON(item.file) ? JSON
										.parse(item.file) : [],
								}
							})
							this.workList = this.workList.concat(newResult)
							if (res.result.records.length < this.pageSize) { //判断接口返回数据量小于请求数据量，则表示此为最后一页
								this.isLoadMore = true
								this.loadStatus = 'nomore'
							} else {
								this.isLoadMore = false
								// that.loadStatus='more'
							}
							uni.stopPullDownRefresh()
						}
					}
				})
			},

			checkItem(val) {
				console.log(val)
				uni.navigateTo({
					url: '../pressureTestBagManage/detail?id=' + val.id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.g-picker-list {
		min-height: 20vh;
		max-height: 50vh;
		// overflow-y: scroll;

		.g-picker-item {
			position: relative;
			width: 100%;
			height: 80rpx;

			.g-picker-item_label {
				width: 100%;
				margin: 0 auto;
				text-align: center;
				line-height: 80rpx;
				white-space: nowrap;
				text-overflow: ellipsis;
				overflow: hidden;
				padding: 0 20rpx;
			}

			.g-picker-item--actived {
				font-weight: 600;
				position: relative;
			}

			.g-picker-item--actived::after {
				content: '';
				position: absolute;
				top: 0;
				right: 0;
				background-color: #228AFC;
				width: 20rpx;
				height: 100%;
			}

			.g-picker-item_icon {
				position: absolute;
				top: 50%;
				right: 40rpx;
				transform: translateY(-50%);
			}
		}
	}

	.screenDialog {

		// position: absolute;
		// // top: 11%;
		// // height: 95%;
		// /* background: pink; */
		// background: white;
		// width: 100%;
		// border-radius: 40rpx;
		// margin-left: -4%;
		// background-color: white;
		// /* 设置为半透明的灰色 */
		// z-index: 9;
		/* 设置一个较大的 z-index 值，保证遮罩层在最上层 */
		>:deep( view ){
			background-color: rgba(0, 0, 0, 0) !important;
		}

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

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

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

		.screenContent {
			width: 30vw;
			// height: 70%;
			// width: 90%;
			// margin: -65% 0%;
			overflow: scroll;
			// position: relative;
			// margin-top: 180%;
			// border-radius: 40rpx 40rpx 0 0;
			// margin-left: -4%;
			background-color: white;
			// padding-left: 10%;
			position: fixed;
			right: 0;
			top: 88rpx;

			.titleItem {
				font-size: 28rpx;

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

		.footerBtn {
			display: flex;
			text-align: center;
			line-height: 80rpx;
			margin-top: 2%;
			margin-left: 6%;

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

			.foterRight {
				width: 43%;
				background: #5181f6;
				height: 80rpx;
				border-top-right-radius: 40rpx;
				border-bottom-right-radius: 40rpx;
				color: #fff;
			}
		}

	}

	.searchBox {
		// background-color: white;
		background-color: #F3F5F7;
	}

	.uni-form-item {
		position: relative;
		display: flex;
		align-items: center;
		font-size: 28rpx;
		/* .search-icon{
			position: absolute;
			top: 50%;
			right: 50rpx;
			transform: translateY(-50%);
		} */
	}

	.uni-input {
		border-radius: 40rpx;
		margin: 20rpx;
		// background-color: #f7f8fa;
		background: #FFFFFF;
		height: 70rpx;
		line-height: 60rpx;
		padding: 0 40rpx;
		font-size: 28rpx;
		flex: 1;
	}

	.screen {
		line-height: 100rpx;
		color: gray;
	}

	.flex {
		display: flex;
		align-items: center;
	}

	.content {
		padding: 0px 30rpx 20rpx;
		box-sizing: border-box;
		width: 100%;
	}

	.download {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		margin-top: 10rpx;
		// justify-content: center;
	}

	.img {
		width: 120rpx;
		height: 120rpx;
	}

	.dangerbig-list {
		min-height: 100%;
		// background: #F6F6F6;
		background-color: #F3F5F7;

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

			.headerName {
				z-index: 1;
			}

			:deep( .headerBox ){
				background-color: #F3F5F7;
			}

			:deep( .right ){
				font-size: 24rpx;
				position: absolute;
				right: 20rpx;
				top: 50%;
				z-index: 4;
				transform: translateY(-50%);

				.scancode {
					width: 44rpx;
					height: 44rpx;
				}
			}
		}

		.list {
			padding: 20rpx 0;
			margin: 0 20rpx;

			.list-item {
				background: #fff;
				margin-bottom: 20rpx;
				padding: 20rpx 0;
				position: relative;
				border-radius: 24rpx;

				.list-title {
					padding: 10rpx 40rpx;
					// border-bottom: 4rpx solid #F6F6F6;
					display: flex;
					align-items: center;
					justify-content: space-between;
					color: #1A1A1A;

					.tag {
						background: #F0AD4E;
						color: #fff;
						padding: 4rpx 8rpx;
						font-size: 24rpx;
						margin-right: 20rpx;
						margin-left: -20rpx;
						height: 32rpx;
					}

					.status1 {
						background: #2b8df3;
						color: #fff;
						padding: 4rpx 8rpx;
						font-size: 24rpx;
					}

					.status2 {
						background: #F0AD4E;
						color: #fff;
						padding: 4rpx 8rpx;
						font-size: 24rpx;
					}

					.status3 {
						background: #B22222;
						color: #fff;
						padding: 4rpx 8rpx;
						font-size: 24rpx;
					}

					.status4 {
						background: #ccc;
						color: #fff;
						padding: 4rpx 8rpx;
						font-size: 24rpx;
					}
				}

				.list-content {
					margin-top: 14rpx;
					padding-bottom: 20rpx;
					border-bottom: 1px dashed #CCCCCC;
				}

				.list-info {
					display: flex;
					padding: 10rpx 40rpx;
					margin-left: 40rpx;
					font-size: 28rpx;
					// border-bottom: 2rpx solid #F6F6F6;
					color: #444444;
					position: relative;

					>view:first-child {
						width: 220rpx;
					}

					>view:last-child {
						flex: 1;
						word-break: break-all;
					}
				}

				.list-info::after {
					content: '';
					width: 15rpx;
					height: 15rpx;
					background-color: #007BF5;
					border-radius: 50%;
					border: 10rpx solid #EBF0FA;
					position: absolute;
					left: 0;
					top: 14rpx;
					// top: 50%;
					// transform: translateY(-50%);
				}

				.info-status {
					padding: 3rpx 16rpx;
					// border: 1px solid #DD524D;
					// border-radius: 6rpx;
					// color: #DD524D;
					margin-left: 10rpx;
					border-radius: 30rpx;
					background-color: #DD524D;
					color: white;
				}

				.btn_detail {
					// background-color: #4181FE;
					// color: white;
					// padding: 3rpx 16rpx;
					// border-radius: 30rpx;
					// position: absolute;
					// bottom: 16rpx;
					// right: 16rpx;
					padding: 20rpx 40rpx;
					font-size: 26rpx;
					color: #FF0000;
					text-align: right;

					.arrowright {
						color: #FF0000 !important;
						font-size: 24rpx !important;
					}
				}
			}
		}

		.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;
			}
		}
	}
</style>