<template>
	<view class="fullHeight">
		<levitatedsphere :x="100" :y="80"></levitatedsphere>
		<headers :showBack="true">
			<view class="headerName">
				车辆冲洗抓拍记录
			</view>
		</headers>
		<!-- <view class="menuBox">
			<view class="menuItem" @click="changeMenu(0)" :class="tabIndex==0?'active':''">
				进出记录
			</view>
			<view class="menuItem" @click="changeMenu(1)" :class="tabIndex==1?'active':''">
				黑白名单
			</view>
		</view> -->
		<!-- <view class="" v-if="tabIndex==0"> -->
			<view class="selectContent selectContent2">
				<!-- <input class="selectVideoBox" type="text" confirm-type="search" v-model="carNumber" placeholder="搜索车牌号" @confirm="inOutList=[];getInOutList()" /> -->
				<picker :range="alarmTypeArr" @change="changeCarType" :value="isBlack">
					<view class="selectVideoBox">
						<text class="videoName">{{alarmTypeArr[isBlack]}}</text>
						<uni-icons2 class="arrow" type="arrowdown" size="15"></uni-icons2>
					</view>
				</picker>
				<picker mode="date" @change="changeDate" :value="searchDate" style="margin-left:30rpx">
					<view class="selectVideoBox">
						<text class="videoName">{{searchDate}}</text>
						<uni-icons2 class="arrow" type="arrowdown" size="15"></uni-icons2>
					</view>
				</picker>
			</view>
			<view class="blockBox" v-for="(item,index) in inOutList" :key="index">
				<view class="alarmItem">
					<text class="label">车牌号：</text><text class="value">{{item.carNumber}}</text>
				</view>
				<view class="alarmItem">
					<text class="label">车牌颜色：</text><text class="value">{{item.carColour}}</text>
				</view>
				<view class="alarmItem">
					<text class="label">车型：</text><text class="value">{{item.vehicleType}}</text>
				</view>
				<view class="alarmItem">
					<text class="label">报警类型：</text><text class="value">{{alarmTypeArr[item.alarmType]}}</text>
				</view>
				<view class="alarmItem">
					<text class="label">抓拍时间：</text><text class="value">{{item.captureTime}}</text>
				</view>
				<view class="alarmItem">
					<text class="label">抓拍设备：</text><text class="value">{{item.deviceNo}}</text>
				</view>
				<view class="alarmItem">
					<text class="label">告警照片：</text><text class="value">
					<image v-if="item.photoUrl" :src="item.photoUrl" class="profile_photo" @click="previewImg(item.photoUrl)"></image>
					</text>
				</view>
				<view class="alarmItem">
					<text class="label">告警声音：</text><text class="value" @click="playVideo(item.vedioUrl,'audio')">播放</text>
				</view>
				<view class="alarmItem">
					<text class="label">离开时间：</text><text class="value">{{item.leaveTime}}</text>
				</view>
				<view class="alarmItem">
					<text class="label">离开工地视频：</text><text class="value" @click="playVideo(item.leaveVedioUrl,'video')">播放</text>
				</view>
			</view>
			<view class="placeholderBox" v-if="inOutList.length==0">
				<image src="/static/noData.png" mode="" class="noDataImg"></image>
				<view class="text">
					暂无数据
				</view>
			</view>
		<!-- </view> -->
		<!-- <view class="" v-if="tabIndex==1">
			<view class="selectContent selectContent2">
				<input class="selectVideoBox" confirm-type="search" type="text" v-model="carNumber" placeholder="搜索车牌号" @confirm="carList=[];getEnvironmentDev()" />
				<picker :range="carTypeArr" range-key="name" @change="changeCarType" :value="isBlack" style="margin-left:30rpx">
					<view class="selectVideoBox">
						<text class="videoName">{{carTypeArr[isBlack].name}}</text>
						<uni-icons2 class="arrow" type="arrowdown" size="15"></uni-icons2>
					</view>
				</picker>
			</view>
			<view class="blockBox" v-for="(item,index) in carList" :key="index" @click="goAdd(item.id)">
				<view class="alarmItem">
					<text class="label">车牌号：</text><text class="value">{{item.carNumber}}</text>
				</view>
				<view class="alarmItem">
					<text class="label">车辆颜色：</text><text class="value">{{item.carColor}}</text>
				</view>
				<view class="alarmItem">
					<text class="label">车辆类型：</text><text class="value">{{item.carTypeName}}</text>
				</view>
				
				<view class="alarmItem">
					<text class="label">司机姓名：</text><text class="value">{{item.driverName}}</text>
				</view>
				<view class="alarmItem">
					<text class="label">司机电话：</text><text class="value">{{item.driverTelephone}}</text>
				</view>
				<view class="alarmItem">
					<text class="label">车辆图片：</text><text class="value">
					<image v-if="JSON.parse(item.carPhotosUrl)[0]" :src="JSON.parse(item.carPhotosUrl)[0]?url_config+'image/'+JSON.parse(item.carPhotosUrl)[0].url:''" class="profile_photo" @click="previewImg(url_config+'image/'+JSON.parse(item.carPhotosUrl)[0].url)"></image>
					</text>
				</view>
				<text class="tags" :class="item.isBlack?'black':''">{{item.isBlack?'黑名单':'白名单'}}</text>
			</view>
			<view class="placeholderBox" v-if="carList.length==0">
				<image src="/static/noData.png" mode="" class="noDataImg"></image>
				<view class="text">
					暂无数据
				</view>
			</view>
		</view>
		<image v-show="tabIndex==1" src="/static/addImg.png" class="addImg" @click="goAdd('')"></image> -->
		<!-- <image v-show="tabIndex==1" src="/static/addImg.png" class="addImg" @click="playVideo('https://bjetxgzv.cdn.bspapp.com/VKCEYUGU-hello-uniapp/2cc220e0-c27a-11ea-9dfb-6da8e309e0d8.mp3','audio')"></image> -->
	</view>
