<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="record-list">
      <div class="listItem" v-for="(item, index) in records" :key="index">
        <div class="flex listItemC">
          <div class="tr4">类型</div>
          <div class="money-col">金额</div>
          <div class="status-text">状态</div>
          <div class="remark">详情</div>
          <div class="right">日期</div>
        </div>
        <div class="flex listItemB">
          <div class="tr4">{{ getTypeText(item.type) }}</div>
          <div class="money-col money-text">{{ item.money }}</div>
          <div class="status-text">{{ getStatusText(item.stat, item) }}</div>
          <div class="remark">{{ item.remark || '-' }}</div>
          <div class="right gggg">
            <div>{{ item.addtime.split(' ')[0] }}</div>
            <div>{{ item.addtime.split(' ')[1] }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

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

export default {
  name: 'OrderList',
  data() {
    return {
      userInfo: {},
      records: []
    }
  },
  created() {
    this.getUserInfo();
    this.getRecords();
  },
  methods: {
    async getUserInfo() {
      try {
        const res = await getUserInfo();
        this.userInfo = res.data;
      } catch (error) {
        console.error('获取用户信息失败:', error);
      }
    },
    async getRecords() {
      try {
        const res = await getWithdrawRecords();
        this.records = res.data || [];
      } catch (error) {
        console.error('获取提现记录失败:', error);
      }
    },
    getStatusText(stat, item) {
      if (stat === 0 && item.type === 2) {
        // 获取提现日期
        const withdrawDate = new Date(item.addtime);
        const cutoffDate = new Date('2025-06-29 00:00:00');
        
        if (withdrawDate < cutoffDate) {
          return '审核已通过，7月20号到账您的银行卡';
        } else {
          // 计算到账日期：提现日期 + 21天
          const arrivalDate = new Date(withdrawDate);
          arrivalDate.setDate(withdrawDate.getDate() + 21);
          
          const month = arrivalDate.getMonth() + 1;
          const day = arrivalDate.getDate();
          
          return `审核已通过，${month}月${day}号到账您的银行卡`;
        }
      }
      
      const statusMap = {
        0: '审核中',
        1: '提现成功',
        2: '提现失败'
      };
      return statusMap[stat] || '未知';
    },
    getTypeText(type) {
      const typeMap = {
        1: '红旗资产',
        2: '退休补贴',
        3: '党员薪资',
        4: '每日分红',
        5: '原始股权'
      };
      return typeMap[type] || '未知';
    }
  }
}
</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;
}

.record-list {
  padding: 15px;
}

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

.flex {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.listItemC {
  color: #999;
  font-size: 14px;
  margin-bottom: 10px;
}

.listItemB {
  color: #333;
  font-size: 14px;
  margin-bottom: 5px;
}

.tr4 {
  flex: 0 0 75px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 2px;
}

.type-text {
  font-size: 13px;
  color: #666;
}

.money-col {
  flex: 0 0 70px;
  text-align: center;
}

.money-text {
  font-size: 16px;
  color: #222;
  font-weight: bold;
}

.right {
  flex: 0 0 132px;
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  word-break: break-all;
}

.gggg {
  color: #999;
}

.status-row {
  width: 100%;
  justify-content: center;
  margin-top: 10px;
}

.status-text {
  color: #666;
  font-size: 14px;
  flex: 0 0 65px;
}

.remark {
  flex: 0 1 auto;
  min-width: 20px;
  max-width: 120px;
  text-align: left;
  color: #666;
  font-size: 13px;
  padding-left: 10px;
  word-break: break-all;
}
</style> 