<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="tab" style="background-color: #F3F5F7;">
				<view class="tabType" @click="changeTab(item.id)" :class="checkedTab==item.id?'checkedTab':'noCheckTab'"
					v-for="item in checkedList" :key="item.id">
					{{item.checkedName}}
				</view>
			</view>
			<view class="uni-form-item" style="background-color: #ffffff;">
				<input class="uni-input" name="searchName" v-model="searchName" 
					placeholder="请输入编号" />
				<!-- <uni-icons2 class="search-icon" type="search" @click="loadData"></uni-icons2> -->
				<button class="mini-btn" type="primary" size="mini" @click="loadData">搜索</button>
			</view>
		</view>
		<view :style="{ 'padding-top': (statusBarHeight + 110) * 2 + 'rpx' }">
			<view v-if="workList && workList.length>0">
				<view class="list" v-if="checkedTab == 1 || checkedTab == 2">
					<view class="list-item" v-for="(item,index) in workList" :key="index" @click="checkItem(item)">
						<view class="list_index">
							{{index + 1}}
						</view>
						<view class="list-title">
							<!-- 未销项 -->
							<view>
								<!-- <text class="tag" v-if="item.hiddenDangerNum > 0">未销项{{item.hiddenDangerNum}}</text> -->
								装置/单元：{{item.deviceUnitName}}
							</view>
							<!-- <view :class="{'status2': item.engineeringState !== 4, 'status4': item.engineeringState === 4}">
								{{item.engineeringState === 4 ? "已完工" : "在施"}}
							</view> -->
						</view>
						<view class="list-content">
							<!-- <view class="list-info">
								类别：{{item.workCategory ? workCategoryList[item.workCategory - 1].workCategoryName : '--'}}
							</view> -->
							<view class="list-info">
								<view class="">
									编号
								</view>
								<view class="">
									{{item.num}}
								</view>
							</view>
							<view class="list-info">
								<view class="">
									承包商：
								</view>
								<view class="">
									{{item.contractorName}}
								</view>
							</view>
							<view class="list-info">
								<view class="">
									填报时间：
								</view>
								<view class="">
									{{item.reportingTime}}
								</view>
							</view>
							<!-- <view class="list-info">
								<view class="">
									承包模式
								</view>
								<view class="">
									{{item.contractingModel ? workCategoryList[item.contractingModel - 1].workCategoryName : ''}}
								</view>
							</view> -->
							<view class="list-info">
								<view class="">
									填报人：
								</view>
								<view class="">
									{{item.reportingPersonName}}
								</view>
							</view>
							<view class="list-info">
								<view class="">
									联系电话：
								</view>
								<view class="">
									{{item.contactNumber}}
								</view>
							</view>
						</view>
					</view>
					<view class="loadMoreBox" v-if="isLoadMore">
						<uni-load-more :status="loadStatus" iconType="auto"></uni-load-more>
					</view>
				</view>
				<view class="list" v-if="checkedTab == 3 || checkedTab == 4">
					<view class="summation">
						<view class="summation_title">
							合计
						</view>
						<view class="summation_main">
							<view>
								<view>
									0
								</view>
								<view>
									本周管道防腐量(㎡)
								</view>
							</view>
							<view>
								<view>
									0
								</view>
								<view>
									本周管道防腐量(㎡)
								</view>
							</view>
							<view>
								<view>
									0
								</view>
								<view>
									本周管道防腐量(㎡)
								</view>
							</view>
							<view>
								<view>
									0
								</view>
								<view>
									本月钢结构防腐量(吨)
								</view>
							</view>
						</view>
					</view>
					<view class="list-item list-item_up" v-for="(item,index) in workList" :key="index">
						<view class="list_index">
							{{index + 1}}
						</view>
						<view class="list-title">
							<view>
								<!-- <text class="tag" v-if="item.hiddenDangerNum > 0">未销项{{item.hiddenDangerNum}}</text> -->
								装置/单元：{{item.deviceUnitName}}
							</view>
							<view style="flex-shrink: 0;">
								{{item.reportingTime}}
							</view>
						</view>
						<view class="list-content">
							<view class="list-info">
								<view class="">
									承包商：
								</view>
								<view class="">
									{{item.contractorName}}
								</view>
							</view>
							<view class="list-info" v-if="checkedTab == 3">
								<view class="">
									本周管道防腐量(平方米)：
								</view>
								<view class="">
									{{item.weekPipelineSum}}
								</view>
							</view>
							<view class="list-info" v-else-if="checkedTab == 4">
								<view class="">
									本月管道防腐量(平方米)：
								</view>
								<view class="">
									{{item.monthPipelineSum}}
								</view>
							</view>
							<view class="list-info" v-if="checkedTab == 3">
								<view class="">
									本周钢结构防腐量(吨)：
								</view>
								<view class="">
									{{item.weekSteelSum}}
								</view>
							</view>
							<view class="list-info" v-else-if="checkedTab == 4">
								<view class="">
									本月钢结构防腐量(吨)：
								</view>
								<view class="">
									{{item.monthSteelSum}}
								</view>
							</view>
							<view class="list-info">
								<view class="">
									累计管道防腐里(平方米)：
								</view>
								<view class="">
									{{item.totalPipelineSum}}
								</view>
							</view>
							<view class="list-info">
								<view class="">
									累计钢结构防腐量(吨)：
								</view>
								<view class="">
									{{item.totalSteelSum}}
								</view>
							</view>
						</view>
					</view>
					<view class="loadMoreBox" v-if="isLoadMore">
						<uni-load-more :status="loadStatus" iconType="auto"></uni-load-more>
					</view>
				</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" mask-background-color="rgba(0,0,0,0)" type="center" 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: 280rpx; position: relative">
							<dateTimePiccker v-if="inspectStartTime === ''" :placeholder="startTime" :start="startTime"
								fields="minute" @change="bindPickerChangeStart($event, 'startTime')"
								class="dateTimePiccker">
							</dateTimePiccker>
							<view v-else>{{ inspectStartTime }}</view>
							<view v-if="inspectStartTime != ''" @click="showTimePicker(1)" style="
			    position: absolute;
			    top: -1vh;
			    left: 34vw;
			    font-size: 30rpx;
			  ">×</view>
						</view>
						<span style="color: gray; margin: 6% 10rpx">一</span>
						<view class="screenI" style="width: 280rpx; position: relative">
							<dateTimePiccker v-if="inspectEndTime === ''" :placeholder="startTime" :start="startTime"
								fields="minute" @change="bindPickerChangeEnd($event, 'startTime')"
								class="dateTimePiccker">
							</dateTimePiccker>
							<view v-else>{{ inspectEndTime }}</view>
							<view v-if="inspectEndTime != ''" @click="showTimePicker(2)" style="
			    position: absolute;
			    top: -1vh;
			    left: 34vw;
			    font-size: 30rpx;
			  ">×</view>
						</view>
					</view>
					<view class="line"></view>
					<view class="footerBtn">
						<view class="foterLeft" @click="resettingBtn"> 重置 </view>
						<!-- <view class="foterRight" @click="screenShow=false">
						完成
					</view> -->
						<view class="foterRight" @click="closeRed">
							查看{{ listNum }}条记录
						</view>
					</view>
				</scroll-view>
			</view>

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

