<template>
    <!-- <el-dropdown
        class="international"
        @command="handleSetLanguage"
        placement="bottom"
    >
        <!-- <span class="theme-color">{{ $t('selectLang.switchLang') }}</span> -->
    <!--     <i
            :class="
                $i18n.locale === 'zh-CN'
                    ? 'cqlt-icon-zhongyingwenqiehuan-zhongwen'
                    : 'cqlt-icon-zhongyingwenqiehuan-yingwen'
            "
            class="theme-color cqlt-icon"
        ></i>
        <el-dropdown-menu slot="dropdown">
            <el-dropdown-item
                :disabled="$i18n.locale === 'zh-CN'"
                command="zh-CN"
                >中文</el-dropdown-item
            >
            <el-dropdown-item
                :disabled="$i18n.locale === 'en-US'"
                command="en-US"
                >English</el-dropdown-item
            >
        </el-dropdown-menu>
    </el-dropdown> -->
    <i
        :class="
            $i18n.locale === 'zh-CN'
                ? 'cqlt-icon-zhongyingwenqiehuan-yingwen'
                : 'cqlt-icon-zhongyingwenqiehuan-zhongwen'
        "
        class="theme-color cqlt-icon"
        @click="handleSetLanguage"
    ></i>
</template>

<script>
import moment from 'moment' //日期格式化插件
import portal from '@/api/portal.js'
export default {
    name: 'lang-select',
    computed: {
        language() {
            return localStorage.getItem('lang') || 'zh-CN'
        },
    },
    methods: {
        handleSetLanguage() {
            if (this.$i18n.locale === 'zh-CN') {
                this.$i18n.locale = 'en-US'
            } else {
                this.$i18n.locale = 'zh-CN'
            }
            let lang = this.$i18n.locale
            // this.$validator.locale = lang

            // 日期控件格式化
            if ('zh-CN' == lang) {
                moment.locale('zh-cn')
            } else {
                moment.locale('en')
            }

            localStorage.setItem('lang', lang)
            this.$message({
                message: this.$t('selectLang.switchLangMsg'),
                type: 'success',
            })
            if (this.$route.path.indexOf('login') == -1) {
                window.location.reload()
            }
        },
        getAllDict() {
            portal.getSysDict().then((data) => {
                if (data) {
                    sessionStorage.setItem('dict_data', JSON.stringify(data))
                }
            })
        },
    },
}
</script>

<style lang="scss" scoped>
@import '@/assets/css/element-variables.scss';
.theme-color {
  color: $--color-primary;
  cursor: pointer;
  margin-right: 36px;
}
.international {
  margin-right: 36px;
}
</style>
