<template>
	<view>
		<view class="barBox fixedheader">
			<headers class="" :showBack="true">
				<view class="headerName">
					告警提示
				</view>
			</headers>
			<view class="selectContent">
				<picker mode="date" @change="changeDate" :value="searchForm.attendanceDate" class="selectItem">
					<view class="selectVideoBox">
						<text class="videoName">{{ searchForm.attendanceDate }}</text>
						<!-- <uni-icons2 class="arrow" type="arrowdown" size="15"></uni-icons2> -->
						<uni-icons2 class="arrowright" type="arrowright"></uni-icons2>
					</view>
				</picker>
				<picker mode="selector" :range="showType" @change="changePersonType" range-key="value"
					:value="personTypeIndex" style="margin-left:20rpx" class="selectItem">
					<view class="selectVideoBox">
						<text class="videoName">{{ showType[personTypeIndex].value }}</text>
						<!-- <uni-icons2 class="arrow" type="arrowdown" size="15"></uni-icons2> -->
						<uni-icons2 class="arrowright" type="arrowright"></uni-icons2>
					</view>
				</picker>
			</view>
		</view>
		<view class="alarm_main" :style="{paddingTop: (mobileTopHeight + 90) * 1.5 + 'rpx'}">
			<!-- <view class="alarm-item" v-for="(item,index) in listData" :key="index" @click="goHiidden()"> -->
			<view class="alarm-item" v-for="(item,index) in listData" :key="index">
				<view class="item-bottom">
					<view class="bottom-left">
						<!-- <image mode="heightFix" @click="saveImage(url_config+'image/'+item.imageUrl,index)" class="accessoryImg"
							src="/static/bg1.png"></image> -->

						<!-- <image mode="heightFix" @click="saveImage(url_config+'image/'+item.imageUrl,index)" class="accessoryImg"
							:src="item.imageUrl"></image> -->

						<image v-if="item.imageUrl" class="accessoryImg" :src="item.imageUrl?item.imageUrl:''"
							@click="previewImg(item.imageUrl)"></image>
						<!-- @click="previewImg(item.imageUrl)"></image> -->
					</view>
					<view class="bottom-right" @click="goDisposition(item)"
						v-if="!item.handleResult && (item.isEnableHandle || userInfo.accountType == 5 || userInfo.accountType == 10)"
						v-show="btnAuth">
						去处置
					</view>
					<view class="bottom-right" @click="goShutting(item)" style="background-color: #b0b0b0;"
						v-if="item.handleResult">
						已闭合
					</view>
				</view>
				<view class="item-header">
					<view class="header-left">
						<!-- <view class="header-info">未戴安全帽</view> -->
						<!-- <view class="header-info">{{}}</view> -->
						<view class="header-info">
							<!-- 车辆报警 -->
							{{ item.alarmType ? showType[item.alarmType - 1].value : '' }}
						</view>
						<view class="logo">
							<image src="/static/aiWarn/aiWarn.png"></image>
						</view>
					</view>
					<!-- <view class="header-right" v-if="!item.handleResult">
						<image src="/static/aiWarn/aiWarn2.png"></image>
					</view>
					<view class="header-right" v-else>
						<image src="/static/aiWarn/correct.png"></image>
					</view> -->
					<!-- <view class="btn_detail">
						处置详情
						<uni-icons2 class="arrowright" type="arrowright"></uni-icons2>
					</view> -->
				</view>
				<view class="textCss">
					<view>
						<!-- 来源: -->
						地址:
					</view>
					<view>
						{{item.alarmDesc}}
					</view>
				</view>
				<view class="textCss">
					<view>
						抓拍时间:
					</view>
					<view>
						{{item.createTime}}
					</view>
				</view>
			</view>
			<view class="no_data" v-if="listData.length == 0">
				<image src="/static/noData.png"></image>
				<view>暂无数据</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { GetDateStr } from "@/static/js/util.js"

	export default {
		data() {
			return {
				mobileTopHeight: 0,
				listData: [],
				projectSn: '',
				pageNo: 1,
				pageSize: 7,
				systemInfo: {
					statusBarHeight: 0
				},
				showType: [{
						id: "",
						value: '全部',
					},{
						id: 1,
						value: '安全帽报警',
					},
					{
						id: 2,
						value: '明火报警'
					},
					{
						id: 3,
						value: '聚众报警'
					},
					{
						id: 4,
						value: '未戴安全帽报警'
					},
					{
						id: 5,
						value: '越界报警'
					},
					{
						id: 6,
						value: '闯入报警'
					},
					{
						id: 7,
						value: '反光衣报警'
					},
					{
						id: 8,
						value: '未穿反光衣'
					},
				],
				btnAuth: true,
				userInfo: {},
				searchDate: "",
				personTypeIndex: 0,
				searchForm: {
					personType: 1, //1、施工人员 2、管理人员
					attendanceDate: ''
				},
			}
		},
		onLoad() {
			this.btnAuth = this.checkBtnPermission({
				key: 'ai_disposition',
				menuPath: '/project/carViolation/warningList'
			})
			this.userInfo = JSON.parse(uni.getStorageSync('userInfo'));
			this.searchForm.attendanceDate = GetDateStr(0, '-');
		},
		onShow() {
			this.systemInfo = uni.getStorageSync('systemInfo')
			this.projectSn = JSON.parse(uni.getStorageSync('projectDetail')).projectSn;
			this.getListData()
		},
		onPullDownRefresh() {
			this.getListData()
			setTimeout(function() {
				uni.stopPullDownRefresh()
			}, 1000)
		},
		onReachBottom() {
			// console.log("============================")
			this.pageNo++;
			uni.showLoading({
				title: '加载中'
			})
			this.getListData()
		},
		mounted() {
			var that = this
			uni.getSystemInfo({
				success(res) {
					that.mobileTopHeight = res.statusBarHeight ? res.statusBarHeight : 0;
					uni.setStorageSync('systemInfo', res)
					console.log(res)
				}
			})
			console.log('this.mobileTopHeight', this.mobileTopHeight)
		},
		methods: {
			changeDate(e) {
				this.searchForm.attendanceDate = e.detail.value
				this.pageNo = 1
				this.getListData()
			},
			changePersonType(e) {
				// console.log(e)
				this.personTypeIndex = e.detail.value
				this.searchForm.personType = this.showType[this.personTypeIndex].id
				this.pageNo = 1
				this.getListData()
			},
			//获取列表数据
			getListData() {
				this.sendRequest({
					url: 'xmgl/carDangerDetectRecord/selectPageList',
					method: "post",
					data: {
						projectSn: this.projectSn,
						pageNo: this.pageNo,
						pageSize: this.pageSize,
						startTime: this.searchForm.attendanceDate,
						endTime: this.searchForm.attendanceDate,
						alarmType: this.searchForm.personType,
						isPushed: 1
					},
					success: res => {
						if (res.code == 200) {
							console.log('res', res)
							// res.result.records.forEach((item) => {
							// 	const result = this.showType.find((item2) => {
							// 		return item2.id == item.alarmType
							// 	})
							// 	// item.alarmType = result.value
							// 	item.alarmType = result.alarmType
							// })
							if (this.pageNo == 1) {
								this.listData = []
							}
							// console.log('--------')
							// this.listData = res.result.records
							this.listData = [...this.listData, ...res.result.records]
							uni.hideLoading() //关闭加载中
						}
					}
				})
			},
			goBack() {
				uni.reLaunch({
					url: "/pages/projectEnd/projectIndex/projectIndex"
				});
			},
			// 点击跳转
			goDisposition(item) {
				console.log("=================================================");
				uni.navigateTo({
					url: "/pages/carViolation/disposition/disposition?item=" + encodeURIComponent(JSON.stringify(
						item))
				});
			},
			// 点击跳转
			goShutting(item) {
				console.log("=================================================");
				uni.navigateTo({
					// url: "/pages/carViolation/disposition/disposition?item="+ encodeURIComponent(JSON.stringify(item))
					url: "/pages/carViolation/shutting/shutting?item=" + encodeURIComponent(JSON.stringify(item))
				});
			},
			previewImg(imgUrl) {
				console.log(imgUrl)
				//urls为数组，数据里有多少图片链接则显示多少张，若只想预览一张的话，直接传只有一个图片地址的数组即可
				let imgurl = imgUrl
				let imgArr = []
				imgArr[0] = imgurl
				uni.previewImage({
					current: 0,
					urls: imgArr
				})
			},
			// saveImage(url) {
			// 	uni.showLoading({
			// 		title: "保存中..."
			// 	})
			// 	uni.downloadFile({
			// 		url: url, //网络路径，下载下来  
			// 		success: (res) => {
			// 			if (res.statusCode === 200) {
			// 				uni.saveImageToPhotosAlbum({
			// 					filePath: res.tempFilePath, //下载后的临时路径  
			// 					success: res => { //下载完成后在相册里压根找不到  
			// 						uni.hideLoading()
			// 						uni.showToast({
			// 							title: "保存成功！"
			// 						})
			// 						uni.navigateTo({
			// 							url: "/pages/projectEnd/safeManage/addExamine"
			// 						});
			// 					}
			// 				})
			// 			}
			// 		}
			// 	});

			// }

		}
	}
