<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="list" size="24" color="#ffffff"></uni-icons>
          </view>
          <view class="header-info">
            <text class="card-name">{{ detailInfo.accountName }}</text>
          </view>
          <view class="amount-group">
            <view class="status-badge" :class="detailInfo.dealType === '收入' ? 'status-income' : 'status-expense'">
              <text>{{ detailInfo.dealType }}</text>
            </view>
            <text class="amount-value" :class="detailInfo.dealType === '收入' ? 'status-income' : 'status-expense'">{{ detailInfo.amount }}元</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">{{ detailInfo.type }}</text>
              </view>
                <view class="list-item">
                <text class="item-label">交易时间</text>
                <text class="item-value">{{ detailInfo.createTime }}</text>
              </view>
              <view class="list-item">
                <text class="item-label">交易类别</text>
                <text class="item-value">{{ detailInfo.dealCategory }}</text>
              </view>
              <view class="list-item" v-if="detailInfo.childCategory && detailInfo.childCategory != detailInfo.dealCategory">
                <text class="item-label">交易子类别</text>
                <text class="item-value">{{ detailInfo.childCategoryName }}</text>
              </view>
              <view class="list-item">
                <text class="item-label">余额</text>
                <text class="item-value orange">{{ detailInfo.currentBalance }}元</text>
              </view>
            </view>
          </view>

          <view class="info-section" v-if="detailInfo.locationAddress || detailInfo.locationName">
            <view class="section-title">
              <view class="title-icon"></view>
              <text>地点</text>
            </view>
            <view class="location-content">
              <text v-if="detailInfo.locationName" class="location-name">{{ detailInfo.locationName }}</text>
              <text class="location-address">{{ detailInfo.locationAddress || detailInfo.locationName }}</text>
              <view v-if="hasCoordinate" class="location-map" @click="openLocation">
                <uni-icons type="paperplane" size="16" color="#667eea"></uni-icons>
                <text>查看地图</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 { getAccountDealRecord} from '@/api/invest/accountDealRecord'
import {onLoad} from "@dcloudio/uni-app";
import { getDicts } from '@/api/system/dict/data.js'
import {reactive ,toRefs,ref,computed }from "vue";
const id = ref('')
const data = reactive({
  detailInfo: {} 
})
const {detailInfo} = toRefs(data)
const hasCoordinate = computed(() => {
  return detailInfo.value.longitude !== null && detailInfo.value.longitude !== undefined
    && detailInfo.value.latitude !== null && detailInfo.value.latitude !== undefined
})
onLoad((option) => {
    id.value = option.id
    getInfo()
  })
  function getInfo() {
    getAccountDealRecord(id.value).then(res => {
          detailInfo.value = res.data
          // 类型
        getDicts('account_type').then(result => {
          detailInfo.value.type=dictStr(detailInfo.value.type, result.data)
      })
       // 交易类型
          getDicts('deal_type').then(result => {
         detailInfo.value.dealType=dictStr(detailInfo.value.dealType, result.data)
      })
          // 交易类别
        getDicts('deal_category').then(result => {
         detailInfo.value.dealCategory=dictStr(detailInfo.value.dealCategory, result.data)
      })
      // 交易子类别（如果需要）
      if(detailInfo.value.childCategory && detailInfo.value.childCategory != detailInfo.value.dealCategory) {
        getDicts('daily_expenses').then(result => {
          detailInfo.value.childCategoryName=dictStr(detailInfo.value.childCategory, result.data)
        })
      }
        })
  }
  function dictStr(val, arr) {
      let str = ''
      arr.map(item => {
        if (item.dictValue === val) {
          str = item.dictLabel
        }
      })
      return str
    }
  function openLocation() {
    const latitude = Number(detailInfo.value.latitude)
    const longitude = Number(detailInfo.value.longitude)
    if (!Number.isFinite(latitude) || !Number.isFinite(longitude)) {
      return
    }
    uni.openLocation({
      latitude,
      longitude,
      name: detailInfo.value.locationName || '',
      address: detailInfo.value.locationAddress || detailInfo.value.locationName || ''
    })
  }
  </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%);
  min-height: 80rpx;
  
  .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;
    }
  }
  
  .amount-group {
    display: flex;
    align-items: center;
    gap: 12rpx;
    flex-shrink: 0;
    
    .amount-value {
      font-size: 32rpx;
      font-weight: 700;
      line-height: 1;
      white-space: nowrap;
      
      &.status-income {
        color: #52c41a;
      }
      
      &.status-expense {
        color: #ff4d4f;
      }
    }
  }
  
  .status-badge {
    padding: 12rpx 28rpx;
    border-radius: 24rpx;
    font-size: 26rpx;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    line-height: 1;
    
    text {
      line-height: 1;
    }
    
    &.status-income {
      background: #52c41a;
      color: #ffffff;
      box-shadow: 0 2rpx 8rpx rgba(82, 196, 26, 0.3);
    }
    
    &.status-expense {
      background: #ff4d4f;
      color: #ffffff;
      box-shadow: 0 2rpx 8rpx rgba(255, 77, 79, 0.3);
    }
  }
}

.card-body {
  padding: 24rpx;
}

.info-section {
  margin-bottom: 32rpx;
  
  &:last-child {
    margin-bottom: 0;
  }
  
  .section-title {
    display: flex;
    align-items: center;
    margin-bottom: 20rpx;
    
    .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: 20rpx;
      background: #f8f9fa;
      border-radius: 8rpx;
      margin-bottom: 12rpx;
      
      &: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;
        
        &.orange {
          color: #fa8c16;
        }
        
        &.status-income {
          color: #52c41a;
        }
        
        &.status-expense {
          color: #ff4d4f;
        }
      }
    }
  }
  
  .remark-content {
    padding: 20rpx;
    background: #f8f9fa;
    border-radius: 8rpx;
    
    text {
      color: #2c3e50;
      font-size: 26rpx;
      line-height: 1.6;
    }
  }

  .location-content {
    padding: 20rpx;
    background: #f8f9fa;
    border-radius: 8rpx;

    .location-name,
    .location-address {
      display: block;
      color: #2c3e50;
      font-size: 26rpx;
      line-height: 1.6;
      word-break: break-all;
    }

    .location-name {
      font-weight: 600;
    }

    .location-address {
      color: #606266;
    }

    .location-map {
      display: inline-flex;
      align-items: center;
      gap: 8rpx;
      margin-top: 16rpx;
      padding: 10rpx 18rpx;
      background: rgba(102, 126, 234, 0.1);
      border-radius: 10rpx;

      text {
        color: #667eea;
        font-size: 24rpx;
        font-weight: 500;
      }
    }
  }
}
  </style>
