<template>
  <div class="user">

    <el-dialog
      :visible.sync="addInp"
      :close-on-click-modal="false"
      title="请选择登录企业">
      <div style="height: 200px;">
<!--        <Dropdown trigger="click" style="margin-left: 20px;margin-right: 20px;; font-size: 14px;float: left;" v-show="isShowEnt" @on-click="changeEnt" >-->
<!--          <a href="javascript:void(0)">-->
<!--            {{entForm.baseEnt}}-->
<!--            <Icon type="ios-arrow-down"></Icon>-->
<!--          </a>-->
<!--          <DropdownMenu slot="list" >-->
<!--            <DropdownItem v-for="item in entForm.entList" :value="item.value" :key="item.value" :name="item.value">{{item.name}}</DropdownItem>-->
<!--          </DropdownMenu>-->
<!--        </Dropdown>-->

        <el-radio-group v-model="radio3" size="small" @change="changeEnt">
          <el-radio :label="item.value" border v-for="item in entForm.entList" :value="item.value" :key="item.value" :name="item.value">{{item.name}}</el-radio>
        </el-radio-group>

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

</template>

<script>
  import {deptRoleList} from '@/api/admin/role'
  import {fetchTreeAddUser} from '@/api/admin/dept'
  import {tableOption} from '@/const/crud/admin/user'
  import {mapGetters} from 'vuex'
  import VDistpicker from 'v-distpicker'
  import {getDeptList} from '@/api/admin/dept'

  export default {
    name: 'SysUser',
    data() {
      return {
        addInp:true,
        entForm:{
          entList:[],
          baseEnt:""
        },
        loginForm:{
          mobile:'',
          code:'',
          drugEntId:''
        },
        isShowEnt:true,
        radio3:0
      }
    },
    computed: {
      ...mapGetters(['permissions','userInfo','tagWel'])

    },
    components: {
      VDistpicker
    },
    watch: {
      role() {
        this.form.role = this.role
      }
    },
    mounted() {
      this.getDrugEntList();
    },
    methods: {
      changeEnt(name){
        let username=this.userInfo.username;
        this.$store.dispatch('LogOut').then(() => {
          this.loginForm.mobile=username;
          this.loginForm.drugEntId=name
          this.$store.dispatch('LoginByPhoneForChangeEnt', this.loginForm).then(() => {
            this.$router.push({path: this.tagWel.value+"?r="+username+"+123123"})
            //window.location.reload();
          })
        })
      },
      getDrugEntList()
      {
        this.entForm.entList=[];
        if(null!=this.userInfo.username&&undefined!=this.userInfo.username)
        {
          var obj={
            username:this.userInfo.username
          }
          getDeptList(obj).then(response => {
            const result = response.data.data
            if(result.length>0)
            {
              for(var i=0;i<result.length;i++)
              {
                  this.entForm.entList.push(
                    {
                      value:result[i].id,
                      name:result[i].entname
                    }
                  )

                if(result.length>1)
                {
                  this.addInp=true;
                  this.isShowEnt=true;

                }

              }
            }
          })
        }
      },
    }
  }
</script>
<style lang="scss">
  .user {
    height: 100%;

    &__tree {
      padding-top: 3px;
      padding-right: 20px;
    }

    &__main {
      .el-card__body {
        padding-top: 0;
      }
    }
  }

  .distpicker-address-wrapper{
    color: #000000 !important;
  }


  .distpicker-address-wrapper .address-header ul li.active{
    color: #000000 !important;
  }
</style>

