<template>
    <view class="container">
      <u-navbar
			leftIconSize="40rpx"
			leftIconColor="#333333"
			title="信用卡详情"
		>
		</u-navbar>
      
      <view class="detail-card">
        <view class="card-header">
          <view class="header-icon">
            <uni-icons type="vip-filled" size="24" color="#ffffff"></uni-icons>
          </view>
          <view class="header-info">
            <text class="card-name">{{ detailInfo.name }}<text class="card-code" v-if="detailInfo.code">({{ detailInfo.code }})</text></text>
          </view>
        </view>
        
        <view class="card-body">
          <view class="info-section">
            <view class="section-title">
              <view class="title-icon"></view>
              <text>账户信息</text>
            </view>
            <view class="info-list">
              <view class="list-item">
                <text class="item-label">信用额度</text>
                <text class="item-value primary">{{ detailInfo.creditLimit }}元</text>
              </view>
              <view class="list-item">
                <text class="item-label">可用额度</text>
                <text class="item-value orange">{{ detailInfo.availableLimit }}元</text>
              </view>
              <view class="list-item">
                <text class="item-label">余额</text>
                <text class="item-value orange">{{ detailInfo.balance }}元</text>
              </view>
              <view class="list-item">
                <text class="item-label">账户状态</text>
                <text class="item-value" :class="getStatusClass(detailInfo.status, detailInfo.statusText)">{{ detailInfo.statusText }}</text>
              </view>
              <view class="list-item">
                <text class="item-label">银行</text>
                <text class="item-value">{{ detailInfo.bankName || '-' }}</text>
              </view>
              <view class="list-item">
                <text class="item-label">卡片等级</text>
                <text class="item-value">{{ detailInfo.cardTierText || '-' }}</text>
              </view>
              <view class="list-item">
                <text class="item-label">卡面</text>
                <text class="item-value">{{ detailInfo.cardFace || '-' }}</text>
              </view>
            </view>
          </view>
          
          <view class="info-section">
            <view class="section-title">
              <view class="title-icon"></view>
              <text>账单信息</text>
            </view>
            <view class="info-list">
              <view class="list-item">
                <text class="item-label">账单日</text>
                <text class="item-value">{{ detailInfo.billDateName }}</text>
              </view>
              <view class="list-item">
                <text class="item-label">还款日</text>
                <text class="item-value">{{ detailInfo.payDateName }}</text>
              </view>
              <view class="list-item">
                <text class="item-label">延缓期限</text>
                <text class="item-value">{{ detailInfo.delayPeriod }}</text>
              </view>
              <view class="list-item">
                <text class="item-label">账单日消费</text>
                <text class="item-value">{{ detailInfo.isNextBillDate }}</text>
              </view>
              <view class="list-item">
                <text class="item-label">0账单操作</text>
                <text class="item-value">{{ detailInfo.isZeroBill }}</text>
              </view>
            </view>
          </view>
          
          <view class="info-section">
            <view class="section-title">
              <view class="title-icon"></view>
              <text>开户信息</text>
            </view>
            <view class="info-list">
              <view class="list-item">
                <text class="item-label">开户行</text>
                <text class="item-value">{{ detailInfo.openingBank || '-' }}</text>
              </view>
              <view class="list-item">
                <text class="item-label">开户日期</text>
                <text class="item-value">{{ detailInfo.activationDate }}</text>
              </view>
              <view class="list-item">
                <text class="item-label">有效期</text>
                <text class="item-value">{{ detailInfo.effectiveDate }}</text>
              </view>
            </view>
          </view>
          
          <view class="info-section" v-if="detailInfo.remark">
            <view class="section-title">
              <view class="title-icon"></view>
              <text>备注</text>
            </view>
            <view class="remark-content">
              <text>{{ detailInfo.remark }}</text>
            </view>
          </view>
        </view>
      </view>
      
      <u-toast ref="uToast"></u-toast>
    </view>
  </template>
  
<script setup>
import { getBankcardLend} from '@/api/invest/bankcardlend'
import { getDicts } from '@/api/system/dict/data.js'
import { listBankBaseInfo } from '@/api/invest/bankBaseInfo'
import {onLoad} from "@dcloudio/uni-app";
import {reactive ,toRefs,ref,computed }from "vue";
const id = ref('')
const data = reactive({
  detailInfo: {} 
})
const {detailInfo} = toRefs(data)

