<template>
  <div>
    <div class="xtop">
      <div class="xtop-content xcontent">
      <div class="xtop-left">
        <!-- <div> -->
          <router-link class="routerLink" to="/index"><img src="../../../assets/logo/logo2.png" style="width:240px;height: 40px;" /></router-link> 
        <!-- </div> -->
        <div class="xtop-nav">
          <div><a :href="`${webBaseUrl}/index`">首页</a></div>
          <div><a :href="`${webBaseUrl}/course`">课程</a></div>
          
          <div><a :href="`${webBaseUrl}/article`">文章</a></div>
          <div><a :href="`${webBaseUrl}/qa`">问答</a></div>
          <div>
            <el-dropdown placement="bottom" @command="handleCommand">
              <span class="el-dropdown-link" style="color:#fff;font-size:16px;cursor: pointer;">专区</span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command='one'>BOE系列公开课</el-dropdown-item>
                <el-dropdown-item command='two' divided>Grow180</el-dropdown-item>
                <el-dropdown-item command='three' divided>管理者进阶</el-dropdown-item>
                <el-dropdown-item command='four' divided>U选小课堂</el-dropdown-item>
                <el-dropdown-item command='five' divided>社招新员工</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
          <div><a :href="`${webBaseUrl}/case`">推荐案例</a></div>
          <div><a :href="`${webBaseUrl}/follow`">我的关注</a></div>
        </div>
      </div>
      <div class="xtop-right" style="display: flex;justify-content: flex-end;align-items: center;">
         <!-- <div style="margin-left:250px;margin-right:50px;"> -->
            <!-- <el-input placeholder="搜索" style="width: 260px;border-radius: 20px !important;" @keyup.enter.native="searchJump()" clearable maxlength="50" v-model="keyword" class="input-with-select">
              <el-select  v-model="findType" style="width: 75px;" slot="prepend" placeholder="请选择">
                <el-option label="课程" value="1"></el-option>
                <el-option label="案例" value="2"></el-option>
                <el-option label="文章" value="3"></el-option>
                <el-option label="问答" value="4"></el-option>
              </el-select>
              <el-button slot="append" icon="el-icon-search" @click="searchJump()" class="input-with-select-btn"></el-button>
            </el-input> -->
          <!-- </div> -->
        <div>
            <el-badge :value="userMsg" :hidden="userMsg==0" class="message-count">
              <!-- <el-link type="primary" :href="`${webBaseUrl}/message`" target="_blank" icon="el-icon-message-solid" :underline="false"></el-link> -->
              <svg-icon style="margin-right: 0;font-size:26px;" icon-class="messfff"></svg-icon>
            </el-badge>
          </div>
          <el-dropdown class="person-action-index" style="margin-left: 44px;">
              <span class="el-dropdown-link">
                 <span v-if="current == 'qa'" style="color: #333;">学员</span> 
                <span v-else style="color: #fff;">学员</span><i class="el-icon-arrow-down el-icon--right"></i>
               
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item>学员</el-dropdown-item>
                <el-dropdown-item>教师</el-dropdown-item>
                <el-dropdown-item>管理员</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          <div style="margin-left: 50px;color: #fff;"><el-avatar :src="userInfo.avatar" style="vertical-align: middle;width:40px;height:40px;margin-right:10px;"></el-avatar>{{userInfo.name}}</div>
          <!-- <div style="margin-left: 5px;">
            <el-dropdown @command="handleUcCommand">
              <span class="el-dropdown-link">
                {{userInfo.name}}<i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="logout">退出</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div> -->
		  <div class="person-action">
		    <el-button @click="logout()" type="text"><svg-icon  style="margin-right: 4px;font-size:22px;color: #000;" icon-class="white-out"></svg-icon>退出</el-button>
		  </div>
      </div>
      </div>
    </div>
    <el-dialog title="修改登录密码" :close-on-click-modal="false" :visible.sync="pwdDlg.show" width="600px" custom-class="g-dialog">
      <el-form :model="pwdDlg" size="medium" label-width="100px">
        <el-form-item label="当前密码"><el-input v-model="pwdDlg.nowPwd" type="password" placeholder="当前的登录密码" :style="{ width: '100%' }"></el-input></el-form-item>
        <el-form-item label="新密码">
          <el-input v-model="pwdDlg.newPwd" type="password" placeholder="新的密码" :maxlength="20" clearable :style="{ width: '100%' }"></el-input>
        </el-form-item>
        <el-form-item label="密码确认">
          <el-input v-model="pwdDlg.rePwd" type="password" placeholder="和上面新密码一致" :maxlength="20" clearable :style="{ width: '100%' }"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="pwdDlg.show = false">取 消</el-button>
        <el-button type="primary" @click="submitPwd">提交修改</el-button>
      </span>
    </el-dialog>
    <el-dialog custom-class="dialog-signin" :show-close="false" :visible.sync="signInShow" :close-on-click-modal="false" width="520px" top="8vh">
       <div>
         <img usemap="#HotMap" src="/pc/ad/dlg.png" style="width:416px;height: 576px;">
         <map name="HotMap" id="HotMap">
             <area shape="circle" name="link1" coords="380,40,30" @click="closeSignDlg" href="javascript:;" />
             <area shape="rectangle" name="link2" coords="150,400,300,500" target="_blank"  href="https://boehrsurvey.wjx.cn/vm/PmreuFN.aspx"  />
           </map>
        </div>

    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from 'vuex';