<script>
	import dateTimePiccker from "@/components/dateTimePicker/index.vue";
	export default {
		components: {
			dateTimePiccker,
		},
		data() {
			return {
				statusBarHeight: 0,
				pageNo: 1,
				pageSize: 10,
				projectSn: "",
				startTime: "请选择日期",
				listData: [],
				isLoadMore: false,
				loadStatus: 'more',
				workList: [],
				workCategoryList: [{
					id: 1,
					workCategoryName: "EPC"
				}, {
					id: 2,
					workCategoryName: "E+P+C"
				}],
				checkedTab: 1,
				checkedList: [{
					id: 1,
					checkedName: "周计划"
				}, {
					id: 2,
					checkedName: "月计划"
				}],
				searchName: "",
				popupShow: false,
				inspectStartTime: "",
				inspectEndTime: "",
				listNum: 0,
			}
		},
		onShow() {
			this.statusBarHeight = uni.getStorageSync('systemInfo').statusBarHeight;
			this.projectSn = JSON.parse(uni.getStorageSync('userInfo')).sn
		},
		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: {
			//筛选开始时间
			bindPickerChangeStart(e, type) {
				if (type == "startTime") {
					this.inspectStartTime = e.f3;
				}
				this.loadData();
			},
			//筛选结束时间
			bindPickerChangeEnd(e, type) {
				console.log(e)
				if (type == "startTime") {
					this.inspectEndTime = e.f3;
				}
				// if (this.inspectStartTime && this.inspectEndTime) {
				// 	this.loadData();
				// }
				this.loadData();
			},
			//点击重新选择时间
			showTimePicker(type) {
				if (type == 1) {
					this.inspectStartTime = "";
				} else {
					this.inspectEndTime = "";
				}
			},
			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;
				this.resettingBtn();
			},
			//重置
			resettingBtn() {
				this.inspectStartTime = "";
				this.inspectEndTime = "";
				this.loadData();
			},
			closeRed() {
				this.$refs.screenShow.close();

				this.popupShow = false;
			},
			//点击打开筛选
			screenData() {
				this.$refs.screenShow.open();

				this.popupShow = true
			},
			loadData() {
				this.pageNo = 1
				this.workList = []
				if (this.checkedTab == 1 || this.checkedTab == 2) {
					this.getWorkList()
				} else if (this.checkedTab == 3 || this.checkedTab == 4) {
					this.getAnticorrosionEntrustCountList();
				}
			},
			searchFile(e) {
				this.searchName = e.detail.value
			},
			getAnticorrosionEntrustCountList() {
				let data = {
					pageNo: this.pageNo,
					pageSize: this.pageSize,
					projectSn: this.projectSn,
					num: this.searchName,
					levelType: this.checkedTab == '3' ? 2 : 1,
					reportingTime_begin: this.inspectStartTime,
					reportingTime_end: this.inspectEndTime,
				}
				this.sendRequest({
					url: 'xmgl/anticorrosionEntrust/count',
					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)
							this.workList = this.workList.concat(res.result.records)
							this.listNum = res.result.total;
							if (res.result.records.length < this.pageSize) { //判断接口返回数据量小于请求数据量，则表示此为最后一页
								this.isLoadMore = true
								this.loadStatus = 'nomore'
							} else {
								this.isLoadMore = false
								// that.loadStatus='more'
							}
							uni.stopPullDownRefresh()
						}
					}
				})
			},
			//切换tab
			changeTab(type) {
				this.checkedTab = type;
				this.loadData()
			},
			getWorkList() {
				let data = {
					pageNo: this.pageNo,
					pageSize: this.pageSize,
					projectSn: this.projectSn,
					contractorName: this.searchName,
					levelType: this.checkedTab == '1' ? 2 : 1,
					reportingTime_begin: this.inspectStartTime,
					reportingTime_end: this.inspectEndTime,
				}
				this.sendRequest({
					url: 'xmgl/anticorrosionPlanApplication/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)
							this.workList = this.workList.concat(res.result.records)
							this.listNum = res.result.total;
							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: './detail?id=' + val.id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep .placeholder {
		padding-left: 80rpx;
	}

	.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 值，保证遮罩层在最上层 */

		.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: 100vw;
			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;
			left: 0;
			bottom: 0;

			.titleItem {
				font-size: 28rpx;

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

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

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

			.screenText {
				width: 180rpx;
				font-size: 24rpx;
				height: 60rpx;
				background: #f7f8fa;
				border-radius: 30rpx;
				text-align: center;
				line-height: 60rpx;
				color: #000;
				margin: 5% 5% 5% 0%;
			}

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

			.screenTextClose {
				width: 180rpx;
				font-size: 24rpx;
				height: 60rpx;
				text-align: center;
				line-height: 60rpx;
				color: #000;
				margin: 5% 5% 5% 0%;
			}
		}

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

	.tab {
		// width: 100%;
		overflow: auto;
		height: 90rpx;
		text-align: center;
		// box-shadow: 0 0 20rpx rgba(194, 194, 194, 0.5);
		padding: 0 40rpx;
		display: flex;
		align-items: center;
		// justify-content: space-between;

		.tabType {
			// width: 33%;
			min-width: 180rpx;
			line-height: 86rpx;
			position: relative;
			// border-bottom: 2rpx solid rgba(194, 194, 194, 0.2);
		}

		.checkedTab::after {
			content: '';
			width: 120rpx;
			height: 4rpx;
			position: absolute;
			left: 50%;
			bottom: 0;
			transform: translateX(-50%);
			// color: #4181FE;
			// border-bottom: 4rpx solid;
			background: linear-gradient(to right, #2B8DF3, #ffffff);
		}

		.noCheckTab {
			padding-bottom: 4rpx;
		}
	}

	.uni-form-item {
		position: relative;
		// width: 100%;
		// padding: 0 20rpx;
		// height: 60rpx;
		display: flex;
		margin: 24rpx 40rpx;
		background-color: #FFFFFF;
		border-radius: 48rpx;
		justify-content: space-between;

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

		.mini-btn {
			width: 120rpx;
			font-size: 24rpx;
			border-radius: 100rpx;
			margin: 0;
		}
	}

	.uni-input {
		flex: 1;
		border-radius: 30rpx;
		// margin: 20rpx 20rpx;
		background-color: #ffffff;
		height: 60rpx;
		line-height: 60rpx;
		padding: 0 40rpx;
		font-size: 28rpx;
		width: 65%;
	}

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

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

			:deep( .headerBox ){
				background-color: transparent !important;
			}

			.headerName {
				z-index: 1;
				background-color: transparent !important;
			}

			: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;

			.summation {
				width: 100%;
				background: linear-gradient(180deg, rgba(47, 143, 243, 0.3) 0%, rgba(47, 143, 243, 0) 100%);
				border-radius: 16rpx;
				padding: 16rpx 32rpx;
				margin-bottom: 32rpx;

				.summation_title {
					font-size: 30rpx;
					position: relative;
					color: #171717;
				}

				.summation_title::before {
					content: '';
					width: 4rpx;
					height: 28rpx;
					background: #2F8FF3;
					position: absolute;
					left: -10rpx;
					top: 50%;
					transform: translateY(-50%);
				}

				.summation_main {
					display: flex;
					flex-wrap: wrap;
					padding-bottom: 20rpx;

					>view {
						width: 50%;
						display: flex;
						flex-direction: column;
						align-items: center;
						justify-content: center;
						margin-top: 32rpx;

						>view:first-child {
							font-size: 30rpx;
							color: #444444;
						}

						>view:last-child {
							color: #707070;
							font-size: 26rpx;
						}
					}
				}
			}

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

				.list_index {
					color: white;
					font-size: 24rpx;
					position: absolute;
					left: 10rpx;
					z-index: 1;
				}

				.list-title::before {
					content: '';
					border-top: 30rpx solid #5181F6;
					border-right: 30rpx solid transparent;
					border-left: 30rpx solid #5181F6;
					border-bottom: 30rpx solid transparent;
					border-radius: 10rpx 0 0 0;
					position: absolute;
					left: 4rpx;
				}

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

					.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: 0 10rpx;
					border: 1px solid #DD524D;
					border-radius: 6rpx;
					color: #DD524D;
					margin-left: 10rpx;
				}
			}

			.list-item_up {
				.list-info {
					>view:first-child {
						width: 330rpx;
					}
				}
			}
		}

		.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>