function formatCardCode(code) {
  if (!code) return ''
  // 去除所有空格和特殊字符
  const cleanCode = code.replace(/\s+/g, '')
  // 如果卡号长度小于等于4位，直接返回
  if (cleanCode.length <= 4) return code
  // 只显示后4位，前面用 XX 替代
  const suffix = cleanCode.substring(cleanCode.length - 4)
  return `XX ${suffix}`
}

function getStatusClass(status, statusText) {
 // 根据状态值判断
  const statusStr = String(status)
  if (statusStr === '1') {
    return 'status-normal'
  }
  if (statusStr === '5') {
    return 'status-error'
  }
  
  return 'status-default'
}

onLoad((option) => {
    id.value = option.id
    getInfo()
  })
  function getInfo() {
    getBankcardLend(id.value).then(res => {
          detailInfo.value = res.data
          detailInfo.value.statusText = res.data.status
                     // 类型
            getDicts('is_next_bill_date').then(result => {
         detailInfo.value.isNextBillDate=dictStr(detailInfo.value.isNextBillDate, result.data)
      })
                           // 类型
            getDicts('is_zero_bill').then(result => {
         detailInfo.value.isZeroBill=dictStr(detailInfo.value.isZeroBill, result.data)
      })
          // 类型
              getDicts('account_status').then(result => {
         detailInfo.value.statusText=dictStr(detailInfo.value.status, result.data)
      })
          // 卡片等级
          getDicts('card_tier').then(result => {
         detailInfo.value.cardTierText=dictStr(detailInfo.value.cardTier, result.data)
      })
          // 银行名称
          listBankBaseInfo({ pageSize: 1000, pageNum: 1 }).then(res => {
          const bank = res.rows.find(item => item.id === detailInfo.value.bankId)
          if (bank) {
            detailInfo.value.bankName = bank.bankName
          }
      })
        })
  }
  function dictStr(val, arr) {
      let str = ''
      arr.map(item => {
        if (item.dictValue === val) {
          str = item.dictLabel
        }
      })
      return str
    }
  </script>
  
  <style lang="scss" scoped>
.container {
  background: #f5f7fa;
  padding-bottom: 24rpx;
}

.detail-card {
  margin: 24rpx;
  background: #ffffff;
  border-radius: 16rpx;
  box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16rpx 20rpx;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  
  .header-icon {
    width: 48rpx;
    height: 48rpx;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 16rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12rpx;
    backdrop-filter: blur(10rpx);
  }
  
  .header-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    
    .card-name {
      color: #ffffff;
      font-size: 28rpx;
      font-weight: 600;
      line-height: 1.2;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      
        .card-code {
          color: rgba(255, 255, 255, 0.85);
          font-size: 28rpx;
          font-weight: 400;
          margin-left: 8rpx;
        }
      }
    }
  }

  .card-body {
    padding: 16rpx;
  }

  .info-section {
  margin-bottom: 20rpx;
  
  &:last-child {
    margin-bottom: 0;
  }
  
  .section-title {
    display: flex;
    align-items: center;
    margin-bottom: 12rpx;
    
    .title-icon {
      width: 6rpx;
      height: 28rpx;
      background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
      border-radius: 3rpx;
      margin-right: 12rpx;
    }
    
    text {
      color: #2c3e50;
      font-size: 28rpx;
      font-weight: 600;
    }
  }
  
  .info-list {

    
    .list-item {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 16rpx;
      background: #f8f9fa;
      border-radius: 8rpx;
      margin-bottom: 5rpx;
      
      &:last-child {
        margin-bottom: 0;
      }
      
      .item-label {
        color: #7f8c8d;
        font-size: 26rpx;
      }
      
      .item-value {
        color: #2c3e50;
        font-size: 28rpx;
        font-weight: 500;
        text-align: right;
        
        &.primary {
          color: #667eea;
        }
        
        &.orange {
          color: #fa8c16;
        }
        
        &.status-normal {
          color: #52c41a;
        }
        
        &.status-error {
          color: #ff4d4f;
        }
        
        &.status-default {
          color: #666666;
        }
      }
    }
  }
  
  .remark-content {
    padding: 16rpx;
    background: #f8f9fa;
    border-radius: 8rpx;
    
    text {
      color: #2c3e50;
      font-size: 26rpx;
      line-height: 1.6;
    }
  }
}
</style>