<template>
  <el-dropdown
    class="international"
    trigger="click"
    @command="handleSetLanguage"
  >
    <div>中英文</div>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item :disabled="language === 'zh'" command="zh"
      >中文
      </el-dropdown-item
      >
      <el-dropdown-item :disabled="language === 'en'" command="en"
      >English
      </el-dropdown-item
      >
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>
export default {
  name: 'ChoiceLanguage',
  computed: {
    language() {
      return this.$store.getters.language
    }
  },
  methods: {
    handleSetLanguage(lang) {
      // 选择语言
      this.$i18n.locale = lang
      // 保存vuex
      this.$store.dispatch('app/setLanguage', lang)
      let msg
      if (lang == 'zh') {
        msg = '切换成功'
      } else {
        msg = 'switch language success'
      }
      this.$message({
        message: msg,
        type: 'success'
      })
      // 触发重新加载事件
      this.$emit('handerevent')
    }
  }
}
</script>

<style scoped>
.international-icon {
  font-size: 22px;
  cursor: pointer;
  vertical-align: -5px !important;
  color: #fff;
}

.el-dropdown {
  color: #5a5e66;
}
</style>