</template>

<script>
	import headers from "../../../components/headers/headers.vue"
	import {
		GetDateStr
	} from "../../../static/js/util.js"
	export default {
		components: {
			headers
		},
		data() {
			return {
				projectDetail: '',
				carList: [],
				inOutList: [],
				currentDevDetail: {},
				searchDate: '',
				tabIndex: 0,
				pageNo: 1,
				pageSize: 20,
				loadStatus:'more',
				isLoadMore:false,
				carNumber:'',
				carTypeArr:[
					{name:'全部车辆',value:-1},
					{name:'白名单',value:0},
					{name:'黑名单',value:1}
				],
				alarmTypeArr: ["全部","车辆绕行", "冲洗时间不足", "未冲洗", "其他", "正常冲洗"],
				isBlack:0
			};
		},
		mounted() {
			this.projectDetail = JSON.parse(uni.getStorageSync('projectDetail'))
			this.searchDate = GetDateStr(0, '-')
			this.loadData()
		},
		onReachBottom() {
			if(!this.isLoadMore){  //此处判断，上锁，防止重复请求
				this.isLoadMore=true
				this.pageNo+=1
				this.loadData()
			}
		},
		onPullDownRefresh() {
			this.pageNo=1
			this.carList=[];
			this.inOutList=[]
			this.loadData()
		},
		methods: {
			playVideo(src,type){
				uni.navigateTo({
					url:'./mediaPlay?url='+src+'&type='+type
				})
			},
			// goAdd(id){
			// 	uni.navigateTo({
			// 		url:'./addCar?id='+id
			// 	})
			// },
			previewImg(url){
				uni.previewImage({
					urls:[url]
				})
			},
			changeCarType(e){
				this.isBlack=e.target.value;
				this.pageNo=1;
				this.inOutList=[]
				this.getInOutList()
			},
			changeDate(e) {
				this.searchDate = e.target.value
				this.pageNo=1;
				this.inOutList=[]
				this.getInOutList()
			},
			changeMenu(index) {
				this.tabIndex = index;
				this.carList=[];
				this.inOutList=[];
				this.pageNo=1;
				this.loadData()
			},
			loadData() {
				this.getInOutList()
				// switch (this.tabIndex) {
				// 	case 0:
				// 		this.getInOutList()
				// 		break;
				// 	case 1:
				// 		this.getEnvironmentDev()
				// 		break;
				// }
			},
			//获取进出列表
			getInOutList() {
				var that = this
				this.sendRequest({
					url: "xmgl/carWashCurrentData/list",
					data: {
						projectSn: this.projectDetail.projectSn,
						pageNo: this.pageNo,
						pageSize: this.pageSize,
						startTime: this.searchDate,
						endTime: this.searchDate,
						devSn: '',
						carNumber:this.carNumber,
						alarmType:this.isBlack==0?'':this.isBlack
					},
					method: "post",
					success(res) {
						that.inOutList=that.inOutList.concat(res.result.records)
						if(res.result.records.length<that.pageSize){  //判断接口返回数据量小于请求数据量，则表示此为最后一页
							  that.isLoadMore=true                                             
							  that.loadStatus='nomore'
						}else{
							  that.isLoadMore=false
							  // that.loadStatus='more'
						}
						uni.stopPullDownRefresh()
					}
				})
			},
			//获取设备
			getEnvironmentDev() {
				var that = this
				var type=this.isBlack==0?'':this.isBlack-1
				this.sendRequest({
					url: "xmgl/carInfo/selectCarList",
					data: {
						projectSn: this.projectDetail.projectSn,
						carNumber: this.carNumber,
						isBlack: type,
						pageNo: this.pageNo,
						pageSize: this.pageSize
					},
					method: "POST",
					success(res) {
						that.carList=that.carList.concat(res.result.records)
						if(res.result.records.length<that.pageSize){  //判断接口返回数据量小于请求数据量，则表示此为最后一页
							  that.isLoadMore=true                                             
							  that.loadStatus='nomore'
						}else{
							  that.isLoadMore=false
							  // that.loadStatus='more'
						}
						uni.stopPullDownRefresh()
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.menuBox {
		display: flex;
		align-items: center;
		height: 36px;
		font-size: 30rpx;
		background-color: white;
		margin-top: -1px;
		position: relative;
		z-index: 999;
		border-bottom: 1px solid rgba(194, 194, 194, 0.2);

		.menuItem {
			flex: 1;
			text-align: center;

			&.active {
				color: rgba(43, 141, 243, 1);
			}
		}
	}

	.blockBox {
		box-shadow: 0 4px 24px 0px rgba(212, 220, 236, 0.69);
		border-radius: 16rpx;
		margin: 30rpx;
		padding: 30rpx;
		position: relative;
	}
	.selectContent {
		text-align: center;
		margin-top: 30rpx;
	}

	.selectVideoBox {
		border: 1px solid rgba(42, 43, 91, 0.2);
		border-radius: 36rpx;
		height: 70rpx;
		font-size: 30rpx;

		display: inline-block;

		.videoName {
			padding: 0 24rpx 0 30rpx;
			// border-right: 1px solid rgba(42, 43, 91, 0.2);
			line-height: 70rpx;
			height: 70rpx;
		}

		.arrow {
			padding: 0 24rpx 0 4rpx;
		}
	}

	.arrow {
		margin-left: 20rpx;
	}



	.alarmIcon {
		width: 40rpx;
		height: 40rpx;
	}


	.blockTitle {
		text-align: center;
	}



	.selectContent2 {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.alarmItem {
		font-size: 28rpx;
		position: relative;
		.label {
			opacity: 0.6;
			display: inline-block;
			vertical-align: top;
		}
	}

	.profile_photo {
		width: 60rpx;
		height: 60rpx;
	}

	.tags{
		position: absolute;
		right: 30rpx;
		top: 0;
		border-bottom-left-radius: 16rpx;
		border-bottom-right-radius: 16rpx;
		box-shadow: 0 4px 26rpx 0px rgba(125, 126, 160, 0.39);
		font-size: 26rpx;
		padding: 4rpx 10rpx;
	}
	.black{
		background-color: #c1c1c1;
		box-shadow: 0 4px 26rpx 0px rgba(193, 193, 193, 0.69);
		color: white;
	}
	.addImg{
		position: fixed;
		bottom: 30rpx;
		right: 30rpx;
		width: 64rpx;
		height: 64rpx;
	}
</style>
