<template>
  <div class="container">
    <!-- 导航栏 -->
    <div class="nav-bar">
      <div class="back-btn" @click="$router.back()">
        <i class="arrow-left"></i>
      </div>
      <div class="title">资金明细</div>
    </div>

    <!-- 固定顶部资产信息 -->
    <!-- <div class="fixedTop">
      <div class="top">
        <div class="flex totalView">
          <div class="totalText" style="font-weight: bold;">账户总资产</div>
          <img 
            :src="isBalanceVisible ? require('@/assets/eye-open.png') : require('@/assets/eye-close.png')"
            class="eye-icon"
            @click="toggleBalance"
          >
        </div>
        <div class="flex opts">
          <div class="flex optsItem optsItem1">
            <div class="botalNumView1">¥ {{ isBalanceVisible ? totalAssets : '******' }}</div>
          </div>
        </div>
        <div class="flex">
          <div class="flex optsItem optsItem1" style="flex-direction: column;">
            <div class="optsItemText">财政补贴</div>
            <div class="optsItemText">{{ isBalanceVisible ? (assetInfo.subsidy || '0.00') : '******' }}</div>
          </div>
          <div class="line-divider"></div>
          <div class="flex optsItem optsItem2" style="flex-direction: column;">
            <div class="optsItemText">现金储备</div>
            <div class="optsItemText">{{ isBalanceVisible ? (assetInfo.cashReserve || '0.00') : '******' }}</div>
          </div>
          <div class="line-divider"></div>
          <div class="flex optsItem optsItem3" style="flex-direction: column;">
            <div class="optsItemText">万泰红利</div>
            <div class="optsItemText">{{ isBalanceVisible ? (assetInfo.bonus || '0.00') : '******' }}</div>
          </div>
          <div class="line-divider"></div>
          <div class="flex optsItem optsItem4" style="flex-direction: column;">
            <div class="optsItemText">养生币</div>
            <div class="optsItemText">{{ isBalanceVisible ? (ethInfo.balance || '0.00') : '******' }}</div>
          </div>
        </div>
        <div class="flex opts"></div>
      </div>
      <div class="flex acc"></div>
    </div> -->

    <!-- 交易记录列表 -->
    <div class="record-list">
      <div class="listItem" v-for="(item, index) in transactions" :key="index">
        <div class="flex listItemC">
          <div>详细</div>
          <div class="tr4">金额</div>
          <div class="right">日期</div>
        </div>
        <div class="flex listItemB">
          <div>{{ item.memo }}</div>
          <div class="tr4">{{ item.money }}</div>
          <div class="right gggg">{{ item.addtime }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getUserInfo } from '@/api/home';
import { getEthInfo } from '@/api/profile';

export default {
  name: 'AssetCenter',
  data() {
    return {
      userInfo: {},
      ethInfo: {},
      assetInfo: {
        subsidy: '0.00',
        cashReserve: '0.00',
        bonus: '50805558.28'
      },
      transactions: [],
      isBalanceVisible: true
    }
  },
  computed: {
    totalAssets() {
      const bonus = parseFloat(this.assetInfo.bonus) || 0;
      const subsidy = parseFloat(this.assetInfo.subsidy) || 0;
      const cashReserve = parseFloat(this.assetInfo.cashReserve) || 0;
      return (bonus + subsidy + cashReserve).toFixed(2);
    }
  },
  created() {
    this.getUserInfo();
    this.getEthInfo();
  },
  methods: {
    async getUserInfo() {
      try {
        const res = await getUserInfo();
        this.userInfo = res.data;
      } catch (error) {
        console.error('获取用户信息失败:', error);
      }
    },
    async getEthInfo() {
      try {
        const res = await getEthInfo();
        this.ethInfo = res.data;
        if (res.data) {
          this.transactions = res.data;
        }
      } catch (error) {
        console.error('获取ETH信息失败:', error);
      }
    },
    toggleBalance() {
      this.isBalanceVisible = !this.isBalanceVisible;
    }
  }
}
</script>

<style scoped>
.container {
  min-height: 100vh;
  background: #f5f5f5;
}

.nav-bar {
  height: 44px;
  background-color: #fff;
  color: #000;
  display: flex;
  align-items: center;
  position: relative;
  padding: 0 15px;
  font-weight: bold;
}

.back-btn {
  width: 24px;
  height: 44px;
  display: flex;
  align-items: center;
  cursor: pointer;
}

.arrow-left {
  width: 12px;
  height: 12px;
  border-left: 2px solid #000;
  border-bottom: 2px solid #000;
  transform: rotate(45deg);
}

.title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 16px;
  font-weight: 500;
}

.fixedTop {
  background: #ed4b39;
  padding: 15px;
  margin-bottom: 10px;
}

.flex {
  display: flex;
}

.totalView {
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.totalText {
  font-size: 16px;
  color: #fff;
  font-weight: normal;
}

.eye-icon {
  width: 20px;
  height: 20px;
  cursor: pointer;
}

.botalNumView1 {
  font-size: 24px;
  color: #fff;
  font-weight: bold;
  text-align: center;
  width: 100%;
}

.line-divider {
  width: 1px;
  height: 40px;
  background: #fff;
  margin: 0;
}

.optsItem {
  flex: 1;
  text-align: center;
  padding: 10px 0;
}

.optsItemText {
  font-size: 14px;
  color: #fff;
  margin: 5px 0;
  font-weight: normal;
}

.listItem {
  background: #fff;
  margin: 10px;
  padding: 15px;
  border-radius: 8px;
}

.listItemC {
  justify-content: space-between;
  color: #999;
  font-size: 14px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
}

.listItemB {
  justify-content: space-between;
  color: #333;
  font-size: 14px;
  display: flex;
  align-items: center;
}

.tr4 {
  flex: 0 0 100px;
  text-align: center;
}

.right {
  flex: 0 0 150px;
  text-align: right;
}

.listItemC > div:first-child,
.listItemB > div:first-child {
  flex: 1;
  text-align: left;
}

.listItemC .tr4,
.listItemB .tr4 {
  margin: 0 10px;
}

.gggg {
  color: #999;
}
</style> 