<template>
  <div class="mine">
    <div class="banner">
      <div class="flex-col flex-ac">
        <div class="block_1">
          <img src="@/assets/logo.png" class="avatar" />
        </div>
        <div class="flex-col flex-ac">
          <span class="text_1">{{ userinfo.nickname }}</span>
          <div class="flex-row">
            <span class="text_2">{{ $t('lang35') }}{{ userinfo.addressEncrypt }}</span>
            <!-- <div class="text-wrapper_2"> -->
            <!-- <span>复制</span> -->
            <img src="@/assets/images/trade/copy.png" alt="" class="copys" @click="copy" :data-clipboard-text="this.userinfo.address" />
            <!-- </div> -->
          </div>
          <img src="@/assets/images/lang.png" alt="" class="lang" @click="reckoningClick('language')" />
        </div>
      </div>
    </div>
    <div class="content">
      <div class="balance_box">
        <div class="balance_li" @click="reckoningClick('assets')">
          <div class="left">
            <span class="amount">{{ $t('lang36') }}</span>
          </div>
          <div class="right">
            <!-- <img src="@/assets/images/usdt.png" class="icon1" /> -->
            <span>{{ $t('lang37') }}</span>
          </div>
        </div>
        <div class="balance_li" @click="reckoningClick('teaRights')">
          <div class="left">
            <span class="amount">{{ $t('lang218') }}</span>
          </div>
          <div class="right">
            <!-- <img src="@/assets/images/mine.png" class="icon2" /> -->
            <span>{{ $t('lang39') }}</span>
          </div>
        </div>
      </div>
      <div class="list">
        <div @click="switchovers('myTeaFriends')" class="li">
          <div class="li_left">
            <div class="imgbox">
              <img src="@/assets/images/my.png" class="li_img" />
            </div>
            <span>{{ $t('lang40') }}</span>
          </div>
          <van-icon name="arrow" color="#aaaaaa" size="16" />
        </div>
        <div @click="switchovers('invite')" class="li">
          <div class="li_left">
            <div class="imgbox">
              <img src="@/assets/images/invite.png" class="li_img" />
            </div>
            <span>{{ $t('lang41') }}</span>
          </div>
          <van-icon name="arrow" color="#aaaaaa" size="16" />
        </div>
        <!-- <div @click="switchovers('share')" class="li">
          <div class="li_left">
            <div class="imgbox">
              <img src="@/assets/images/trade/detail.png" class="li_img" />
            </div>
            <span>{{ $t('lang205') }}</span>
          </div>
          <van-icon name="arrow" color="#aaaaaa" size="16" />
        </div> -->
        <div @click="switchovers('1')" class="li">
          <div class="li_left">
            <div class="imgbox">
              <img src="@/assets/images/trade/custom.png" class="li_img" />
            </div>
            <span>{{ $t('lang43') }}</span>
          </div>
          <van-icon name="arrow" color="#aaaaaa" size="16" />
        </div>
        <div @click="switchovers('setting')" class="li">
          <div class="li_left">
            <div class="imgbox">
              <img src="@/assets/images/set.png" class="li_img" />
            </div>
            <span>{{ $t('lang44') }}</span>
          </div>
          <van-icon name="arrow" color="#aaaaaa" size="16" />
        </div>
      </div>
    </div>
    <!-- 上级弹窗 -->
    <van-popup v-model="superiorShow" round style="width: 80%">
      <Superior :address="userinfo.parent_address" :level="userinfo.team_level_name" :parantId="userinfo.parent_id"></Superior>
    </van-popup>
    <BottomNavigation></BottomNavigation>
  </div>
</template>

