<template>
  <div class="lang">
    <div class="sticky">
      <div class="header">
        <div class="back">
          <backIcon @cancel="cancel" back="cancel"/>
        </div>
        <!-- 语言 -->
        {{ $t('home.l24') }}
      </div>
    </div>
    <div class="list">
      <div class="item flex" @click="selectLang('zh-CN')">
        <div>简体中文</div>
        <van-icon v-if="language == 'zh-CN'" name="passed" color="#FE6F30" />
      </div>
      <div class="item flex" @click="selectLang('zh-TW')">
        <div>繁体中文</div>
        <van-icon v-if="language == 'zh-TW'" name="passed" color="#FE6F30" />
      </div>
      <div class="item flex" @click="selectLang('en')">
        <div>English</div>
        <van-icon v-if="language == 'en'" name="passed" color="#FE6F30" />
      </div>
      <div class="item flex" @click="selectLang('th')">
        <div>แบบไทย</div>
        <van-icon v-if="language == 'th'" name="passed" color="#FE6F30" />
      </div>
      <div class="item flex" @click="selectLang('vi')">
        <div>Tiếng Việt</div>
        <van-icon v-if="language == 'vi'" name="passed" color="#FE6F30" />
      </div>
      <div class="item flex" @click="selectLang('ru')">
        <div>Русский</div>
        <van-icon v-if="language == 'ru'" name="passed" color="#FE6F30" />
      </div>
    </div>
  </div>
</template>
<script>
import { setVantLang } from "@/lang";
import bus from '@/utils/bus'
import { updateUserLanguage } from "@/api/user";
export default {
  data () {
    return {
      
    }
  },
  methods: {
    cancel() {
      this.$emit('cancel')
    },
    selectLang(lan) {
      this.cancel()
      if (this.language == lan) {
        return
      }
      this.$store.commit('setLang', lan)
      bus.$emit('selectLang')
      this.$i18n.locale = lan
      setVantLang(lan)
      this.$store.commit('CHANGE_META_INFO', {
        title: this.$t('html.title'),
        description: this.$t('html.description'),
        keywords: this.$t('html.keywords')
      })
      if (this.isLogin) {
        updateUserLanguage({
          language: lan
        }).then(res => {}).catch(() => {})
      }
    }
  }
}
</script>
<style lang="less" scoped>
.lang {
  min-height: 100vh;
  background-color: #F6FAFE;
}
.sticky {
  position: sticky;
  top: 0;
  z-index: 20;
  background-color: var(--bg-);
}
.header {
  position: relative;
  text-align: center;
  padding-top: 15px;
  padding-bottom: 17px;
  font-size: 18px;
  background-color: var(--bg-);
  .back {
    position: absolute;
    left: 9px;
    top: 11px;
  }
}
.list {
  background-color: var(--bg-);
  padding: 0 18px;
  .item {
    height: 49px;
    justify-content: space-between;
    cursor: pointer;
    font-size: 16px;
    color: var(--color-1-);
    &+.item  {
      border-top: 1px solid #EDF2F7;
    }
  }
  .van-icon {
    font-size: 20px;
  }
}
</style>