import desk from '@/api/console.js';
import Cookies from 'vue-cookies';
export default {
  data() {
    return {
      checked:true,
      signInShow: false,
      signLocalTimesKey:'xboe_sign_dlg_times',
      keyword: '',
      findType: '1',
      mouseIndex: 0,
      activeIndex: '',
      msg: { num: 0 },
      user: { name: '' },
      pwdDlg: { show: false, newPwd: '', nowPwd: '', rePwd: '' },
      current:1
    };
  },
  computed: {
    ...mapGetters(['userInfo', 'userMsg']),
    showName: function() {
      //console.log('name='+this.name);
      //console.log('loginName='+this.loginName);
      if (this.userInfo.name != '') {
        return this.userInfo.name;
      } else {
        return this.userInfo.userName;
      }
    }
  },
  mounted() {
    //控制弹出窗口的代码
    let now = new Date() //当前时间
    let end = new Date('2022/08/14 00:00:00') //对比时间
    if(now.getTime() < end.getTime()){
        let times = localStorage.getItem(this.signLocalTimesKey);
        let isNewLogin=localStorage.getItem(this.$Constants.newLoginKey);
        //let isNewLogin='1';
        if(isNewLogin && isNewLogin=='1'){
          if(!times){
            this.signInShow = true;//显示
            localStorage.setItem(this.signLocalTimesKey,1);
          }else{
            let intTimes=parseInt(times);
            if(intTimes<2){
               this.signInShow = true;//显示
               intTimes++;
               localStorage.setItem(this.signLocalTimesKey,intTimes);
            }
          }
          localStorage.setItem(this.$Constants.newLoginKey,0);
        }

    }
    this.$store.dispatch('refrashMsg');
  },
  methods: {
    closeSignDlg(){
       this.signInShow=false;
    },
    handleCommand(val) {
      // let obj = {
      //   one: process.env.VUE_APP_BOE_WEB_URL+'/web/teacherLesson',
      //   two: process.env.VUE_APP_BOE_WEB_URL+'/grow180/login',
      //   three: this.webBaseUrl + '/study/index',
      //   four: 'https://m.qingxuetang.com/x/?appId=qxtcorp306130',
      //   five: process.env.VUE_APP_BOE_WEB_URL+'/boe/new-employee/index.html'
      // };
      let urlPre=window.location.protocol+'//'+window.location.host;
      // process.env.VUE_APP_BOE_WEB_URL
      let obj = {
        one: urlPre+'/web/teacherLesson',
        two: urlPre+'/grow180/login',
        three: this.webBaseUrl + '/study/index?study=1',
        four: 'https://m.qingxuetang.com/x/?appId=qxtcorp306130',
        five: urlPre+'/boe/new-employee/index.html'
      };
      window.open(obj[val]);
    },
    handleUcCommand(val){
      if(val == 'logout'){
        this.logout();
      }
    },
    handleSelect(key, keyPath) {
      //console.log(key, keyPath);
    },
    showPwd() {
      this.pwdDlg.show = true;
    },
    submitPwd() {
      if (this.pwdDlg.nowPwd == '' || (this.pwdDlg.newPwd == '') | (this.pwdDlg.rePwd == '')) {
        return;
      }
      let params = {
        loginName: this.loginName,
        old: this.pwdDlg.nowPwd,
        newPassword: this.pwdDlg.newPwd,
        rePassword: this.pwdDlg.rePwd
      };
      desk.updatePassword(params).then(res => {
        if (res.status == 200) {
          this.$message({ message: '修改成功，请重新登录', type: 'success' });
        } else {
          this.$message({ message: '修改失败，请检查输入', type: 'error' });
        }
      });
    },
    logout() {
      this.$confirm('确定退出系统吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$store.dispatch('LogOut').then(() => {
          //location.href = this.webBaseUrl + '/login';
          location.href =process.env.VUE_APP_LOGIN_URL;
        });
      });
    }
  }
};
</script>