<script>
import Superior from './superiorPopup.vue';
import { Notify } from 'vant';
import { usApi, newsLetterApi, walletApi, homeApi } from '@/api/index';
import { mapState } from 'vuex';
import union from '../../api/union';
import BottomNavigation from '@/components/BottomNavigation.vue';
import Clipboard from 'clipboard';
import Web3 from 'web3';
export default {
  data() {
    return {
      show: false, //上级弹窗状态
      withdrawShow: false, //提现弹窗状态
      total: 0,
      team_level_name: '',
      userinfo: {
        address: undefined,
        nickname: undefined,
        avatar: undefined,
        team_level_id: undefined,
        seso_url: undefined,
        submit_limit: 0,
      },
      order_count: {
        pay: 0,
        sell: 0,
        success: 0,
        cancel: 0,
      },
      withdrawAmount: 0, // 提现金额
      feeObj: {
        usdt: 0,
        withdraw_fee_rate: 0,
        withdraw_min_amount: 0,
      },
      receiptAmount: 0, // 实际到账金额
      superiorShow: false, //上级弹窗
    };
  },
  created() {
    this.init();
  },
  mounted() {
    // this.init();
  },
  methods: {
    init() {
      if (this.account) {
        this.userinfo = JSON.parse(localStorage.getItem('userinfo'));
        this.userinfo.addressEncrypt = this.userinfo.address.substring(0, 5) + '****' + this.userinfo.address.substring(this.userinfo.address.length - 5, this.userinfo.address.length);
        this.getUserInfo();
      }
    },

    switchovers(router) {
      console.log(router);
      if (router == '') {
        // window.location.href = this.userinfo.seso_url;
        this.superiorShow = true;
      } else if (router == '1') {
        this.$toast(this.$t('lang2'));
      } else {
        this.$router.push({ name: router });
      }
    },
    reckoningClick(name) {
      this.$router.push({ name: name });
    },
    getUserInfo() {
      homeApi.getUserInfo({}).then(res => {
        if (res.code == 200) {
          this.userinfo = res.data;
          this.order_count = res.data.order_count;
          this.userinfo.addressEncrypt = this.userinfo.address.substring(0, 5) + '****' + this.userinfo.address.substring(this.userinfo.address.length - 5, this.userinfo.address.length);
        }
      });
    },
    copy() {
      if (this.userinfo.address) {
        var clipboard = new Clipboard('.copys');
        clipboard.on('success', e => {
          this.$toast(this.$t('lang45'));
          clipboard.destroy(); // 释放内存
        });
        clipboard.on('error', e => {
          this.$toast(this.$t('lang46'));
          clipboard.destroy(); // 释放内存
        });
      }
    },
  },
  computed: {
    ...mapState(['account']),
  },
  watch: {
    account() {
      this.init();
    },
    withdrawAmount(e) {
      // this.receiptAmount = 0;
      this.receiptAmount = Number(e) - Number(e) * Number(this.feeObj.withdraw_fee_rate);
    },
  },
  components: {
    Superior,
    BottomNavigation,
  },
};
</script>

