<template>
    <div class="common_header_pc_1">
        <div class="header-top">
            <div class="container">
                <div class="row">
                    <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 hidden-xs">
                        <div class="header-top-left">
                            <span class="sp1" id="djs">{{CUR_TIME}}</span>
                           <!-- <span class="sp2">{{placeholder}}<i>26,265,890</i></span> -->
                        </div>
                    </div>
                    <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                        <div class="header-top-right">
                            <ul>
                                <!--<li><a href="">微信公众号</a></li>
                                丨
                                <li class="share"><a href="">分享</a></li>
                                丨 -->

                                 <li class="afterlogin" v-if="userData && userData.custName">
                                   <span class="sp1">
                                       <img v-if="userData.photo" :src="userData.photo" alt="">
                                       <img v-else src="../../theme-chalk/src/images/header.jpg" alt="">
                                    </span>
                                   <span class="sp2" style="margin-left:10px;"><a href="javascript:void(0)" @click="toCenter" >{{userData.custName}}</a></span>
                                   <span class="sp3" style="margin-left:10px;"><a @click="logout" href="javascript:void(0)">退出登录</a></span>
                                </li>
                                <li v-else><a  @click="regAccount" href="javascript:void(0)" >注册</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="header-main">
            <div class="container">
                <div class="row">
                    <div class="col-lg-7 col-md-7 col-sm-7 col-xs-12">
                        <div class="header-main-logo">
                            <a href=""><img src="../../theme-chalk/src/images/pic.png" alt=""></a>
                            <span class="sp1">主办：安徽省应急管理宣传教育中心</span>
                        </div>
                    </div>
                    <div class="col-lg-5 col-md-5 col-sm-5 col-xs-12">
                        <div class="header-main-search">
                            <span class="sp1">服务电话：0551-62640921</span>
                            <span class="sp2">
                       <input type="text" placeholder="输入关键字进行查找" v-model="isearch" class="inpkuang">
                       <input type="button" value="搜索" @click="search" class="subbtn">
                    </span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="header-menu">
                <div class="container">
                    <div class="row">
                        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                            <div class="sp_nav hidden-lg hidden-sm hidden-md"><span></span><span></span><span></span>
                            </div>
                            <div class="header-menu-body sjj_nav">
                                <ul id="hearderul">
                                    <li><a @click="jump($event)" href="/index?type=sy">首页</a></li>
                                    <li><a id="pxjh" @click="jump($event)" href="/projectlist?type=pxjh">培训计划</a></li>
                                    <li><a @click="jump($event)" href="/courselist?type=kccs">课程超市</a></li>
                                    <li><a @click="jump($event)" href="/infolist?name=用户指南&type=yhzn">用户指南</a></li>

                                    <li><a @click="jump($event)" href="/infolist?name=通知公告&type=tzgg">通知公告</a></li>
                                    <li><a @click="jump($event)" href="/infolist?name=政策法规&type=zcfg">政策法规</a></li>
                                    <li><a @click="jump($event)" href="/hoursinquiry?type=xscy">学时查验</a></li>
                                    <li><a @click="jump($event)" href="/aboutus?type=gywm">关于我们</a></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
   <el-login ref="child" @setOpen="setOpen" @isphone="isPhone" @isname="isName" @iscard="isCard"  @iscode="isCode" @dataNull="dataNull" :isCard="iscard" :isPhone="isphone" :isName="isname" :isCode="iscode" :open="isOpen"></el-login>

    </div>
</template>

<script>
import formMixin from "../../../src/mixins/formMixin";
import lenye_base from "lenye_base";
import $ from "fy-kit";
import login from "../../login";
import msg from "../../message";

