<template>
    <div class="fullHeight dataBoardPage" :class="{'dataBoardPage_blue':enabledProjectV2==3,'dataBoardPage_blue2':enabledProjectV2==4 ,'longguangBg':company=='longguang'}">
        <div class="headerBox">
            <p class="projectName">{{ $store.state.currentProDetail.projectName }}</p>
            <h1 class="title">
                <img v-if="headerLogo" style="width: auto;height: 30px;margin-right: 16px;" :src="headerLogo" />
                <span v-if="company != 'longguang'">
                <!-- 智慧工地云平台 -->
                {{$t('message.dataBoard.headerTitle')}}
                </span>
                <span v-else style="color:#fff;margin-top:15px">
                <!-- 龙光智慧工地平台 -->
                {{$t('message.dataBoard.headerTitle2')}}
                </span>
                <!-- {{ $t("message.carOverview.vehicleStatistics") }} -->
            </h1>
            <div class="headerDataBox">
                <div class="date">{{date}}</div>
                <div class="time">{{time}}</div>

                <!-- <div class="weatherBox"> -->
                    <img class="weaImg" :src="weatherInfo.url" width="26" height="26" />
                    <div class="tem">{{ weatherInfo.tem2 }} ~ {{ weatherInfo.tem1 }}</div>
                    <div class="wea">{{ weatherInfo.wea }}</div>
                <!-- </div> -->
                <!-- <div style="text-align: center;"> -->
                    <div class="win_speed">{{ weatherInfo.win_speed }}</div>
                    <!-- <div>风力</div> -->
                <!-- </div> -->
            </div>

            <closePage></closePage>
        </div>
        <div class="leftLine" v-if="enabledProjectV2!=3"></div>
        <div class="rightLine" v-if="enabledProjectV2!=3"></div>
        <div class="bottomLine" v-if="enabledProjectV2!=3"></div>
        <div style="height: 40px" class="menuBox">
            <ul v-if="parameterUrl.COMPANY != 'longguang'" class="left">
                <li v-for="(item,index) in menuList" :key="index" :class="{'right':index > (menuList.length-1)/2,'active':$route.path==item.modulePath}" @click="menuClick(item,index)">{{item.moduleName}}</li>
            </ul>
        </div>
        <div class="dataBoardContent">
            <router-view ></router-view>
        </div>
    </div>
</template>
<script>
    function GetRequest() {
        var url = decodeURI(window.location.href); //?id="123456"&Name="bicycle";
        var object = {};
        if(url.indexOf("?") != -1)//url中存在问号，也就说有参数。
        {
            var str = url.substr(url.indexOf("?")+1); //得到?后面的字符串
            var strs = str.split("&"); //将得到的参数分隔成数组[id="123456",Name="bicycle"];
            for(var i = 0; i < strs.length; i ++)
            {
                object[strs[i].split("=")[0]]=strs[i].split("=")[1]
            }
        }
        return object;
    }//截取地址栏的参数
import closePage from "@/components/closePage"
import {
  getWeatherDataApi
} from "@/assets/js/api/environmentManage";
export default {
    components:{closePage},
    data(){
        return{
            menuIndex:0,
            menuList:[],
            enabledProjectV2:2,
            date:'',
            time:'',
            weatherInfo:{
                wea_img:'',
                tem1:'',tem2:'',
                wea:'',win_speed:'',url:'',
                cityName: ""
            },
            parameterUrl:'',
            headerLogo: ""
        }
    },
    created(){
        this.parameterUrl = GetRequest()
        // COMPANY: "longguang"
        this.company = COMPANY;
        console.log(GetRequest().COMPANY != 'longguang');
    },
    mounted(){
        if(localStorage.getItem('systemInfo')){
            this.headerLogo = JSON.parse(localStorage.getItem('systemInfo')).bigScreenLogo
        }
        this.getTime()
        this.loadWeather()
        this.enabledProjectV2=enabledProjectV2
        document.title=this.$store.state.currentProDetail.projectName+this.$t('message.dataBoard.dataBoard')
        this.getAllModule()
    },
    methods:{
        getTime(){
            var myDate = new Date(); //实例一个时间对象；
            this.date=myDate.getFullYear();   //获取系统的年；
            this.date+='-'+(myDate.getMonth()+1);   //获取系统月份，由于月份是从0开始计算，所以要加1
            this.date+='-'+myDate.getDate(); // 获取系统日，
            this.time=' '+myDate.getHours(); //获取系统时，
            this.time+=':'+myDate.getMinutes(); //分
            this.time+=':'+myDate.getSeconds(); //秒

            setTimeout(() => {
                this.getTime()
            }, 1000);
        },
        loadWeather(){
            var _this = this
            getWeatherDataApi({cityid:this.$store.state.currentProDetail.cityCode}).then((res) => {
                var json = JSON.parse(res.result);
                console.log(json);
                this.weatherInfo = json.data[0]
                this.weatherInfo.url = require('@/assets/images/weather/'+this.weatherInfo.wea_img+'.png')
            });
        },
        getAllModule(){
            var half = this.$store.state.userInfo.menuAuthority.moduleList
            console.log(half)
            half.forEach(element => {
                console.log(element.moduleName)
                if(element.moduleType==4){
                    console.log(element)
                    this.menuList.push(element)
                }
            });
        },
        menuClick(item,index){
            console.log('item', item)
            this.menuIndex = index;

            if (item.modulePath.includes('http://') || item.modulePath.includes('https://')) {
                return window.open(item.modulePath)
            }

            if(item.moduleName == '智能安全帽') {
                let NodeRSA = require("node-rsa");
                //请求参数
                let params = JSON.stringify({
                    // account: '妇幼保健院',
                    account: this.$store.state.userInfo.account,
                    page_flag: 3,
                });
                //公钥
                const pubKey = `
            -----BEGIN PUBLIC KEY-----
            MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDcmP0ug4NTHwW2oeHxheZjmYPDxVGFP770eECdLwRtaH0pPWvsXG6MSO/kCzgjEVEo1K1bvRxkkasQRu02fhI+gsZa8wvVeo3s4zJDA48Oj99JAXsx56/WN1RlNh+tsXcH9oQWy3gbX5cDkheuVZj8gsV7Ez59Ucj4e78zNJrUDwIDAQAB
            -----END PUBLIC KEY-----`;

                var publicKey = new NodeRSA(pubKey);
                var async_key = publicKey.encrypt(params, 'base64')
                window.open("http://58.210.96.206:91/async_danzhou.html?async_key="+async_key)
                // window.location.href = "http://58.210.96.206:91/async_danzhou.html?async_key="+async_key;
            } else {
                this.$router.push(item.modulePath)
            }
            
        }
    }
}
</script>
<style lang="less" scoped>
 @import url("./style.less");
 .headerDataBox{
     position: absolute;
     right: 100px;
     top:5px;
     display: flex;
     align-items: center;
     font-size: 16px;
    //  .time{
    //      font-size: 22px;
    //  }
     &>*{
         margin-right: 20px;
     }
 }
 .headerBox{
     .title{
         display: flex;
         align-items: center;
         justify-content: center;
         font-size: 32px;
     }
 }
//  .dataBoardPage{
//      background-color: blue;
//  }
</style>
