<template>
	<view>
		<view class="barBox">
			<headers :themeType="'white'" :showBack="true">
				<view class="title">
					<view class="backBtn">
						<view>
							<!-- <span class="back" @click="goBack()">返回</span> -->
							<span class="tip">告警提示</span>
						</view>
					</view>
				</view>
			</headers>
		</view>
		<view class="">
			<!-- <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-header">
					<view class="header-left">
						<view class="logo">
							<image src="/static/aiWarn/aiWarn.png"></image>
						</view>
						<!-- <view class="header-info">未戴安全帽</view> -->
						<!-- <view class="header-info">{{}}</view> -->
						<view class="header-info">AI报警</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>
				<view class="textCss">抓拍时间: {{item.createTime}}</view>
				<view class="textCss">来源: {{item.alarmDesc}}</view>
				<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" mode="heightFix" class="accessoryImg"
						       :src="item.imageUrl" 
						       @click="previewImg(item.imageUrl)"></image>
						       <!-- @click="previewImg(url_config+'image/'+item.imageUrl)"></image> -->
					</view>
					<view class="bottom-right" @click="goDisposition(item)"  v-if="!item.handleResult">
						去处置
					</view>
					<view class="bottom-right" @click="goShutting(item)" style="background-color: #b0b0b0;" v-else>
						已闭合
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				listData: [],
				projectSn: '',
				pageNo: 1,
				pageSize: 7,
				systemInfo: {
					statusBarHeight: 0
				},
				showType: [
					{ id: 1, value: '安全帽报警', },
					{ id: 2, vlaue: '明火报警' },
					{ id: 3, value: '聚众报警' }, 
					{ id: 4, value: '未戴安全帽报警' },
					{ id: 5, value: '越界报警' },
					{ id: 6, value: '闯入报警' },
					{ id: 7, value: '反光衣报警' },
					{ id: 8, value: '未穿反光衣' },
				]
			}
		},
		mounted() {
			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()
		},
		methods: {
			//获取列表数据
			getListData() {
				this.sendRequest({
					url: 'xmgl/aiAnalyseHardWareAlarmRecord/selectPageList',
					method: "post",
					data: {
						projectSn: this.projectSn,
						pageNo: this.pageNo,
						pageSize: this.pageSize,
					},
					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/alarmPage/disposition/disposition?item="+ encodeURIComponent(JSON.stringify(item))
				});
			},
			// 点击跳转
			goShutting(item) {
				console.log("=================================================");
				uni.navigateTo({
					// url: "/pages/alarmPage/disposition/disposition?item="+ encodeURIComponent(JSON.stringify(item))
					url: "/pages/alarmPage/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>
	.item-bottom{
		display: flex;
		justify-content: space-between;
		align-items: flex-end;
		// height: 100px;
		.bottom-left{
			
		}
		.bottom-right{
			width: 25%;
			font-size: 14px;
			background-color: #5181f6;
			color: #fff;
			padding: 5px;
			display: flex;
			justify-content: center;
			align-items: center;
			border-radius: 5px;
			z-index: 999;
		}
	}
	.accessoryImg {
		margin-top: 20px;
		// width: 100%;
		max-width: 150px;
		max-height: 75px;
	}
	.item-header{
		display: flex;
		justify-content: space-between;
		width: 100%;
		.header-left{
			height: 30px;
			width: 40%;
			// background-color: darkred;
			display: flex;
			justify-content: flex-start;
			align-items: center;
			.logo{
				width: 20%;
				height: 100%;
				background-size: 100% 100%;
				::v-deep uni-image>div, uni-image>img{
					width: 7%;
					height: 10%;
				}
			}
			.header-info{
				font-size: 16px;
			}
		}
		.header-right{
			width: 10%;
			height: 20px;
			// background-color: #5181F6;
			::v-deep uni-image>div, uni-image>img{
				width: 11.5%;
				height: 15%;
			}
			transform: translateY(-10px);
			// position: absolute;
			// right: 10%;
			// top: 5;
		}
	}
	.textCss{
		letter-spacing: 1px;
		color: #a9a9a9;
		margin-top: 10px;
		font-size: 12px;
	}
	.barBox {
		background-color: #5181F6;
	}

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


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

	.back {
		font-size: 12px;
	}

	.tip {
		margin-left: 5rem;
	}

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

	.alarm-item {
		width: 650rpx;
		margin: 20rpx auto;
		background-color: #fff;
		padding: 20px;
		box-sizing: border-box;
		border-radius: 10px;
		box-shadow: 0 0 5px #ccc;
	}

	.alarm-lable {
		display: flex;
	}

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

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