<template>
  <div class="view-top clearfix">
      <audio ref='bgaudio' :src="webconfig.BgMusic" loop="loop" autoplay="true"></audio>
      <!-- 公告 -->
        <div class="notice box-sizing">
          <marquee class="message" behavior="scroll" scrollamount="3" scrolldelay="30"><span v-for="item in userInfo.memo">{{item.title}}</span></marquee>
          <div class="tip-box"><span v-for="item in userInfo.memo">{{item.title}}</span></div>
        </div>
        <div class="setup">
            <el-tooltip v-if="webconfig.isServerCode||false" class="item" effect="dark" :content="Language.tip_service" placement="bottom">
                <span  @click="openCustomerService()" class="btn service" ></span>
            </el-tooltip>
            <el-tooltip class="item" effect="dark" :content="Language.tip_cn_tw" placement="bottom">
                <span  @click="isShowPop('updatelang')" class="btn fontj" ></span>
            </el-tooltip>
          <el-tooltip class="item" effect="dark" :content="Language.tip_audio" placement="bottom">
            <span @click="switchAudio" class="btn audio-btn" :class="{'on':isAudio}"></span>
          </el-tooltip>
          <el-tooltip class="item" effect="dark" :content="Language.game_record" placement="bottom">
              <span class="btn history-btn" @click="isShowPop('history');"></span>
          </el-tooltip>
          <el-tooltip class="item" effect="dark" :content="Language.tip_game_rule" placement="bottom">
              <span class="btn rules-btn" @click="isShowPop('rules');"></span>
          </el-tooltip>
          <el-tooltip class="item" effect="dark" :content="Language.tip_recharge_withdraw" placement="bottom">
              <span class="btn recharge-info-btn" @click="isShowPop('rechargeInfo');"></span>
          </el-tooltip>
          <el-tooltip class="item" effect="dark" :content="Language.edit_pass" placement="bottom">
             <span class="btn updatepwd-btn"  @click="isShowPop('updatepwd');"></span>
          </el-tooltip>
          <el-tooltip class="item" effect="dark" :content="Language.tip_refresh" placement="bottom">
            <span class="btn setting-btn" @click="reload();"></span>
          </el-tooltip>
           <el-tooltip class="item" effect="dark" :content="Language.tip_exit" placement="bottom-end">
            <span class="btn signout-btn" @click="logout"></span>
          </el-tooltip>
        </div>
  </div>
</template>
<script>
import { mapState} from 'vuex'
import {Tooltip} from 'element-ui';
export default {
  data(){
    return{
      isAudio:this.getStorage('audio') ,
      userInfo:this.$store.state.userInfo,
      is_sw:'',
    }
  },
  components: {
    'el-tooltip':Tooltip,
  },
  mounted: function(){

    this.$refs.bgaudio.muted = !this.isAudio;

    // this.notice=this.$store.state.userInfo.memo;
    this.is_sw=this.$store.state.userInfo.is_sw;
  },
  methods: {
    switchAudio(){
       this.setStorage('audio',!this.isAudio)
       this.isAudio=!this.isAudio;
       this.$refs.bgaudio.muted = !this.isAudio;
       this.$store.dispatch('isAudio');

    },
    isShowPop(type){
      if(this.is_sw==1&&type=='updatepwd'){
        this.$message.error(this.Language.trial_account2);
      }else{
        this.$store.dispatch('updatemainPop',{type:type,ishow:true});
      }

    },
    openCustomerService(){
      this.$root.$emit('openCustomerService');
    },
    offPop(){
      this.$store.dispatch('updatemainPop',{type:'',ishow:false});
    },
    reload(){
      this.$router.go(0);
    },
    // 退出登录
    logout(){
        var _this=this;
      this.$alert(_this.Language.exit_logout, _this.Language.tip_exit, {
          confirmButtonText: _this.Language.confirm,
          callback: action => {
            if(action=='confirm'){
               ////////清除在线人数的定时器
             clearInterval(_this.$store.state.numTimer) ;
               this.$cookies.remove('userInfo');
               this.$message({message:_this.Language.exit_logout,type: 'success'});
               this.$router.push({ path:'/'})
               window.location.reload();
            }
          }
        });
    }
  },
  computed: {
    ...mapState(['webconfig','Language'])
  }
}
</script>

<style scoped>
    .view-top .setup .btn.service{
        background-image:url(../../common/image/icon/kf.png);
    }
    .view-top .setup .btn.fontj{
        background-image:url(../../common/image/icon/jt.png);
    }
   .view-top{
    height: 0.5rem;
    width:100%;
  }
   .view-top .notice{
      width:9.5rem;
      color:#fff;
      border: .02rem solid #3b2b1d;
      background: #1f150e;
      border-radius: .2rem;
      cursor: pointer;
      font-size: 12px;
      background: url(../../common/image/icon/icon_msg.png) 10px center no-repeat;
      -webkit-background-size: 18px;
      background-size: 18px;
      float: left;
  }
   .notice{
    position: relative;
   }
   .notice .message{
    display:block;
    line-height: 0.4rem;
    margin-left: 0.45rem
  }
  .notice .tip-box{
    position: absolute;
    left:50%;
    margin-left: -2.5rem;
    top: 0.58rem;
    z-index: 999;
    background: rgba(0,0,0,0.8);
    color: #faf1b4;
    font-weight: 600;
    width:5rem;
    padding: 0.1rem;
    border-radius: 5px;
    -webkit-box-shadow:0 0 2px rgba(255, 255, 255, .5);  
    -moz-box-shadow:0 0 2px rgba(255, 255, 255, .5);  
    box-shadow:0 0 2px rgba(255, 255, 255, .5); 
    transition: 0.5s all; 
    display: none;
  }
  .notice:hover .tip-box{
    display: block;
  }
  .notice .tip-box:after{
    content: "";
    width:0;
    height:0;
    border-right:10px solid transparent;
    border-left:10px solid transparent;
    border-bottom:10px solid rgba(0,0,0,0.8);
    position: absolute;
    top: -8px;
    left:50%;
    margin-left: -5px;
  }
   .view-top .setup{
    float: left;
    width:5rem;
    height: 0.5rem;
  }

   .view-top .setup .btn{
    float: left;
    width:0.45rem;
    height: 0.5rem;
    margin-left: 0.13rem;
    -webkit-background-size: 0.35rem;
    background-size: 0.35rem;
    background-position-x: center;
    background-position-y: center;
    background-repeat: no-repeat;
    cursor: pointer;
  }

   .view-top .audio-btn.on{
    background-image:url(../../common/image/icon/btn_volume_on.png);
  }
   .view-top .audio-btn{
    background-image:url(../../common/image/icon/btn_volume_off.png);
  }
   .view-top .history-btn{
    background-image:url(../../common/image/icon/btn_history.png);
  }
   .view-top .rules-btn{
    background-image:url(../../common/image/icon/btn_help.png);
  }
   .view-top .updatepwd-btn{
    background-image:url(../../common/image/icon/btn_lock.png);
  }
   .view-top .setting-btn{
    background-image:url(../../common/image/icon/btn_setting.png);
  }
   .view-top .signout-btn{
    background-image:url(../../common/image/icon/btn_exit.png);
  }
   .view-top .recharge-info-btn{
    background-image:url(../../common/image/icon/icon_money.png);
  }


</style>