<template>
	<view>


		<uni-row>
			<uni-col :span="20">
				<view class="uni-padding-wrap uni-common-mt">
					<uni-segmented-control :current="current" :values="tableitems" :style-type="styleType"
						:active-color="activeColors()" @clickItem="onClickItem" />
				</view>
			</uni-col>
			<uni-col :span="4">

			</uni-col>
		</uni-row>
		<uni-row>
			<uni-col :span="24">
				<view class="uni-padding-wrap uni-common-mt">
					<select-cy :value="tval" placeholder="ATA" name="name" :options="datalist" :showClearIcon="true"
						:zindex="zindex" @change="change_select_cy"></select-cy>
				</view>
			</uni-col>
		</uni-row>

		<view style="font-size: 20rpx;">
			<view v-if="current === 0" >

				<eventinit-fault :eventlist="listFde" :fleet="fleet" :latestAcarsTime="latestAcarsTime">
				</eventinit-fault>
				<eventinit-fault :eventlist="listSMT" :fleet="fleet" :latestAcarsTime="latestAcarsTime">
				</eventinit-fault>
				<eventinit-fault :eventlist="listMMO" :fleet="fleet" :latestAcarsTime="latestAcarsTime">
				</eventinit-fault>
				<uni-row style="padding-left: 10px; padding-top: 20px;font-weight: 800;">非关联维护信息({{listMMSG.length}})
				</uni-row>
				<view v-if="listMMSG.length>0">
					<eventinit-fault :eventlist="listMMSG" :fleet="fleet" :latestAcarsTime="latestAcarsTime">
					</eventinit-fault>
				</view>
				<view v-else style="padding-left: 10px; ">
					--
				</view>
				<uni-row style="padding-left: 10px; padding-top: 20px;font-weight: 800;">警告信息({{listAlert.length}})
				</uni-row>
				<view v-if="listAlert.length>0">
					<eventinit-fault :eventlist="listAlert" :fleet="fleet" :latestAcarsTime="latestAcarsTime">
					</eventinit-fault>
				</view>
				<view v-else style="padding-left: 10px;">
					--
				</view>

				<!-- <view v-else style="margin-top: 10px; margin-left: 30px;">暂无数据</view> -->
			</view>
			<view v-if="current === 1">
				<view v-if="listFde.length>0">
					<eventinit-fault :eventlist="listFde" :fleet="fleet" :latestAcarsTime="latestAcarsTime">
					</eventinit-fault>
				</view>
				<view v-else style="margin-top: 10px; margin-left: 30px;">暂无数据</view>
			</view>
			<view v-if="current === 2">
				<view v-if="listSMT.length>0">
					<eventinit-fault :eventlist="listSMT" :fleet="fleet" :latestAcarsTime="latestAcarsTime">
					</eventinit-fault>
				</view>
				<view v-else style="margin-top: 10px; margin-left: 30px;">暂无数据</view>
			</view>
			<view v-if="current === 3">
				<view v-if="listMMO.length>0">
					<eventinit-fault :eventlist="listMMO" :fleet="fleet" :latestAcarsTime="latestAcarsTime">
					</eventinit-fault>
				</view>
				<view v-else style="margin-top: 10px; margin-left: 30px;">暂无数据</view>
			</view>
			<view v-if="current === 4">
				<view v-if="listMMSG.length>0">
					<eventinit-fault :eventlist="listMMSG" :fleet="fleet" :latestAcarsTime="latestAcarsTime">
					</eventinit-fault>
				</view>
				<view v-else style="margin-top: 10px; margin-left: 30px;">暂无数据</view>
			</view>
			<view v-if="current === 5">
				<view v-if="listAlert.length>0">
					<eventinit-fault :eventlist="listAlert" :fleet="fleet" :latestAcarsTime="latestAcarsTime">
					</eventinit-fault>

				</view>
				<view v-else style="margin-top: 10px; margin-left: 30px;">暂无数据</view>
			</view>

		</view>

	</view>

</template>

