<template>
	<view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
		<cus-header title='巡检记录'></cus-header>
		<div class="query">
			<div class="pre" @tap="selectQuery(1)">
				<span>{{statusText}}</span>
				<u-icon name="arrow-down-fill" color="#C0C4CC" size="20rpx"></u-icon>
			</div>
			<div class="pre" @tap="selectQuery(2)">
				<span>{{timeText}}</span>
				<u-icon name="arrow-down-fill" color="#C0C4CC" size="20rpx"></u-icon>
			</div>
			<div class="pre" @tap="selectQuery(3)">
				<span>{{placeText}}</span>
				<u-icon name="arrow-down-fill" color="#C0C4CC" size="20rpx"></u-icon>
			</div>
		</div>
		<div class="boxs" v-if="dataList.length">
			<div class="box" v-for="(item,index) in dataList" :key="index" @tap="toDetail(item)">
				<div class="top">
					<div class="left">{{item.inspectionSite||''}}</div>
					<div class="right">
						<div class="status" :class="{'zc':item.status===0,'yc':item.status===1}">{{item.status===0?'正常':'异常'}}</div>
						<image :src="imgBase+'operation/arrow_right.png'" mode="widthFix"></image>
					</div>
				</div>
				<div class="text">
					<div class="left">巡检时间</div>
					<p>{{item.startDate2||''}}</p>
				</div>
				<div class="text">
					<div class="left">巡检负责人</div>
					<p>{{item.inspector||''}}</p>
				</div>
			</div>
		</div>
		<template v-else>
			<page-empty :height="'calc(100vh - 200px)'"></page-empty>
		</template>
		<div class="bottom">
			<div class="btn" @tap="addRecord">添加巡检记录</div>
		</div>
		<u-picker :itemHeight="88" :show="show1" :columns="columns1" keyName="label" title="巡检状态"
			@cancel="show1=false" @confirm="e=>confirm(e,1)" :immediateChange="true"></u-picker>
		<u-datetime-picker :itemHeight="88" :show="show2" v-model="queryParams.month" mode="year-month" title="巡检时间"
			@cancel="show2=false" @confirm="e=>confirm(e,2)" :immediateChange="true" :minDate="minDate" :maxDate="maxDate"></u-datetime-picker>
		<u-picker :itemHeight="88" :show="show3" :columns="columns3" keyName="customerName" title="巡检地点"
			@cancel="show3=false" @confirm="e=>confirm(e,3)" :immediateChange="true"></u-picker>
	</view>
</template>

<script>
	import pageEmpty from '@/components/pageEmpty/index.vue'
	export default {
		components:{
			pageEmpty
		},
		data(){
			return {
				statusText:'巡检状态',
				timeText:'巡检时间',
				placeText:'巡检地点',
				queryParams:{
					page:1,
					limit:10,
					status:'',
					startDate:'',
					endDate:'',
					inspectionSite:''
				},
				show1:false,
				show2:false,
				show3:false,
				columns1:[[
					{value:0,label:'正常'},
					{value:1,label:'异常'}
				]],
				columns3:[],
				minDate:'',
				maxDate:'',
				isOver:false,
				dataList:[]
			}
		},
		onReachBottom() {
			if(this.isOver) return
			this.getList();
		},
		onShow() {
			let d = new Date();
			this.minDate = new Date(d.getFullYear()-3,d.getMonth()+1,d.getDate()).getTime();
			this.maxDate = new Date().getTime();
			this.init();
			this.getCustomerList();
			this.getList();
		},
		methods:{
			getCustomerList(){
				this.$api.get('/wms/project/getCustomerList',{page:1,limit:-1}).then(res=>{
					if(res.data.code!==0) return this.$showToast(res.data.msg)
					let list = res.data.data.map(d=>{return {id:d,customerName:d}})
					this.columns3 = [list]
				})
			},
			getList(){
				this.$api.get('/wms/order/inspection/page',this.queryParams).then(res=>{
					if(res.data.code===0){
						if(this.dataList.length<res.data.data.total){
							this.queryParams.page++;
							this.dataList = [...this.dataList,...res.data.data.list];
							this.dataList.forEach(d=>{
								d.startDate2 = new Date(d.startDate).Format('yyyy-MM-dd');
							})
						}else this.isOver = true
					}else this.$showModal(res.data.msg)
				});
			},
			init(){
				this.statusText = '巡检状态';
				this.timeText = '巡检时间';
				this.placeText = '巡检地点';
				this.queryParams = {
					page:1,
					limit:10,
					status:'',
					startDate:'',
					endDate:'',
					inspectionSite:''
				};
				this.isOver = false;
				this.dataList = [];
			},
			selectQuery(type){
				this['show'+type] = true;
			},
			confirm(e,type){
				this.init();
				if(type==1){
					this.statusText = e.value[0].label;
					this.queryParams.status = e.value[0].value;
					this.show1 = false;
				}else if(type==2){
					this.timeText = new Date(e.value).Format('yyyy-MM-dd');
					this.queryParams.startDate = new Date(e.value).Format('yyyy-MM-dd');
					this.queryParams.endDate = new Date(new Date().setDate(new Date(this.queryParams.startDate).getDate()+1)).Format('yyyy-MM-dd');
					this.show2 = false;
				}else if(type==3){
					this.placeText = e.value[0].customerName;
					this.queryParams.inspectionSite = e.value[0].id;
					this.show3 = false;
				}
				this.getList();
			},
			addRecord(){
				uni.navigateTo({
					url:'/pagesOperation/record/add'
				})
			},
			toDetail(item){
				uni.navigateTo({
					url:'/pagesOperation/record/detail?id='+item.id
				})
			}
		}
	}
