<template>
    <view>

        <view v-for="(item,i) in list" :key="i">
            <view class="a_wai0" :class="addclass(item.priority)">
                <view v-if="item.priority==0" class="a_wai_5_0">
                    M
                </view>
                <view v-if="item.priority==1" class="a_wai_5">
                    L
                </view>
                <view v-if="item.priority==2" class="a_wai_5_2">
                    M
                </view>
                <view v-if="item.priority==3" class="a_wai_5_3">
                    H
                </view>
                <view class="a_wai_95">
                    <!-- <view class=" a_top"> -->
                    <uni-row style="margin-top: 10px;">
                        <uni-col :span="12" style="padding-left: 20rpx;">
                            ADVISORY
                        </uni-col>
                        <uni-col :span="12" style="padding-left: 10rpx;font-weight :600;text-align: right;
        padding-right: 20rpx;">
                            <!-- class="a_left font_weight" -->
                            {{activityup(item.activity)}}
                        </uni-col>
                    </uni-row>

                    <view class="a_top" style=" padding-left: 20rpx; font-weight:700 ;font-size: 16px; ">
                        {{item.description}}
                    </view>
                    <view>
                        <uni-row style=" padding-left: 20rpx;padding-top: 10rpx;">
                            <uni-col :span="4" style="color: #8F9799;">
                                {{item.name}}:
                            </uni-col>
                            <uni-col :span="12" style=" color: #0299E3;padding-left: 20rpx; font-weight :700 ">
                                {{item.code}}
                            </uni-col>
                        </uni-row>

                    </view>
                    <view v-if="item.eventDetails ==null || item.eventDetails.length==0 " class="a_top" style=" padding-left: 20rpx; font-weight:500 ;" @click="mmsgclick(i,item)">
                        Correlated Maintenance
                        Messages({{item.eventDetails ==null ?0: item.eventDetails.length}})
                    </view>
                    <view v-else class="a_top" style=" padding-left: 20rpx; font-weight:500 ;color: #0299E3;" @click="mmsgclick(i,item)">
                        Correlated Maintenance
                        Messages({{item.eventDetails ==null ?0: item.eventDetails.length}})
                    </view>
                    <view v-else>

                    </view>

                    <view>
                        <uni-row style="padding-left: 20rpx;padding-top: 10rpx;">
                            <uni-col :span="12" style="color:  #CFC9BD;">
                                {{item.msgTime}}
                            </uni-col>
                            <uni-col :span="12"
                                style="font-weight :600;text-align: right; padding-right: 20rpx; color:  #CFC9BD;">
                                {{item.phase}}
                            </uni-col>
                        </uni-row>

                        <view class="a_top">

                            <uni-row>
                                <to-history :circleFlag="item.circleFlag" :occurLegList="item.legs"
                                    :occurLegStatusList="item.legsStatus"></to-history>
                            </uni-row>
                        </view>
                        <view v-if="isfalg=='0'" class="a_top  mtl_reports" >
                            <uni-row style="padding-left: 20rpx;padding-top: 10rpx;padding-bottom: 10px;">
                                <uni-col :span="6">FDE手册:</uni-col>
                                <uni-col :span="18">
                                    <view style="color:  #0299E3; font-weight:700 ;font-size: 14px;"
									 @click="gotoMEL(itemfde)">
									 41-27-24-01
									</view>
                                </uni-col>
                            </uni-row>
                        </view>
                        <view v-if="isfalg=='1'" class="a_top  mtl_reports" >
                            <uni-row style="padding-left: 20rpx;padding-top: 10rpx;padding-bottom: 10px;">
                                <uni-col :span="6">MEL手册:</uni-col>
                                <uni-col :span="18">
                                    <view style="color:  #0299E3; font-weight:700 ;font-size: 14px;" @click="gotoMEL(itemfde)">DMC-B787-A-27-20-F4-12A-421A-A</view>
                                </uni-col>
                            </uni-row>
                        </view>
                        <view v-if="isfalg=='2'" class="a_top  mtl_reports" >

                        </view>

                        <!-- <view class="a_top  mtl_reports" v-for="(itemfde,j) in FDElist" :key="j">
                            <uni-row style="padding-left: 20rpx;padding-top: 10rpx;">
                                <uni-col :span="6">FDE手册:</uni-col>
                                <uni-col :span="18">
                                    <view style="color:  #0299E3;" @click="gotoMEL(itemfde)">{{itemfde.code}}</view>
                                </uni-col>
                            </uni-row>
                        </view> -->

                        <!-- <view class="a_top a_bottom  row " >
                        <view style="width:45%;">

                        </view>
                        <view class="acms_reports"
                            @click="CheckReports()">
                            ACMS Reports Viewer
                        </view>
                    </view> -->
                    </view>
                </view>
            </view>

            <view v-show="i == showfalg" v-for="(items,k) in item.eventDetails" :key="k">
				<uni-row>
					<uni-col :span="12">
						<view style="color: #9EA0A6; padding-top: 10px; padding-left: 10px;">
						    {{items.name}}:{{items.code}}
						</view>
					</uni-col>
					<uni-col :span="12">
						<view style="padding-top: 10px;padding-left: 10rpx;font-weight :600;text-align: right;  padding-right: 20rpx;">
						    {{activityup(items.activity)}}
						</view>
					</uni-col>
				</uni-row>
                <view>
                    <view class=" a_top am_bottom5" style=" padding-left: 20rpx;">
                        {{items.description}}
                    </view>
                </view>
				
				<uni-row>
					<uni-col :span="8">
						<view style="height: 15px;"></view>
					</uni-col>
					<uni-col :span="16">
						<view class="fimclass" @click="processingUrl(fimUrllist[k])">
						    DMC-B787-A-27-20-F4-12A-421A-A
						    <!-- {{fimNamelist[k]}} -->
						</view>
					</uni-col>
				</uni-row>

            </view>
        </view>
    </view>
