import { logout } from 'api/base/auth';
import { removeToken } from 'service/auth';

export default {
  components: {
    UiPsw: resolve => require(['views/layout/header_bar/password'], resolve),
    UiDetail: resolve => require(['views/layout/header_bar/detail'], resolve)
  },
  props: {
    collapsed: { // 左侧菜单收缩
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      password: {
        show: false
      },
      detail: {
        show: false
      }
    };
  },
  methods: {
    collapsedChange() {
      this.$emit('update:collapsed', !this.collapsed);
    },
    dropChange(name) {
      if (name == 3) {
        this.$Modal.confirm({
          title: '提示',
          content: '您确定要退出当前账号？',
          onOk: () => {
            logout().then(res => {
              if (res.code === 0) {
                this.$store.commit('CLEAR_TAGNAVS');
                localStorage.clear();
                removeToken();
                this.$router.replace('/login');
              }
            });
          }
        });
      } else if (name == 2) {
        this.detail.show = true;
      } else if (name == 1) {
        this.password.show = true;
      }
    }
  }
};