</script>

<style scoped lang="less">
	.page{
		padding-bottom: 168rpx;
		background: #F4F8FB;
		
		.query{
			width: 100%;
			height: 88rpx;
			background: #FFFFFF;
			display: flex;
			.pre{
				width: calc(100% / 3);
				height: 88rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				span{
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 26rpx;
					color: #86909C;
					line-height: 26rpx;
					margin-right: 12rpx;
				}
			}
		}
	
		.boxs{
			padding: 0 24rpx;
			.box{
				background: #FFFFFF;
				border-radius: 16rpx;
				margin-top: 20rpx;
				padding: 36rpx 24rpx;
				.top{
					display: flex;
					align-items: center;
					justify-content: space-between;
					.left{
						width: calc(100% - 146rpx);
						padding-right: 20rpx;
						font-family: PingFang-SC, PingFang-SC;
						font-weight: bold;
						font-size: 30rpx;
						color: #1D2129;
						line-height: 30rpx;
						overflow: hidden;
						white-space: nowrap;
						text-overflow: ellipsis;
					}
					.right{
						display: flex;
						align-items: center;
						.status{
							width: 88rpx;
							height: 42rpx;
							border-radius: 6rpx;
							font-family: PingFang-SC, PingFang-SC;
							font-weight: bold;
							font-size: 26rpx;
							color: #FFFFFF;
							line-height: 42rpx;
							text-align: center;
							&.zc{
								background: #14CC8C;
							}
							&.yc{
								background: #FF4141;
							}
						}
						image{
							width: 24rpx;
							height: 24rpx;
							margin-left: 10rpx;
						}
					}
				}
				.text{
					margin-top: 36rpx;
					display: flex;
					align-items: center;
					.left{
						width: 168rpx;
						font-family: PingFangSC, PingFang SC;
						font-weight: 400;
						font-size: 26rpx;
						color: #86909C;
						line-height: 26rpx;
					}
					p{
						font-family: PingFangSC, PingFang SC;
						font-weight: 400;
						font-size: 26rpx;
						color: #1D2129;
						line-height: 26rpx;
					}
				}
			}
		}
			
		.bottom{
			width: 100%;
			height: 148rpx;
			padding: 20rpx 48rpx;
			box-sizing: border-box;
			background: #FFFFFF;
			position: fixed;
			bottom: 0;
			left: 0;
			z-index: 9;
			.btn{
				width: 100%;
				height: 88rpx;
				background: #2E69EB;
				border-radius: 16rpx;
				font-family: PingFang-SC, PingFang-SC;
				font-weight: bold;
				font-size: 32rpx;
				color: #FFFFFF;
				line-height: 88rpx;
				text-align: center;
			}
		}
	}
</style>