<template>
  <div class="page">
    <div class="sticky">
      <div class="header">
        <div class="back">
          <backIcon/>
        </div>
        {{serverName[accountInfo.server] || accountInfo.server}}
      </div>
    </div>
    <div class="body">
      <div class="top">
        <div class="info-box flex">
          <div class="name">{{ serverName[accountInfo.server] || accountInfo.server }}</div>
          <div>{{ accountInfo.account }}</div>
        </div>
        <div class="flex equity">
          <!-- 资产净值 -->
          {{$t('account.l2')}}({{serverUtil[accountInfo.server] || accountInfo.server}})
          <img v-show="showAssets" @click.stop="toggleShow(false)" class="eye" src="/img/account/icon1.svg" alt="极度证券">
          <img v-show="!showAssets" @click.stop="toggleShow(true)" class="eye" src="/img/account/icon2.svg" alt="极度证券">
        </div>
        <div class="amount" v-if="showAssets">{{ $numToThousand($handleDigits(equity || accountInfo.equity)) }}</div>
        <div class="amount" v-else>*****</div>
        <profitBox v-if="accountInfo.server" :accountInfo="accountInfo" @setEquity="setEquity" />
      </div>
      <div class="section flex">
        <div class="item flex" @click="$router.push('/exchange/1/buy/' + accountInfo.id)">
          <img class="icon" src="/img/account/icon7.png" alt="极度证券">
          <div class="text">
            <!-- 交易 -->
            {{ $t('tab.tab3') }}
          </div>
        </div>
        <div class="item flex" @click="goUrl('/deposit/' + accountInfo.id)">
          <img class="icon" src="/img/account/icon4.png" alt="极度证券">
          <div class="text">
            <!-- 存入资金 -->
            {{ $t('account.l26') }}
          </div>
        </div>
        <div class="item flex" @click="goUrl('/withdraw')">
          <img class="icon" src="/img/account/icon21.png" alt="极度证券">
          <div class="text">
            <!-- 取款 -->
            {{ $t('home.l14') }}
          </div>
        </div>
        <div class="item flex" @click="goUrl('/convert/' + accountInfo.id)">
          <img class="icon" src="/img/account/icon3.png" alt="极度证券">
          <div class="text">
            <!-- 划转 -->
            {{ $t('home.l15') }}
          </div>
        </div>
        <div class="item flex" @click="$router.push('/account-records/1')">
          <img class="icon" src="/img/account/icon6.png" alt="极度证券">
          <div class="text">
            <!-- 资金记录 -->
            {{ $t('account.l9') }}
          </div>
        </div>
      </div>
      <div class="row">
        <div class="col flex">
          <div>
            <!-- 货币 -->
            {{ $t('account.l85') }}
          </div>
          <div class="val">{{ serverUtil[accountInfo.server] }}</div>
        </div>
        <div class="col flex">
          <div>
            <!-- 杠杆 -->
            {{ $t('account.l86') }}
          </div>
          <div class="val flex">
            <div v-if="tradesServer.leverage">{{ (tradesServer.leverage || 0).toFixed(1) }}X</div>
            <img v-if="tradesServer.adjust_leverage == 1" class="right" src="/img/icon/right.png" alt="极度证券">
          </div>
        </div>
      </div>
    </div>
    <!-- <authIdentity v-if="authShow" @cancel="authShow = false" /> -->
  </div>
</template>
<script>
import bus from '@/utils/bus'
import { mapGetters } from "vuex";
// import authIdentity from "@/components/authIdentity";
import { getTradesServerList } from "@/api/assets";
import profitBox from "./components/profitBox.vue";
export default {
  components: {
    // authIdentity,
    profitBox
  },
  data () {
    return {
      id: null,
      authShow: false,
      equity: 0,
      tradesServerList: []
    }
  },
  computed: {
    ...mapGetters(['accountList', 'showAssets']),
    accountInfo() {
      var info = {}
      this.accountList.forEach(item => {
        if(item.id == this.id) {
          info = item
        }
      })
      return info
    },
    tradesServer() {
      var info = {}
      this.tradesServerList.forEach(item => {
        if(item.code == this.accountInfo.server) {
          info = item
        }
      })
      return info
    }
  },
  created () {
    this.id = this.$route.params.id
    if (!this.accountInfo.account) {
      bus.$emit('updateAssets', ['getAccountList'])
    }
    this.getTradesServerList()
  },
  methods: {
    setEquity(equity) {
      this.equity = equity
    },
    goUrl(url) {
      if (this.userInfo.identity_status == 1) {
        this.$router.push(url)
        return
      }
      this.fullscreenLoading = true
      this.$store.dispatch('getUserInfo').then(() => {
        // if (this.userInfo.identity_status !== 1) {
        //   this.authShow = true
        // } else {
          this.$router.push(url)
        // }
      }).catch(() => {}).finally(() => {
        this.fullscreenLoading = false
      })
    },
    getTradesServerList() {
      getTradesServerList().then(res => {
        this.tradesServerList = res.list || []
      }).catch(() => {})
    },
    toggleShow(sign) {
      this.$store.commit('setShowAssets', sign)
    }
  }
}
</script>
<style lang="less" scoped>
.page {
  min-height: 100vh;
  background-color: #F3F4F6;
}
.sticky {
  position: sticky;
  top: 0;
  z-index: 20;
  background-color: var(--bg2-);
}
.header {
  position: relative;
  font-size: 18px;
  font-weight: 600;
  background-color: var(--bg-);
  height: 50px;
  padding: 0 40px 2px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  .back {
    position: absolute;
    left: 9px;
    top: 11px;
  }
}
.body {
  padding: 13px 17px 0;
}
.top {
  background-color: var(--bg-);
  border-radius: 12px;
  margin-bottom: 12px;
  padding: 11px 12px 12px;
  position: relative;
  .info-box {
    font-size: 12px;
    color: #ABABAB;
    margin-bottom: 13px;
    padding-left: 3px;
    max-width: 50%;
  }
  .name {
    border-radius: 4px;
    border: 1px solid rgba(171, 171, 171, 0.54);
    line-height: 14px;
    padding: 2px 5px;
    margin-right: 4px;
  }
  .amount {
    font-size: 23px;
    font-weight: 600;
    color: #000000;
    line-height: 28px;
  }
}
.equity {
  column-gap: 3px;
  font-size: 12px;
  color: #9D9D9D;
  .eye {
    width: 16px;
    cursor: pointer;
  }
}
.section {
  background-color: var(--bg-);
  height: 103px;
  border-radius: 12px;
  justify-content: space-between;
  padding: 0 4px;
  .item {
    width: calc(20% - 4px);
    justify-content: center;
    flex-direction: column;
    cursor: pointer;
    font-size: 12px;
    color: var(--color-d-);
    .icon {
      margin-bottom: 10px;
      width: 44px;
    }
  }
  .text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    text-align: center;
  }
}
.row {
  background-color: var(--bg-);
  border-radius: 12px;
  padding: 0 12px;
  font-size: 16px;
  color: #171717;
  margin-top: 12px;
  .col {
    justify-content: space-between;
    height: 60px;
    &+.col {
      border-top: 1px solid #F3F3F3;
    }
  }
  .val {
    color: #AEAEAE;
  }
  .right {
    height: 14px;
    margin-left: 6px;
  }
}
</style>