<style lang="less" scoped>
.mine {
  min-height: 100vh;
  .banner {
    // display: flex;
    // justify-content: space-between;
    background: linear-gradient(to bottom right, #29b286, #dae9fd);
    padding: 30px 16px 60px;
    .block_1 {
      box-shadow: 0px 0px 29px 0px rgba(97, 142, 184, 0.19);
      // background-color: rgba(169, 191, 245, 1);
      border-radius: 50%;
      width: 68px;
      height: 68px;
      // border: 3px solid rgba(#b6b3b3, 1);
      margin-right: 14px;
      overflow: hidden;
      .avatar {
        width: 100%;
        height: 100%;
        background-color: #fff;
      }
    }
    .copys {
      width: 16px;
      height: 16px;
      margin-left: 4px;
    }
    .lang {
      width: 26px;
      position: absolute;
      right: 14px;
      top: 14px;
    }
    .grade {
      display: flex;
      align-items: center;
      font-size: 14px;
      color: #fff;
      .grade_img {
        display: block;
        width: 7px;
        height: 12px;
      }
    }
    .text_1 {
      color: rgba(6, 12, 80, 1);
      font-size: 16px;
      font-weight: normal;
      padding: 8px 0 6px;
    }
    .text_2 {
      color: rgba(#000, 0.6);
      font-size: 13px;
    }
    .text-wrapper_1 {
      font-size: 11px;
      line-height: 100%;
      padding: 5px 10px;
      background-color: rgba(246, 162, 15, 1);
      border-radius: 6px;
      margin: 6px;
    }
    .text-wrapper_2 {
      font-size: 11px;
      line-height: 100%;
      padding: 5px 10px;
      background-color: #7938cf;
      border-radius: 6px;
      margin: 6px;
    }
  }
  .flex-col {
    display: flex;
    flex-direction: column;
  }
  .flex-ac {
    align-items: center;
    justify-content: center;
  }
  .flex-row {
    display: flex;
    align-items: center;
  }
  .content {
    padding: 0 16px 100px;
    margin-top: -40px;
    color: #000;
    .balance_box {
      display: flex;
      align-items: center;
      justify-content: space-between;

      .balance_li {
        color: #fff;
        display: flex;
        flex-direction: column;
        width: 48%;
        font-size: 14px;
        padding: 14px;
        box-shadow: 4px 4px 15px 0px rgba(180, 212, 212, 0.29);
        border-radius: 6px;
        background: linear-gradient(to bottom right, #29b286, #30d5a0);

        .left {
          display: flex;
          flex-direction: column;
        }
        .icon1 {
          width: 16px;
          height: 16px;
          margin-right: 4px;
        }
        .icon2 {
          width: 16px;
          height: 14px;
          margin-right: 4px;
        }
        .right {
          display: flex;
          align-items: center;
          color: rgba(#fff, 0.6);
          font-size: 13px;
          margin-top: 6px;
        }
        .btn {
          color: #7938cf;
          font-size: 12px;
          padding: 4px 8px;
          border-radius: 3px;
          margin-left: 8px;
          background-color: rgba(48, 70, 212, 0.1);
        }
        .amount {
          font-size: 16px;
        }
      }
      .balance_li:last-child {
        background: linear-gradient(to bottom right, #14bcc6, #28d3de);
      }
    }
    .order {
      font-size: 13px;
      color: rgba(153, 153, 153, 1);
      border-radius: 16px;
      padding: 16px;
      box-shadow: 4px 4px 15px 0px rgba(180, 212, 212, 0.59);
      margin-top: 16px;
      background-color: rgba(255, 255, 255, 1);
      .top {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding-bottom: 16px;
        border-bottom: 1px solid rgba(232, 240, 247, 1);
        .order_text1 {
          font-size: 16px;
          color: rgba(0, 0, 0, 1);
          font-weight: 600;
        }
        .order_text2 {
          font-size: 12px;
        }
      }
      .bottom {
        padding-top: 16px;
        justify-content: space-between;
        .item {
          align-items: center;
          text-align: center;
          .num {
            color: rgba(#000, 0.75);
            font-size: 16px;
            font-weight: 650;
            padding-bottom: 4px;
          }
        }
      }
    }
    .list {
      margin-top: 16px;
      padding: 0 20px;
      border-radius: 10px;
      background-color: rgba(255, 255, 255, 1);

      .li {
        display: flex;
        align-items: center;
        justify-content: space-between;
        font-size: 14px;
        color: rgb(36, 36, 36);
        padding: 24px 0;
        // margin-bottom: 10px;
        border-top: 1px solid rgba(232, 240, 247, 1);
        // box-shadow: 4px 4px 15px 0px rgba(180, 212, 212, 0.29);

        .li_left {
          display: flex;
          align-items: center;
          .imgbox {
            width: 20px;
            height: 20px;
            margin-right: 12px;
          }
          .li_img {
            width: 20px;
            height: 20px;
          }
        }
        .right {
          width: 7px;
          height: 12px;
        }
      }
    }
  }

  .withdrawPopup {
    padding: 20px 30px;
    color: #666666;
    font-size: 14px;
    .title {
      display: flex;
      justify-content: center;
      padding-bottom: 20px;
      font-weight: bold;
      font-size: 16px;
      color: #000000;
    }

    .tip {
      font-size: 12px;
      display: flex;
      flex-direction: column;
    }
    .btn {
      color: #fff;
      padding: 16px 0;
      text-align: center;
      line-height: 50%;
      border-radius: 20px;
      margin-top: 18px;
      background-color: #7938cf;
    }
    .close—icon {
      position: absolute;
      bottom: -40px;
      left: 45%;
    }
  }
}

/deep/ .van-popup {
  overflow-y: visible;
}

/deep/ .van-field {
  background-color: #f2f9f9;
  border-radius: 8px;
  margin: 6px 0;
}
/deep/ .van-field__body {
  padding: 10px 10px;
}
</style>