<template>
  <div class="page" v-loading.body.fullscreen="fullscreenLoading" element-loading-background="rgba(255, 255, 255, 0)">
    <van-sticky class="sticky">
      <div class="header">
        <div class="back">
          <backIcon/>
        </div>
        <!-- 个人简介 -->
        {{ $t('about.l19') }}
        <div class="edit" @click="updateUserInfo">
          <!-- 完成 -->
          {{ $t('common.l10') }}
        </div>
      </div>
    </van-sticky>
    <div class="container">
      <!-- 介绍自己的投资经验,风格或领域 -->
      <el-input maxlength="60" show-word-limit :placeholder="$t('about.l27')" type="textarea" :rows="8" v-model="description" clearable></el-input>
    </div>
    <div class="tip">
      <!-- 例如;美股研究员/新股专家/量化交易员 -->
      {{ $t('about.l28') }}
    </div>
  </div>
</template>
<script>
import { mapGetters } from "vuex";
import { updateUserInfo } from "@/api/user";
export default {
  data () {
    return {
      description: ''
    }
  },
  computed: {
    ...mapGetters(['userInfo']),
  },
  watch: {
    'userInfo.description'() {
      if (this.userInfo.description !== '') {
        this.description = this.userInfo.description
      }
    }
  },
  created () {
    if (this.userInfo.description !== '') {
      this.description = this.userInfo.description
    }
  },
  methods: {
    updateUserInfo() {
      if (!this.description.trim()) {
        // this.$toast('请输入个人简介');
        this.$toast(this.$t('about.l29'));
        return
      }
      this.fullscreenLoading = true
      var data = {
        description: this.description.trim()
      }
      updateUserInfo({
        info: JSON.stringify(data)
      }).then(() => {
        this.$notify({
          // message: '更新成功',
          message: this.$t('common.l28'),
          type: 'success'
        });
        this.$store.dispatch('getUserInfo')
        this.$router.back()
      }).catch(() => {}).finally(() => {
        this.fullscreenLoading = false;
      })
    },
  }
}
</script>
<style lang="less" scoped>
.page {
  min-height: 100vh;
  background-color: #F6FAFE;
}
.sticky {
  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;
  }
  .edit {
    position: absolute;
    top: 15px;
    right: 17px;
    color: var(--color-);
    cursor: pointer;
    font-size: 16px;
  }
}
.container {
  background-color: var(--bg-);
  // padding: 0 18px;
}
.tip {
  padding: 15px 18px;
  color: #B0B0B0;
  font-size: 13px;
}
::v-deep {
  .el-textarea__inner {
    border: none;
    padding: 15px 18px;
  }
}
</style>