<template>
	<view class="container">
		<view class="tabar">
			<view class="flex pad-20 fs-36" style="align-items: center;font-weight: bold;">
				<image class="wh-36" src="../../static/hoem/icon_back.png" @click="$wskj.goBack(1)"></image>
				<view>待办工单</view>
			</view>
			<view class="flex h-90">
				<view class="flex-center-center" style="flex: 1;" @click="onCz">全部</view>
				<view class="flex-center-center" style="flex: 1;" @click="show=true">
					<text>筛选</text>
					<image class="wh-18 ml-10" src="../../static/icon_sx.png"></image>
				</view>
			</view>
		</view>
		<view class="bgList">
			<scroll-view scroll-y style="height: 100%;">
				<view class="patrolRecordItem" v-for="(item,index) in list" :key="index">
					<view class="item">
						<view class="info">
							<image class="hread" src="../../static/hoem/ic_hread.png"></image>
							<view class="title">
								<view class="toiletName">{{item.toiletId}}公厕</view>
								<view class="devicesName">设备：{{item.equipmentId}}</view>
							</view>
						</view>
						<view class="toInspected" @click="actalert(item)">去补纸</view>
						<view class="patrolTime"> 设备编号：{{item.equipmentId}}</view>
						<view class="patrolTime"> 缺纸时间：{{item.nopaperTime}}</view>
					</view>
				</view>
			</scroll-view>
			<u-popup :show="show" mode="top" @close="show=false" @open="open">
				<view class="pad-20" style="background-color: white;">
					<view class="flex" style="align-items: center;">
						<view @click="showTimeStart=true" class="flex br-10 flex-between-center pad-20"
							style="background-color: #F8F4F4;flex: 1;color: #999;">
							<text>{{ timeStartValue==''?'起始日期':timeStartValue }}</text>
							<image class="wh-36" src="../../static/icon_time.png"></image>
						</view>
						<view class="mlr-20">
							至
						</view>
						<view @click="showTimeEnd=true" class="flex br-10 flex-between-center pad-20"
							style="background-color: #F8F4F4;flex: 1;color: #999;">
							<text>{{ timeEndValue==''?'结束日期':timeEndValue }}</text>
							<image class="wh-36" src="../../static/icon_time.png"></image>
						</view>
					</view>
					<input class=" br-36 mt-20  pad-20 fs-24" style="background: #F8F4F4;color: #999;"
						placeholder="请输入巡查人员姓名搜索" v-model="name" />
					<input class=" br-36 mt-20  pad-20 fs-24" style="background: #F8F4F4;color: #999;"
						placeholder="请输入公厕编号搜索" v-model="number" />
					<view class="flex mt-20" style="align-items: center;">
						<view @click="onCz" class="flex br-40 flex-center-center ptb-20 fs-28"
							style="background-color: #F8F4F4;flex: 1;color: #999;">
							<text>重置</text>
						</view>
						<view @click="onSx" class="flex br-40 flex-center-center ptb-20 fs-28 ml-20"
							style="background: linear-gradient( 90deg, #FCD4D2 0%, #FB262A 100%);;flex: 1;color: white;">
							<text>筛选</text>
						</view>
					</view>
				</view>
			</u-popup>
			<u-datetime-picker :show="showTimeStart" v-model="timeStart" mode="date" @close="showTimeStart=false"
				@cancel="showTimeStart=false" @confirm="onTimeStart"></u-datetime-picker>
			<u-datetime-picker :show="showTimeEnd" v-model="timeEnd" mode="date" @close="showTimeEnd=false"
				@cancel="showTimeEnd=false" @confirm="onTimeEnd"></u-datetime-picker>
				<u-popup :show="subshow" @close="subclose" @open="subopen" mode="center">
					<view class="deleteview">
						<image src="../../static/hoem/ic_close.png" mode="" @click.stop="subclose"></image>
						<view class="title">提示</view>
						<text>已经补纸完成！</text>
						<view class="btn" @click="subfn">我知道了</view>
						<view class="back"></view>
					</view>
				</u-popup>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showTimeStart: false,
				showTimeEnd: false,
				timeStart: Number(new Date()),
				timeEnd: Number(new Date()),
				timeStartValue: '',
				timeEndValue: '',
				name: '',
				number: '',
				show: false,
				list:[],
				subshow: false,
				actdata: {}
			}

		},
		onLoad() {
			
		},
		onShow() {
			this.getCheckList()
		},
		methods: {
			actalert(item){
				// this.subshow = true;
				// this.actdata = item;
				this.$wskj.to('/pages/index/addbuzhi?toiletId=' + item.toiletId+"&equipmentId="+ item.equipmentId+"&id="+ item.id)
			},
			subclose(){
				this.subshow = false;
			},
			subopen(){
				this.subshow = true;
			},
			subfn(){
				const params = {
					url: '/sun/mqtt/paperReplacement',
					data: {
						"id": this.actdata.id,
					},
				}
				this.$request(params).then(res => {
					this.$u.toast('添加成功')
					setTimeout(() => {
						uni.navigateBack({
							delta: 1
						})
					}, 800)
				})
			},
			//巡查记录列表
			getCheckList(){
				const params = {
					url: '/sun/mqtt/paperToBeReplenished',
					data: {
						inspectorId:uni.getStorageSync("userId"),
						status:'1',
						inspector: this.name,//巡查人员姓名
						toiletId: this.number,//公厕编号
						startTime: this.timeStartValue,//开始时间  
						endTime: this.timeEndValue,//结束时间
					},
				}
				this.$request(params).then(res => {
					this.list=res.data;
				})
			},
			onTimeStart(e) {
				this.showTimeStart = false
				this.timeStartValue = this.$wskj.timeFormat(e.value, 'yyyy-mm-dd')
				console.log(this.timeStartValue)
			},
			onTimeEnd(e) {
				this.showTimeEnd = false
				this.timeEndValue = this.$wskj.timeFormat(e.value, 'yyyy-mm-dd')
				console.log(this.timeEndValue)
			},
			onCz() {
				this.timeStartValue = ''
				this.timeEndValue = ''
				this.name = ''
				this.number = ''
				this.getCheckList()
				this.show = false;
			},
			onSx() {
				this.getCheckList()
				this.show = false;
			}
		}
	}