<script>
	import {
		getEventListByReportTypeLegId,
		getAtaListAll
	} from '@/utils/requestahm.js';
	import eventinitFault from "@/pages/components/ahm/eventinitFault.vue";
	import headers from "@/pages/components/ahm/headers.vue";
	import moment from "moment"



	export default {
		data() {
			return {
				moment,

				//模拟初始数据
				tval: [

				],
				// //模拟数据列表
				datalist: [],
				zindex: 999,
				fleetlist: [],


				eventonlist: [], //初始化加载保存所有数据
				eventlist: [],
				listFde: [],
				listMMSG: [],
				listAlert: [],
				listSMT: [],
				listMMO: [],


				current: 0,
				tableitems: ['全部', 'FDE', 'SMT', 'MMO', 'MMSG', 'Alert'],
				styleType: 'button',

				//reportType:'',
				//          legId:'',
				// tailNumber:'',

				carditem: {},
				eventListByReportTypeLegIdData: [],

				//latestAcarsTime:'', //更新时间

			}
		},
		props: {
			latestAcarsTime: {
				type: String,
			},
			fleet: {
				type: String,
			},
			reportType: {
				type: String,
			},
			legId: {
				type: String,
			},
			tailNumber: {
				type: String,
			}

		},
		watch: {
			reportType: {
				immediate: true, //一运行项目就立即开启监视
				handler(newValue, oldValue) {
					// console.log("reportType被监视了",newValue,oldValue);
					//清空下拉显示信息
					this.tval = []
					//回到全部的位置
					this.current = 0
					this.getDate();
				}
			}
		},

		computed: {

		},
		components: {
			headers,
			eventinitFault
		},

		methods: {
			//下拉框改变
			change_select_cy(item, value) {
				
				this.tval1 = value;
				if (value.length > 0) {
					
					let itemlist = this.eventonlist.filter(items => value.indexOf(items.ata) !== -1)
					
					this.eventlist = itemlist
				} else {
					
					this.eventlist = this.eventonlist
				}
				this.listMMO = this.eventlist.filter(items => items.name == 'MMO')
				this.listSMT = this.eventlist.filter(items => items.name == 'SMT')
				this.listFde = this.eventlist.filter(items => items.name == 'FDE')
				this.listMMSG = this.eventlist.filter(items => items.name == 'MMSG')
				this.listAlert = this.eventlist.filter(items => items.msgType == 'Alert')

			},

			//加载故障汇总
			async getDate() {
				//显示加载框
				uni.showLoading({
				    title: '加载中...'
				});
				//ata信息
				const ataitem = await getAtaListAll({

				})
				

				let param = {}
				for (var i = 0; i < ataitem.data.length; i++) {
					param = {
						label: ataitem.data[i].ataId + '-' + ataitem.data[i].name,
						value: ataitem.data[i].ataId,
						//value:ataitem.data[i].ataId+'-'+ataitem.data[i].name,
					}
					this.datalist.push(param)
				}
				// this.legId = '638cc4d85ca2017518741aae'
				// this.tailNumber = 'B-7837'
				const items = await getEventListByReportTypeLegId({
					reportType: this.reportType,
					legId: this.legId,
					tailNumber: this.tailNumber
				})
				this.eventlist = items.data //所有故障信息
				this.eventonlist =  items.data
				if(items.code == 200){
					//显示更新时间用
					this.eventListByReportTypeLegIdData = items.data.filter(
						(v) => v.name && v.code
					);					
					this.listMMO = this.eventlist.filter(item => item.name == 'MMO')
					this.listSMT = this.eventlist.filter(item => item.name == 'SMT')
					this.listFde = this.eventlist.filter(item => item.name == 'FDE')
					this.listMMSG = this.eventlist.filter(item => item.name == 'MMSG')
					this.listAlert = this.eventlist.filter(item => item.msgType == 'Alert')					
				}else{
				
				}
				//隐藏加载
				uni.hideLoading();
				

			},

			//回退到上一页面
			clickLeft() {
				uni.navigateBack()
			},
			activeColors() {
				return '#0299E3';
			},
			onClickItem(e) {
				if (this.current !== e.currentIndex) {
					this.current = e.currentIndex
				}
			},


		},
		onLoad(options) {

		},
		created() {

			//this.getDate();
		},
	}
</script>

<style scoped lang="scss">
	.margin-left {
		margin-left: 10px;
		margin-top: 20px;
	}

	.uni-common-mt {
		margin-top: 10px;
	}

	.uni-padding-wrap {
		// width: 750rpx;
		padding: 0px 10px;
	}

	.popup-content {
		height: 200px;
		align-items: center;
		justify-content: center;
	}
</style>