<style lang="scss" scoped>
::v-deep.xtop .xtop-right .person-action[data-v-5bcef51e] .message-count i{
  color: #fff !important;
}
.el-button--text{
  color: #fff;
}
::v-deep .dialog-signin{
  background: transparent;
  box-shadow:none;
 .el-dialog__header{
    padding: 0;
  }
  .el-dialog__body{
    padding: 0;
  }
  .el-dialog__footer {
    padding: 0;

}
.signin-bg{
  position: relative;
  .el-icon-close{
    position: absolute;
    top: 20px;
    right: 10px;
    color: #fff;
    font-size: 16px;
  }
}
.signin-box2{
	margin-left: 100px;
	font-size: 12px;
	.signin-checkbox{
		display: flex;
		align-items: center;
		color: #FFFFFF;
		margin-top: 10px;
		.el-checkbox{
			margin-right: 5px;
		}
	}
	.signin-text{
		font-family: Alibaba PuHuiTi;
		font-style:italic;
		cursor: pointer;
		margin-left: 20px;
		color:#003eb7;
		font-weight: bolder;
	}
}
  .signin-box{
    margin: 0 70px;
    p{
      line-height: 28px;
    }
    .signin-text{
      font-size: 12px;
      font-weight: bold;
      color: #FFFFFF;
      .ti-yan{
        border-bottom: 1px solid #FFFFFF;
        margin-left: 10px;
        cursor: pointer;
      }
      img{
        width: 14px;
        height: 14px;
        margin-left: 6px;
        vertical-align: middle;
        margin-bottom: 4px;
      }
    }
    .signin-a{
      font-size: 12px;
      font-family: Alibaba PuHuiTi;
      font-weight: 600;
      color: #FFFFFF;
      span{
        border-bottom: 1px solid #FFFFFF;
      }
    }
    .signin-b{
      font-size: 12px;
      color:#FFFFFF;
      text-align: right;
      .el-checkbox__inner{
        //background-color: #588AFC;
        border-color: #FFFFFF;
      }
      .el-checkbox__input.is-checked .el-checkbox__inner{
        background-color: #588AFC;
      }
    }
  }
}
.dialog-footer-signin{
  display: flex;
  justify-content: space-between
}
.xtop {
  height: 72px;
  line-height: 72px;
  background-color: #302F33;
  position: fixed;
  top: 0px;
  left: 0px;
  right: 0px;
  width: 100%;
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #e9e9e9;
  z-index: 9999;
  .xtop-content{
    width: 100%;
    display: flex;
    justify-content: space-between;
  }
}
.xtop .xtop-left {
  display: flex;
  justify-content: flex-start;
  .routerLink{
    padding-right: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
  }
}

.xtop-nav {
  display: flex;
  // justify-content: flex-start;
  a{
    display: inline-block;
  }
}
.xtop-nav > div {
  line-height:72px;
  padding: 0px 24px;
  color: #fff;
}

.xtop .xtop-right {
  .person-action{
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-left: 44px;
    ::v-deep .message-count{
      margin-right: 30px;
      i{
        font-size: 26px;
        color:#409EFF;
      }
    }
    .el-avatar{
      margin-right: 8px;
    }
    .el-button{
		margin-top: 1px;
      // margin-left: 20px;
    }
  }
}
.xtop .xtop-right > ul {
  list-style: none;
  margin: 0px;
}
.xtop .xtop-right > ul > li {
  list-style: none;
  display: inline-block;
  margin: 0px 2px;
  padding: 0px 15px;
  font-size: 14px;
}

.xtop .arrow-down {
  content: '';
  width: 0;
  height: 0;
  border-style: solid dashed dashed;
  border-color: #000000 transparent transparent;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-transition: all 0.2s;
  position: absolute;
  top: 50%;
  margin-top: -3px;
  border-width: 6px;
  border-top-color: #000000;
}
.xtop .arrow-up {
  margin-top: -9px;
  border-style: dashed dashed solid;
  border-color: transparent transparent #000000;
}
.xtop-user {
  width: 110px;
}
.xtop-user-img {
  width: 20px;
  height: 20px;
  border: none;
  display: inline-block;
  vertical-align: middle;
  border-radius: 50%;
}
.xtop-user-menu {
  right: 0px;
  top: 40px;
  background-color: #f4f4f4;
  color: #202020;
  position: absolute;
  width: 140px;
  z-index: 1000;
  padding: 15px 0px;
}
.xtop-user-menu > ul {
  padding: 0px;
  list-style: none;
}
.xtop-user-menu > ul > li {
  display: block;
  text-align: left;
}
.xtop-user-menu > ul > li.divider {
  height: 1px;
  margin: 5px 0px;
  border-bottom: 1px solid #989898;
}
.xtop-user-menu > ul > li > a {
  display: block;
  padding-left: 30px;
  line-height: 30px;
  font-size: 14px;
}
.xtop-user-menu > ul > li > a:hover {
  background-color: #cccccc;
}
.xtop-find {
  border: 1px solid #c9c9c9;
  background-color: #f3f3f3;
  border-radius: 5px;
  line-height: 25px;
  height: 25px;
  display: inline-block;
  padding: 0px 5px;
  input {
    background-color: transparent;
    border: 0px;
    line-height: 25px;
    height: 25px;
  }
  input:focus {
    outline: none;
  }
}
.message-count a{
    color: #fff;
    font-size: 28px;
    margin-top: 0 !important;
}
::v-deep .el-badge{
  margin-top: 0 !important;
  .el-badge__content{
    top: 20px;
  }
}
::v-deep .el-link.el-link--primary:hover {
  color:#588AFC;
}
.el-dropdown-link{
  cursor: pointer;
  color: #fff;
}
</style>