</template>

<script>
    import {
        getHandbookFIM,
        getHandbookFDE
    } from '@/utils/requestahm.js'
    import toHistory from '@/pages/components/ahm/toHistory';
    export default {
        name:'events',
        data() {
            return {
                fimUrllist:[],
                FDElist: [], //fde显示
                fimNamelist: [],
                listitem: [],
                showfalg: '-1',
            }
        },
        props: {
            list :{
                type: Array,
                default: [],
            },
            isfalg :{
                type: String,
                default: '1',
            }

        },
        methods: {
            //legs: [0, -588, -589, -662, -663, -670, -671]
            //legsStatus: [2, 2, 1, 2, 2, 2, 2]
            //根据级别不同切换不同的背景
            addclass(i) {
                switch (i) {
                    case 0:
                        return 'a_wai0';
                    case 1:
                        return 'a_wai1';
                    case 2:
                        return 'a_wai2';
                    case 3:
                        return 'a_wai3';
                }
            },
            activityup(activityitem) {
                if (activityitem == 1) {
                    return 'active'
                } else if (activityitem == 2) {
                    return 'inactive'
                } else if (activityitem == 3) {
                    return 'latched'
                } else if (activityitem == 4) {
                    return 'total_active'
                }
            },
            CheckReports() {
                uni.showToast({
                    title: '功能开发中',
                    icon: 'none'
                })
            },
            //跳转页面
            gotoMEL(item) {
                
                uni.navigateTo({
                    url: '/pages/station_view/showpdf'
                })

            },
            //初始化查询mel
            async CheckMEL() {
              
                //只有fde的有文件
                if (this.list[0].event.name != 'FDE') {
                    return
                }
                let de = this.list[0].event.description;
                let deinf = de.indexOf(":");
                let tagCode = "";
                if (deinf > 0) {
                    tagCode = de.substring(0, deinf);
                } else {
                    return;
                }
               
                let FDEitem = await getHandbookFDE({
                    model: "B787",
                    tagCode: tagCode
                })
                this.FDElist = FDEitem.data
                
            },
            //点击fde 跳转
            async clickFde(item) {
                
                //只有fde的有文件
                if (item.event.name != 'FDE') {
                    return
                }
                let de = item.event.description;
                let deinf = de.indexOf(":");
                let tagCode = "";
                if (deinf > 0) {
                    tagCode = de.substring(0, deinf);
                } else {
                    return;
                }
                
                let fimitem = await getHandbookFDE({
                    model: "B787",
                    tagCode: tagCode
                })
                if (fimitem.code == 200) {
                    
                }

            },

            //假数据
            processingUrl(url){
                let fimPath = 'http://tbr.hnatechnic.com:8080/ToolboxRemote.html#/FIM/da/FIM/bid/0_16/data/DMC-B787-A-27-20-F4-12A-421A-A/ap/B-7880'
                this.Jumpfim(fimPath)
            },

            // 处理url
            // processingUrl(url) {
            //     let fimPath = url
            //     let fimPathlist = []
            //     if (fimPath != '') {
            //         fimPathlist = fimPath.split(':')
            //         fimPath = 'http://tbr.hnatechnic.com:' + fimPathlist[2]
            //     }

            //     this.Jumpfim(fimPath)
            
            // },
            Jumpfim(fimPath) {
               
                uni.navigateTo({
                    url: '/pages/station_view/index7?fimPath=' + fimPath
                })
            },
            //假的跳转
            async mmsgclick(i, item) {
               
                if (this.showfalg == i) {
                    this.showfalg = -1;
                } else {
                    this.showfalg = i;
                }
            },
            // async mmsgclick(i, item) {
            //     if (this.showfalg == i) {
            //         this.showfalg = -1;
            //     } else {
            //         this.showfalg = i;
            //     }
            //     //清空list
            //     this.templist = [];
            //     this.fimNamelist = [];
            //     this.fimUrllist = [];
    
            //     if (item.event.eventDetails.length > 0) {
            //         for (var h = 0; h < item.event.eventDetails.length; h++) {
            //             this.flmlist(item.event.eventDetails[h], h, item.event.eventDetails.length)

            //         }
            //     }
            // },
            async flmlist(items, h, maxh) {
                let item = [];
                item = await getHandbookFIM({
                    code: items.code,
                    tailNum: items.tailnumber
                })
                let maps = {
                    'id': h,
                    'name': item.data[0].fimName,
                    // 'name': item.data[0].fimName + '=' + items.code, //加code确认是否正确
                    'url': item.data[0].fimPath
                }

                this.templist.push(maps);
             
                this.templist.sort(this.compare('id'))
            
                this.getfimName(h, maxh);

            },
            getfimName(h, maxh) {
                if (maxh == this.templist.length) {
                    for (let i = 0; i < this.templist.length; i++) {
                        this.fimNamelist.push(this.templist[i].name)
                        this.fimUrllist.push(this.templist[i].url)
                        
                    }
                   
                }

            },
            //排序
            compare(property) {
                return function(a, b) {
                    var value1 = a[property];
                    var value2 = b[property];
                    return value1 - value2;
                }
            },


        },
        components: {
            toHistory
        },

        created() {
           

        }

    }
