<template>
	<view class="container">
		<scroll-view class="padding-wrap" scroll-y @scrolltolower="loadMore">
			<view class="message-box" @click="goDetail(item)" v-for="(item,index) in dataList" :key="'msg'+index">
				<view class="message-image">
					<image class="image" src="@/static/msg-icon.png" mode="widthFix"></image>
				</view>
				<view class="message-info">
					<view class="message-title">
						<view class="title">{{item.content}}</view>
						<view class="time">{{item.reportTime}}</view>
					</view>
					<view class="message-des">
						报警位置：{{item.buildId}}号楼{{item.floorNo}}层
					</view>
				</view>
			</view>
			<uni-load-more iconType="circle" :status="status" />
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataList: [],
				current: 0,
				size: 10,
				hasMore: true,
				status: 'loading'
			}
		},
		onLoad() {
			this.loadMore();
		},
		methods: {
			//滚动加载更多
			loadMore() {
				if (this.hasMore) {
					this.current = this.current + 1;
					this.staus = 'loading';
					console.log('url =====>',getApp().globalData.apiUrl)
					// this.dataList = [
					// 	{deviceId:'001',deviceName:'001',productName:'检测器',buildId:'1',floorNo:'-3',longidute:'120.42052988196423',latidute:'36.112521198229985'}
					// ]
					uni.request({
						url: getApp().globalData.apiUrl + '/alarmInformation/list?status=1&current=' + this.current + '&size=' + this.size,
						method: 'GET',
						success: (res) => {
							console.log('res ====>',res)
							if(res.data.code == 200){
								this.dataList = this.dataList.concat(res.data.data.records);
								if(res.data.data.records.length == 0 || res.data.data.total < this.size){
									this.hasMore = false;
									this.status = 'nomore';
								}
								else{
									this.status = 'more';
								}
							}else{
								uni.showToast({
									title: res.data.msg,
									icon: 'none'
								})
							}
						}
					})
				}
			},
			goDetail(data) {
				console.log('details ====>')
				uni.navigateTo({
					url: '/pages/message/detail?data=' + JSON.stringify(data)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	page,
	.container {
		height: 100vh;
		background-color: #FFFFFF;
	}

	.padding-wrap {
		padding-top: 30upx;
		height: calc(100vh - 30upx);
	}

	.message-box {
		display: flex;
		flex-direction: row;
		align-items: center;
		padding: 0 30upx;
		margin-bottom: 44upx;

		.message-image {
			display: block;
			margin-right: 20upx;

			.image {
				width: 88upx;
				height: 88upx;
			}
		}

		.message-info {
			flex: 1;
			color: #031945;
			font-size: 28upx;
			line-height: 40upx;

			.message-title {
				display: flex;
				justify-content: space-between;

				.title {
					max-width: 350upx;
					font-family: PingFang SC-Bold, PingFang SC;
					font-weight: bold;
					white-space: nowrap;
					text-overflow: ellipsis;
					overflow: hidden;
				}

				.time {
					color: #90959D;
					font-size: 24upx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
				}
			}

			.message-des {
				display: block;
				width: 550upx;
				color: #90959D;
				white-space: nowrap;
				text-overflow: ellipsis;
				overflow: hidden;
			}
		}
	}
</style>