<template>
    <div class="newheader">
        <div class="headerlogo">
             <div class="logo">公务员平时考核管理系统</div>
        </div>
        <div class="rightinfo">
          <notice style="margin-right: 30px;cursor: pointer;"/>
           <div v-if="objectList.length>0" style="margin-right: 30px">
                <Dropdown @on-click="clickChange">
                <Badge>
                    <Icon :size="18" type="icon iconfont iconquyu"></Icon>&nbsp;
                    <span style="font-size: 13px;font-weight: bold;">{{objectName}}</span>
                </Badge>
                <Icon :size="18" type="md-arrow-dropdown"></Icon>
                <DropdownMenu slot="list">
                    <DropdownItem v-for="item in objectList" :name="item.objectId" :key="item.objectId" :selected="objectName==item.objectName">
                    <span style="font-size: 13px;font-weight: bold;">{{item.objectName}}</span>
                    </DropdownItem>
                </DropdownMenu>
                </Dropdown>
            </div>
           <user :message-unread-count="unreadCount" :depName="depName" :postNameAndRankName="postNameAndRankName" :user-name="userName" :user-avatar="userAvatar" style="margin-right:30px"/>
            <div class="fullscreendiv">
                <fullscreen v-model="isFullscreen" style="margin-top: 8px;"/>
            </div>
        </div>
    </div>
</template>
<script>
import User from '../../bc-components/bc-main/components/user'
import Notice from '../../bc-components/bc-main/components/notice'
import { mapGetters } from 'vuex'
import Fullscreen from '../../bc-components/bc-main/components/fullscreen'
import userImg from '@/assets/images/user.png'
export default {
    components:{User,Notice,Fullscreen},
    inject: ['reload'],
    data(){
        return {
            isFullscreen: false,
            isRouterAlive: true,
            objectId:'',
            objectName:'',
            userType:'',
            objectList:[],
            quarterlyOpenTag:1,
            userImg,
            monthOpenTag:1,
            depName:'',
            postNameAndRankName:'',
        }
    },
    computed: {
        ...mapGetters([
        'errorCount'
        ]),
        tagNavList () {
        return this.$store.state.app.tagNavList
        },
        tagRouter () {
        return this.$store.state.app.tagRouter
        },
        userAvatar () {
        return this.userImg
        //return this.$store.state.user.avatarImgPath
        },
        userId () {

        return this.$store.state.user.userId
        },
        userName () {
        return this.$store.state.user.userName
        },
        unreadCount () {
            return this.$store.state.user.unreadCount
        }
    },
    created(){
      
        this.getBindingInfo()
    },
    methods:{
        clickChange(objectid){
          if(this.objectId==objectid)return
          this.$Modal.confirm({
              title: '系统提示',
              width: '360',
              loading:true,
              content: '<p>确定切换吗？</p>',
              onCancel: () => {
              },
              onOk: () => {
                  this.objectList.forEach((item,i)=>{
                      if(item.objectId == objectid){
                          this.objectId = item.objectId;
                          this.objectName = item.objectName;
                          this.$userUtil.setCurrentObject(item);
                          //刷新单位信息
                          this.$userUtil.refreshCompanyList(item,data=>{
                              this.reload();
                              this.$Modal.remove();
                              this.$Message.success("切换成功!");
                          });
                      }
                  })
              }
          });
        },
        getBindingInfo(){
            let userType = '';//0：业务员、1：人社局、2：组织部 3：主管单位 -1：普通单位
            console.log(this.$store.state)
            let areas = this.$store.state.user.extendedAttribute.areas;
            let areaList = this.$store.state.user.extendedAttribute.bindingAreas;
            let companyList = this.$store.state.user.extendedAttribute.bindingCompanys;
            if(areaList!=null&&areaList.length > 0){
                userType = '0';
                this.objectId = areaList[0].id;
                this.objectName = areaList[0].areaName;
                // this.$userUtil.setCurrentObject({
                //     objectId: areaList[0].id,
                //     objectName: areaList[0].areaName,
                //     userType: userType,
                //     areaId: areaList[0].id,
                //     areaCode: areaList[0].areaCode,
                //     areaName: areaList[0].areaName,
                // });
                areaList.forEach(item=>{
                    this.objectList.push({
                        objectId: item.id,
                        objectName: item.areaName,
                        userType: userType,
                        areaId: item.id,
                        areaCode: item.areaCode,
                        areaName: item.areaName,
                    });
                });
            }else if(companyList.length > 0){
                let companyType = '0';
                for(let item of companyList){
                    if('1'==item.companyType||'2'==item.companyType||'3'==item.companyType){
                        companyType = item.companyType;
                        break;
                    }
                }
                if(companyType == '0'){
                    userType = '-1';
                }else if(companyType == '1'){//人社局
                    userType = '1';
                }else if(companyType == '2'){//组织部
                    userType = '2';
                }else if(companyType == '3'){//主管单位
                    userType = '3';
                }
                this.objectId = areas[0].id;
                this.objectName = areas[0].areaName;
                // this.$userUtil.setCurrentObject({
                //     objectId: this.objectId,
                //     objectName: this.objectName,
                //     userType: userType,
                //     areaId: areas[0].id,
                //     areaCode: areas[0].areaCode,
                //     areaName: areas[0].areaName,
                //     companys: areas[0].companys
                // });
                // areas.forEach(item=>{
                //     this.objectList.push({
                //         objectId: item.id ,
                //         objectName: item.areaName ,
                //         userType: userType,
                //         areaId: item.id ,
                //         areaCode: item.areaCode ,
                //         areaName: item.areaName ,
                //         companys: item.companys
                //     });
                // });
            }else{
                this.$Message.warning({
                    content: '该账号没有绑定区域或单位，请联系管理员!',
                    duration: 60,
                    closable: true
                });
            }
        }
    }
}
</script>
<style scoped>
    .newheader{
        position: relative;
        height: 72px;
        width: 100%;
        background-color: #09294D;
        display: flex;
        justify-content: space-between;
        color:white;
        padding-left:40px;
    }
    .headerlogo{
        display: flex;
        justify-content: center;
        align-items: center;
    }
    .headerlogo .logo{
        background-repeat: no-repeat;
        width: 556px;
        height: 60px;
        font-size: 30px;
        background: linear-gradient(to right, 
        #fff, #007bdd);
        -webkit-background-clip: text;
        color: transparent;
        font-weight: 800;
        line-height: 60px;
    }
    .rightinfo{
        display: flex;
        justify-content: center;
        align-items: center;
    }
    /deep/.rightinfo .ivu-badge-count{
        margin-top: 0px!important;
    }
    /deep/.rightinfo .ivu-poptip-body-content{
        color:black;
    }
    /deep/.rightinfo .user-avatar-dropdown{
        line-height: 34px;
    }
    .noticediv{
        cursor: pointer;
    }
    .fullscreendiv{
        height: 72px;
        width: 72px;
        display: flex;
        justify-content: center;
        align-content: center;
        background-color: #0166B9;
    }
</style>
