<template>
  <div v-loading.body.fullscreen="fullscreenLoading" element-loading-background="rgba(255, 255, 255, 0)">
    <BackBar :title="$t('setting.ti1')">
    </BackBar>
    <div class="container">
      <el-form :model="form" ref="form">
        <el-form-item prop="name">
          <div class="label">
            <!-- 昵称 -->
            {{ $t('about.l16') }}
          </div>
          <!-- 请输入昵称 -->
          <el-input :maxlength="24" :placeholder="$t('setting.l15')" v-model="form.name" clearable @keyup.enter.native="submitClick" />
            <!-- 昵称包含1~24位字符（包含数字、字符和空格），且每月只能修改一次 -->
            <div class="tip">*{{$t('setting.l16')}}</div>
        </el-form-item>
      </el-form>
      <div class="btn" @click="submitClick">
        <!-- 保存 -->
        {{ $t('common.l47') }}
      </div>
    </div>
  </div>
</template>
<script>
import { updateNickName } from '@/api/user'
import BackBar from '@/components/backBar'
export default {
  components: {
    BackBar,
  },
  data() {
    return {
      form: {
        name: '',
      },
    }
  },
  methods: {
    submitClick() {
      if (!this.form.name.trim()) {
        // this.$toast('请输入昵称');
        this.$toast(this.$t('setting.l15'));
        return
      }
      this.alterName()
    },
    alterName() {
      this.fullscreenLoading = true
      updateNickName({
        im_name: this.form.name,
      }).then((res) => {
        this.$notify({
            // '修改成功'
            message: this.$t('setting.alter'),
            type: 'success'
          });
          this.$store.dispatch('getUserInfo')
          this.$router.back()
        }).finally(() => {
          this.fullscreenLoading = false;
        }).catch(() => {
        })
    },
  },
}
</script>
<style lang="less" scoped>
.container {
  padding: 27px 18px;
}
.el-form {
  padding-bottom: 19px;
}
.label {
  font-weight: 600;
  color: #1B1B1B;
  font-size: 18px;
  margin-bottom: 4px;
  line-height: 1;
}
.btn {
  font-size: 16px;
  line-height: 44px;
  text-align: center;
  border-radius: 6px;
  background-color: var(--color-);
  color: #fff;
}
.tip {
  font-size: 14px;
  line-height: 20px;
  margin-top: 12px;
  color: #C0C0C0;
}
.el-input {
  border-bottom: 1px solid #EDEDED;
}
::v-deep {
  .el-input__inner {
    border: none;
    line-height: 52px;
    height: 52px;
    font-size: 16px;
    padding: 0;
  }
}
</style>