<template>
	<view class="app-content">
		<view class="title-box">{{navname}}</view>

		<uni-section title="消息列表" type="line" class="box">
			<uni-list class="messageList">
				<uni-list-item v-for="(item, index) in msgList" :key="index" :title="item.msg" />
			</uni-list>
		</uni-section>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				navname: "消息",
				msgList: [],
				msgSJ: null
			}
		},
		onShow() {
			let that = this;
			this.$msg.stopMsg()
			uni.removeTabBarBadge({
				index: 1
			})
			uni.$on("scancodemsg", (data) => {
				if (data.msg.length > 9) {
					uni.navigateTo({
						url: "/pages/detail/index?luggageNum=" + data.msg
					})
				}
			});
			this.msgSJ = setInterval(function() {
				that.getMsg()
			}, 3000)
		},
		onLoad() {},
		onUnload() {
			this.$msg.getMsg()
			clearInterval(this.msgSJ)
			uni.$off("scancodemsg");
		},
		onHide() {
			uni.$off("scancodemsg");
			clearInterval(this.msgSJ)
		},
		methods: {
			getMsg() {
				let airPort = "CAN"
				if (this.$storage.get("airportName")) {
					airPort = this.$storage.get("airportName")
				}
				let data = {
					"serviceId": 3021,
					"page": 1,
					"pageSize": 9999,
					"dataContent": [{
						"outAirport": airPort
					}]
				}

				this.$http.httpPost('/openApi/query', data).then(res => {
					if (res.code == "0") {
						this.$storage.setJson('msgList', res.returnData)
						this.msgList = res.returnData
						this.msgList.map(item => {
							if (item.abnormalState == "DLY") {
								// 2023-07-06,航班(MU2948,CAN-->CZX),发生(延误或者取消)
								item['msg'] = item.carrierFlightsDate + "，航班：" + item.carrierFlights +
									"（" + item.outAirport + "-" + item.landAirport + "）,延误"
							}
							if (item.abnormalState == "CAN") {
								// 2023-07-06,航班(MU2948,CAN-->CZX),发生(延误或者取消)
								item['msg'] = item.carrierFlightsDate + "，航班：" + item.carrierFlights +
									"（" + item.outAirport + "-" + item.landAirport + "）,取消"
							}
						})
					} else {
						uni.showToast({
							icon: 'none',
							title: "查询信息失败",
							duration: 5000
						});
					}
				})
			},
			scan() {
				uni.scanCode({
					onlyFromCamera: true,
					success: function(res) {
						if (res.result.length > 9) {
							uni.navigateTo({
								url: "/pages/detail/index?luggageNum=" + res.result
							})
						}
					}
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.app-content {
		position: relative;
		background: rgb(49, 85, 99);
		padding-top: 3.6rem;
		box-sizing: border-box;
		height: 100vh;

		>.title-box {
			width: 100%;
			height: 2.375rem;
			display: flex;
			justify-content: center;
			align-items: center;
			padding-top: 1.25rem;
			color: rgb(255, 255, 255);
			font-family: Noto Sans SC;
			font-size: 1rem;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 1000;
		}
		>.box{
			width: 100%;
			height:calc(100vh - 3rem);
			overflow-x: hidden;
			overflow-y: auto;
			// >.messageList {
			// 	width: 100%;
			// 	height:calc(100% - 1rem);
			// 	overflow-x: hidden;
			// 	overflow-y: auto;
			// }
		}
		
	}
</style>