<template>
  <div>
    <div class="block-1">
      <div class="avatar-block">
        <img
          class="edit btn"
          src="https://kuawai.s3.ap-east-1.amazonaws.com/resource/assets/Textures/second/edit_button.png"
          alt=""
          @click="click().edit()">
        <img v-if="userInfo.avatar" :src="userInfo.avatar | img" alt="" class="avatar">
        <img v-else class="avatar" src="https://kuawai.s3.ap-east-1.amazonaws.com/resource/assets/Textures/head2.png" alt="">
        <div class="name">
          {{ userInfo.nickName }}
        </div>
      </div>
      <div class="change">
        <div class="id">
          ID: {{ userInfo.id && userInfo.id.substring(0, 6) }}
        </div>
        <div class="koi-point">
          <img style="width: 34px;" src="https://kuawai.s3.ap-east-1.amazonaws.com/resource/assets/Textures/second/coin_03.png" alt="">
          {{ userInfo.koiPoint && userInfo.koiPoint.toFixed(2) }}
        </div>
        <img class="btn" src="https://kuawai.s3.ap-east-1.amazonaws.com/resource/assets/Textures/chinese/redeem%20credit_button_zh.png" alt="">
      </div>
      <div class="gold-block">
        <div class="card-box">
          <template v-if="userInfo.id">
            <img :src="cardImg[userInfo.playerLevelName]" alt="" class="card-img">
          </template>
          <div class="level">
            {{ levelCurrent.current }} / {{ levelCurrent.needs }}
          </div>
        </div>
        <div class="gold-box">
          <div class="box">
            <UiInput
              :value="userInfo.goldCredit"
              bg="https://kuawai.s3.ap-east-1.amazonaws.com/resource/assets/Textures/second/other-sel.png"
              icon="https://kuawai.s3.ap-east-1.amazonaws.com/resource/assets/Textures/sign/coins_counter.png" />
          </div>
          <div class="box">
            <UiInput
              :value="userInfo.redCredit"
              bg="https://kuawai.s3.ap-east-1.amazonaws.com/resource/assets/Textures/second/other-sel.png"
              icon="https://kuawai.s3.ap-east-1.amazonaws.com/resource/assets/Textures/second/bi_01.png" />
          </div>
        </div>
      </div>
      <div class="country">
        <CountryIcon :name="userInfo.playerCountry" style="width: 34px; display: block;"/>
        <span style="font-size: 12px; margin-left: 4px;">{{ userInfo.playerCountry }}</span>
      </div>
      <div class="login-time">
        最后登入：{{ userInfo.loginDate }}
      </div>
    </div>
    <div class="data">
      <InfoData :data="latestAchievement"/>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import UiInput from '@/components/ui/ui-input'
import CountryIcon from '@/components/ui/country-icon'
import InfoData from './info-data'
export default {
  components: {
    UiInput,
    CountryIcon,
    InfoData,
  },
  props: {
    levelCurrent: {
      type: Object,
      default: () => {
        return {}
      },
    },
    // 个人功绩
    latestAchievement: {
      type: Object,
      default: () => {
        return {}
      },
    },
  },
  data() {
    // 卡片
    const cardImg = {
      Red: 'https://kuawai.s3.ap-east-1.amazonaws.com/resource/assets/Textures/second/card-Red.png',
      Gold: 'https://kuawai.s3.ap-east-1.amazonaws.com/resource/assets/Textures/second/card-Gold.png',
      Silver: 'https://kuawai.s3.ap-east-1.amazonaws.com/resource/assets/Textures/second/card-Silver.png',
      Diamond: 'https://kuawai.s3.ap-east-1.amazonaws.com/resource/assets/Textures/second/card-Diamond.png',
    }
    return {
      cardImg,
    }
  },
  computed: {
    ...mapState([
      'userInfo',
    ]),
  },
  methods: {
    click() {
      return {
        edit: () => {
          this.$message({
            message: '功能维护中...',
            type: 'warning'
          })
        },
      }
    },
  },
}
</script>

<style lang="scss" scoped>
.block-1 {
  width: 100%;
  height: 120px;
  display: flex;
  background-color: #031e28;
  position: relative;
  .avatar-block {
    width: 80px;
    height: 90px;
    position: relative;
    background: #050505;
    border: 2px solid #313f32;
    border-radius: 6px;
    box-sizing: border-box;
    .edit {
      width: 20px;
      height: 20px;
      position: absolute;
      top: 0;
      right: 0;
    }
    .avatar {
      width: 80px;
      height: 70px;
      border-radius: 6px;
      display: block;
    }
    .name {
      line-height: 20px;
      font-size: 12px;
      color: #16b6c0;
      text-align: center;
    }
  }
  .change {
    background-image: url(https://kuawai.s3.ap-east-1.amazonaws.com/resource/assets/Textures/second/Rounded%20Rectangle%204%20copy.png);
    background-size: 100% 100%;
    width: 146px;
    height: 92px;
    padding: 2px;
    .id {
      color: #cca612;
      text-align: center;
      padding: 4px;
      font-size: 13px;
    }
    .koi-point {
      display: flex;
      padding: 0px 10px;
      align-items: center;
      justify-content: space-between;
      font-size: 13px;
      font-weight: bold;
    }
    .btn {
      width: 132px;
      display: block;
      margin: 6px auto;
    }
  }
  .gold-block {
    flex: 1;
    display: flex;
    padding-top: 4px;
    height: 102px;
    background-image: url(https://kuawai.s3.ap-east-1.amazonaws.com/resource/assets/Textures/second/juxing1.png);
    background-size: 100% 100%;
    border: 1px solid #065a6c;
    border-radius: 4px;
    box-sizing: border-box;
    .card-box {
      background-image: url(https://kuawai.s3.ap-east-1.amazonaws.com/resource/assets/Textures/second/Rounded%20Rectangle%204%20copy%202.png);
      background-size: 100% 100%;
      width: 150px;
      .card-img {
        width: 84px;
        margin: 4px auto;
        display: block;
      }
      .level {
        background: #0000007a;
        border-radius: 4px;
        text-align: center;
        margin: 4px auto;
        width: 100px;
        padding: 4px 0;
        font-size: 14px;
      }
    }
    .gold-box{
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      .box {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 140px;
      }
    }
  }
  .country {
    position: absolute;
    bottom: 0;
    display: flex;
    justify-content: center;
    padding: 4px;
    align-items: center;
    color: #1e7d94;
  }
  .login-time {
    color: #1e7d94;
    position: absolute;
    bottom: 0;
    right: 0;
    font-size: 12px;
    zoom: 0.9;
    padding: 2px;
  }
}

</style>
