<template>
  <el-dropdown trigger="click" class="international" @command="handleSetLanguage">
    <div>
      <svg-icon class-name="international-icon" icon-class="language" />
    </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">
        日本語
      </el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>
import Cookies from "js-cookie";
import {locale} from 'element-ui'
import lang1 from 'element-ui/lib/locale/lang/ja'
import lang2 from 'element-ui/lib/locale/lang/zh-CN'
export default {
  computed: {
    language() {
      return this.$store.getters.language
    }
  },
//   mounted(){
// 	// this.handleSetLanguage(Cookies.get('lang'))
// 	// this.$i18n.locale = Cookies.get('lang')
//     // this.$store.dispatch('app/setLanguage', Cookies.get('lang'))
// 	// locale(Cookies.get('lang'))
//   },
  methods: {
    handleSetLanguage(lang) {
      this.$i18n.locale = lang
      this.$store.dispatch('app/setLanguage', lang)
	  Cookies.set('lang',lang)
      this.$message({
        message: this.$store.getters.language=='zh'?'设置语言成功':'言語の設定に成功しました',
        type: 'success'
      })
	  if(lang=='en'){
		locale(lang1)
	  }
	  if(lang=='zh'){
		locale(lang2)
	  }
    }
  }
}
</script>