</script>

<style lang="scss">
	/deep/ .u-fade-enter-active {
		margin-top: 180rpx;
	}

	/deep/ .u-slide-down-enter-active {
		margin-top: 180rpx;
	}

	.container {
		background: linear-gradient(91deg, #FDEDEE 0%, #FFFFFF 100%);
		height: 100%;
		width: 100%;
		display: flex;
		flex-direction: column;
		padding-top: 60rpx;

		.bgList {
			flex: 1;
			overflow-y: auto;
			padding: 0 24rpx;
			background-color: #F8F4F4;
	.patrolRecordItem {
					position: relative;
					padding: 20rpx;
					margin-top: 20rpx;
					background: #FFFFFF;
					border-radius: 14rpx 14rpx 14rpx 14rpx;

					.item {
						margin-top: 20rpx;
						justify-content: space-between;

						.patrolPicture {
							margin-top: 10rpx;
							display: flex;
							font-size: 24rpx;
							color: #666666;

							.picture {

								width: 168rpx;
								height: 126rpx;
								border-radius: 5rpx 5rpx 5rpx 5rpx;
							}
						}

						.patrolTime {
							margin-top: 10rpx;
							font-size: 24rpx;
							color: #666666;
						}

						.toInspected {
							width: 125rpx;
							height: 54rpx;
							text-align: center;
							color: #fff;
							font-size: 24rpx;
							align-items: center;
							line-height: 54rpx;
							position: absolute;
							top: 0%;
							right: 0%;
							background: linear-gradient(90deg, #FCD4D2 0%, #FB262A 100%);
							border-radius: 0rpx 14rpx 0rpx 0rpx;
						}

						.info {
							display: flex;

							.title {
								padding-left: 10rpx;

								.toiletName {
									color: #333333;
									font-size: 28rpx;
									font-weight: 700;
								}

								.devicesName {
									color: #999999;
									font-size: 24rpx;
								}

							}

							.hread {
								width: 75rpx;
								height: 75rpx;
							}
						}
					}

				}
		}

		.tabar {
			display: flex;
			flex-direction: column;
			background: linear-gradient(91deg, #FDEDEE 0%, #FFFFFF 100%);
		}
	}
	
	/deep/.u-popup__content {
		border-radius: 20rpx 20rpx 20rpx 20rpx;
	}
	.deleteview {
		width: 634rpx;
		height: 439rpx;
		background: #FFFFFF;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		position: relative;
		padding: 18rpx 24rpx;
		box-sizing: border-box;
		text-align: center;
		text-align: center;
	
		.back {
			width: 634rpx;
			height: 156rpx;
			background: linear-gradient(180deg, #FDEDEE 0%, #FFFFFF 100%);
			border-radius: 20rpx 20rpx 20rpx 20rpx;
			position: absolute;
			left: 0;
			top: 0;
		}
	
		image {
			width: 40rpx;
			height: 40rpx;
			position: relative;
			z-index: 99;
			position: absolute;
			right: 24rpx;
			top: 18rpx;
		}
	
		.title {
			font-family: Microsoft YaHei, Microsoft YaHei;
			font-weight: bold;
			font-size: 30rpx;
			color: #333333;
			position: relative;
			z-index: 9;
			padding-top: 40rpx;
			margin-bottom: 90rpx;
		}
	
		text {
			display: block;
			font-family: Microsoft YaHei, Microsoft YaHei;
			font-weight: 400;
			font-size: 28rpx;
			color: #333333;
			position: relative;
			z-index: 9;
			margin-bottom: 73rpx;
		}
	
		.btn {
			position: relative;
			z-index: 9;
			font-family: Microsoft YaHei, Microsoft YaHei;
			font-weight: 400;
			font-size: 28rpx;
			color: #FFFFFF;
			width: 302rpx;
			height: 80rpx;
			line-height: 80rpx;
			background: linear-gradient(90deg, #FCD4D2 0%, #FB262A 100%);
			border-radius: 40rpx 40rpx 40rpx 40rpx;
			margin: 0 auto;
		}
	}
</style>