</script>

<style scoped lang="scss">
   

    .font_weight {
        font-weight: 600
    }

    .acms_reports {
        width: 53%;
        background: #0299E3;
        text-align: center;
        color: #ffffff;
        border-radius: 4px;
    }

    .check_mel {
        //width:33%;
        margin-left: 10px;
        //background:  #0299E3;
        text-align: center;
        //color: #ffffff;
        color: #0299E3;
        border-radius: 4px;
    }

    .fimclass {
		margin-right: 10px;
        background: #0299E3;
        text-align: center;
        color: #ffffff;
        font-size: 11px;
        border-radius: 4px;
    }

    .a_top {
        margin-top: 10px;
    }

    .a_bottom {
        margin-bottom: 10px;
    }

    .am_bottom5 {
        margin-bottom: 5px;
    }

    .am_right {
        margin-right: 10px;
    }

    .a_right {
        width: 50%;
        padding-left: 20rpx;
    }

    .a_left {
        width: 50%;
        text-align: right;
        padding-right: 20rpx;
    }

    .a_left_sw {
        width: 50%;
        text-align: right;
        padding-right: 3rpx;
    }

    .a_left1 {
        width: 50%;
        //text-align: right;
        padding-right: 20rpx;
    }

    .logo {
        width: 100%;
        height: 60rpx;
        //padding-bottom: 3px;
    }

    .logo1 {
        width: 90%;
        height: 60rpx;
        padding-left: 20px;
        //padding-bottom: 3px;
    }

    .a_wai0 {
        margin-left: 10px;
        margin-right: 10px;
        display: flex;
        vertical-align: middle;
        background: #f0f0f0;
        margin-top: 15rpx;
        // margin-left: 9px;
        border: 1px solid #000000;
    }

    .a_wai1 {
        width: 95%;
        display: flex;
        vertical-align: middle;
        background: #F6E308;
        margin-top: 15rpx;
        // margin-left: 9px;
        border: 1px solid #000000;
    }

    .a_wai2 {
        width: 95%;
        display: flex;
        vertical-align: middle;
        background: #ffaa00;
        ;
        margin-top: 15rpx;
        // margin-left: 9px;
        border: 1px solid #000000;
        ;
    }

    .a_wai3 {
        width: 95%;
        display: flex;
        vertical-align: middle;
        background: #ff0000;
        margin-top: 15rpx;
        margin-left: 9px;
        border: 1px solid #000000;
    }

    .a_wai_5_0 {
        width: 5%;
        height: auto;
        background-color: #f0f0f0;
        text-align: center;
        margin: auto;
    }

    .a_wai_5 {
        width: 5%;
        height: auto;
        background-color: #F6E308;
        //background: #F6E308;
        text-align: center;
        margin: auto;
    }

    .a_wai_5_2 {
        width: 5%;
        height: auto;
        background-color: #ffaa00;
        background: #ffaa00;
        text-align: center;
        margin: auto;
    }

    .a_wai_5_3 {
        width: 5%;
        height: auto;
        background-color: #ff0000;
        background: #ff0000;
        text-align: center;
        margin: auto;
    }

    .a_wai_95 {
        width: 95%;
        //display: flex;
        background-color: #FDFDFD;

    }

    .em-history-box {
        font-size: 12px;
        // padding-bottom: 5px;
        display: flex;
    }

    .em-history-box-item {
        display: -webkit-box;
        display: -ms-flexbox;
        display: flex;
        -webkit-box-orient: vertical;
        -webkit-box-direction: normal;
        -ms-flex-direction: column;
        flex-direction: column;
        -webkit-box-align: center;
        -ms-flex-align: center;
        align-items: center;
        // margin-right: 3px;
        padding-left: 30px;
        width: 14px;
        min-width: 14px;
        align-items: center;
    }

    .ehbi-text {
        // margin-left: -3px;
        //padding-left:5px;
        margin-top: 2px;
        line-height: 1;
        white-space: nowrap;
    }

    .ehbi-dot {
        //padding-left:5px;
        width: 12px;
        height: 12px;
        background-color: #9e9e9e;
        border-radius: 100%;
        text-align: center;
        line-height: 12px;
        color: #ffffff;
        font-weight: bold;
        font-size: 12px;
        overflow: hidden;
        // margin-right: 3px;
    }

    .ehbi-dot-ak {
        width: 12px;
        height: 12px;
        background-color: transparent;
        border: 1px solid #9e9e9e;
        border-radius: 100%;
        text-align: center;
        line-height: 11px;
        color: #ffffff;
        font-weight: bold;
        font-size: 12px;
    }
</style>