export default {
  name: "ElHeaders",
  mixins: [formMixin],
  props: {
    placeholder: {
      type: String,
      default: "总访问量："
    }
  },
  components: {
    login,
    msg
  },
  computed: {
    defaultAttrs() {
      return {
        placeholder: this.t("ele-form.input") + this.desc._label
      };
    }
  },
  mounted() {


    //setInterval(()=>{
    this.init();

    //},1000)
    if(localStorage.userData){
         this.info();
    //    this.userData = JSON.parse(localStorage.userData);
    }


    this.name = location.pathname;
  },
  filters: {
    $toData(data) {
      return $.date.moment(data).format("YYYY年MM月DD日");
    }
  },
  data() {
    return {
      isearch: "",
      isWx: true,
      hasWx: true,
      isOpen: false,
      isphone: false,
      iscode: false,
      iscard: false,
      isname: false,
      loginName: "",
      password: "",
      datas: {},
      userData: {},
      name: "/index",
      CUR_TIME: "",


    };
  },
  methods: {
    info(){

        $.util
        .ajax(
          lenye_base.base_data.getapiUrl() +
            "/base-service/api/cust/userSelf/detail.do",
          lenye_base.base_data.getformatting({})
        )
        .then(res => {
            if(res.success == '1'){
                this.userData = res.data;
            }else{
                msg.error(res.message);
            }
        })
    },
    toCenter() {
      $.util
        .ajax(
          lenye_base.base_data.getapiUrl() +
            "/base-service/api2/custUserIdentity/queryUserIdentities.do",
          lenye_base.base_data.getformatting({})
        )
        .then(res => {
          if (res.success === "1") {
            // this.datas = res.data;
            if (res.data && res.data[0] && res.data[0].idtCode) {
              if (res.data[0].idtCode == "company") {
                window.location.href = "/comcenter";
              } else {
                window.location.href = "/merchantcenter";
              }
            } else {
              window.location.href = "/personcenter";
            }
          } else {
            msg.error(res.message);
          }
        });
    },
    setActive(num) {
      var ul = $._.default("#hearderul");
      ul
        .find("li")
        .eq(num)
        .addClass("active")
        .siblings("li")
        .removeClass("active");
    },
    logout() {
      localStorage.clear();
      lenye_base.user_data.loginOut();
      // todo
      setTimeout(function() {
        window.location.href = "/?type=sy";
        window.parent.location = "/?type=sy";
      },1000)

     // window.location.reload();
    },
    jump(ev) {
      var ele = $._.default(ev.target);
      ele
        .parent("li")
        .addClass("active")
        .siblings("li")
        .removeClass("active");//infolist

       /* if(ele.html()=='用户指南'){
          $.util.storage('parentName').set('用户指南');
          window.location.href = '/infolist';
        }else if(ele.html()=='通知公告'){
          $.util.storage('parentName').set('通知公告');
          window.location.href = '/infolist';
        }else if(ele.html()=='政策法规'){
          $.util.storage('parentName').set('政策法规');
          window.location.href = '/infolist';
        }
        */



    },
    init() {
      //
      $.util
        .ajax(
          lenye_base.base_data.getapiUrl() + "/base-service/common/sysdate.do",
          lenye_base.base_data.getformatting({})
        )
        .then(res => {
          if (res.success === "1") {
            this.datas = res.data;
            var t = 1000;
            setInterval(() => {
              t += 1000;
              this.CUR_TIME = $.date
                .moment(
                  new Date(
                    res.data.CUR_DATE + " " + res.data.CUR_TIME
                  ).getTime() + t
                )
                .format("YYYY年MM月DD日 HH:mm:ss");
            }, 1000);
            switch ($.util.urlParams('type')) {
              case "sy":
                this.setActive(0);
                break;
              case "pxjh":
                this.setActive(1);
                break;
              case "kccs":
                this.setActive(2);
                break;
              case "yhzn":
                this.setActive(3);
                break;
              case "tzgg":
                this.setActive(4);
                break;
              case "zcfg":
                this.setActive(5);
                break;
              case "xscy":
                this.setActive(6);
                break;
              case "gywm":
                this.setActive(7);
                break;
            }
          } else {
            msg.error(res.message);
          }
        });
    },
    search() {
      window.location.href = "/fullsearch?isearch="+this.isearch;
    },

    setOpen(data) {
      this.isOpen = data;
    },

    regAccount() {
      this.isOpen = true;
      this.$refs.child.clearData();
    },
    isPhone(data) {
      this.isphone = data;
    },
    isName(data) {
      this.isname = data;
    },
    isCode(data) {
      this.iscode = data;
    },
    isCard(data) {
      this.iscard = data;
    },
    dataNull(data) {
      this.isphone = data;
      this.iscode = data;
    }
  }
};
</script>