</script>

<style lang="scss" scoped>
		.no_data{
			position: fixed;
			top: 35%;
			// transform: translateY(-50%);
			left: 50%;
			transform: translateX(-50%);
			padding-top: 60rpx;
			text-align: center;
			color: rgba(0,0,0,0.5);
			font-size: 28rpx;
			uni-image{
				width: 162rpx;
				height: 130rpx;
				display: block;
				margin: 0 auto;
				margin-bottom: 40rpx;
			}
		}
	.selectContent {
		padding: 0 30rpx 10rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		text-align: center;

		.selectItem {
			flex: 1;
		}
	}

	.selectVideoBox {
		border: 1px solid #cccccc;
		border-radius: 18rpx;
		height: 70rpx;
		font-size: 30rpx;
		// display: inline-block;
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;

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

		.arrow {
			padding: 0 24rpx 0 4rpx;
			margin-left: 20rpx;
		}

		.arrowright {
			color: #2D8EF3 !important;
			font-size: 40rpx !important;
		}
	}

	.selectContent {
		text-align: center;

		//margin-top: 30rpx;
		.selectBox {
			margin: 0 20rpx;
			// background-color: #eeeeef;
			border: 2rpx solid #cccccc;
			border-radius: 12rpx;
			padding: 15rpx 20rpx;
			width: 100%;
			background-color: #F3F5F7;
		}

		.selectInput {
			width: 100%;
			text-align: left;
			font-size: 28rpx;
		}
	}

	.alarm_main {
		background-color: #F3F5F7;
		min-height: 100vh;
	}

	.fixedheader {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		z-index: 8;
		background-color: #ffffff;

		.headerName {
			z-index: 1;
		}
	}

	.item-bottom {
		display: flex;
		justify-content: space-between;
		align-items: flex-start;

		// height: 100px;
		.bottom-left {}

		.bottom-right {
			width: 25%;
			font-size: 28rpx;
			background-color: #5181f6;
			color: #fff;
			padding: 10rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			border-radius: 10rpx;
			z-index: 5;
		}
	}

	.accessoryImg {
		// margin-top: 40rpx;
		// width: 100%;
		max-width: 382rpx;
		max-height: 180rpx;
	}

	.item-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 100%;
		padding: 10rpx 0;
		border-bottom: 2rpx solid #E6E6E6;

		.header-left {
			height: 60rpx;
			width: 40%;
			// background-color: darkred;
			display: flex;
			justify-content: flex-start;
			align-items: center;

			.logo {
				width: 20%;
				height: 100%;
				background-size: 100% 100%;
				margin-left: 10rpx;

				// ::v-deep uni-image>div, uni-image>img{
				// 	width: 7%;
				// 	height: 10%;
				// }
				uni-image {
					width: 50rpx;
					height: 55rpx;
				}
			}

			.header-info {
				font-size: 30rpx;
			}
		}

		.header-right {
			width: 10%;
			height: 40rpx;

			// background-color: #5181F6;
			::v-deep uni-image>div,
			uni-image>img {
				width: 11.5%;
				height: 15%;
			}

			transform: translateY(-20rpx);
			// position: absolute;
			// right: 10%;
			// top: 5;
		}

		.btn_detail {
			// padding: 20rpx 40rpx;
			font-size: 26rpx;
			color: #FF0000;
			text-align: right;

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

	.textCss {
		// letter-spacing: 1px;
		// color: #a9a9a9;
		// margin-top: 20rpx;
		// font-size: 24rpx;4
		display: flex;
		padding: 20rpx 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;
		}
	}

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



	.barBox {
		// background-color: #5181F6;
		// height: 100%;
		// background-color: #f6f6f6;
		// min-height: 100%;

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

			.headerName {
				z-index: 1;
			}

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

	.title {
		height: 44px;
		line-height: 44px;
		font-size: 40rpx;
		width: 750rpx;
		background-color: #5181F6;
		color: #fff;
		text-align: center;
		position: relative;
	}


	.backBtn {
		// display: flex;
		// justify-content: flex-start;
		font-size: 30rpx;
		position: absolute;
		left: 20%;
	}

	.back {
		font-size: 24rpx;
	}

	.tip {
		margin-left: 5rem;
	}

	.contain2 {
		width: 750rpx;
		content: " ";
		// background-color: #f8f8f8;
		// height: calc(100vh - 44px);
		// overflow: auto;
	}

	.alarm-item {
		// width: 650rpx;
		margin: 20rpx 30rpx;
		background-color: #fff;
		padding: 32rpx 24rpx;
		box-sizing: border-box;
		border-radius: 20rpx;
		// box-shadow: 0 0 10rpx #ccc;
	}

	.alarm-lable {
		display: flex;
	}

	.alarm-lable-1 {
		width: 200rpx;
	}

	.alarm-lable-2 {
		flex: 1;
		text-align: right;
		color: #888;
	}
</style>