<template>
  <!-- 页面整体容器 -->
  <div class="home">
    <!-- 导航栏 -->
     <nav-bar />
    
    <!-- 蓝色背景区域 -->
    <div class="blue-bg"></div>
    
    <!-- 医院信息区域 -->
    <div class="hos-info">
      <div class="pay-to">付款给</div>
      <div class="hos-name">{{ payInfo.hospitalName || '中国人民武装警察部队宁夏回族自治区总队医院' }}</div>
      <div class="hos-icon">
        <img src="@/assets/医院图标@2x.png" alt="医院图标" />
      </div>
    </div>
    
    <!-- 费用明细卡 -->
    <div class="fee-card">
      <div class="fee-item total-fee">
        <span style="font-size: 0.52rem; font-family: 'PingFang SC', 'Microsoft YaHei', '黑体', sans-serif; ">总费用:</span>
        <span class="fee-value">¥{{ payInfo.feeSumamt || '0.00' }}</span>
      </div>
      
      <!-- 总费用下方的横线 -->
      <div class="divider"></div>
      
      <div class="fee-item">
        <span>医保基金支付</span>
        <span class="fee-value">¥{{ payInfo.fundPay || '0.00' }}</span>
      </div>
      
      <div class="fee-item">
        <span>个人账户支付</span>
        <span class="fee-value">¥{{ payInfo.psnAcctPay || '0.00' }}</span>
      </div>
      
      <div class="fee-item">
        <span>其他抵扣金额</span>
        <span class="fee-value">¥{{ payInfo.othFeeAmt || '0.00' }}</span>
      </div>
      
      <div class="fee-item cash-pay">
        <span>现金支付</span>
        <span class="fee-value">¥{{ payInfo.ownPayAmt || '0.00' }}</span>
      </div>
      
      <!-- 现金支付下方的横线 -->
      <div class="divider"></div>
    </div>
    <!-- 医保支付信息 -->
      <div class="medical-payment-info">
        <div class="pay-icon-bottom">
          <img src="@/assets/医保混合支付@2x.png" class="medical-icon" alt="医保移动支付图标" />
          <span class="medical-text">医保移动支付</span>
        </div>
        
        <!-- 医保移动支付下方的横线 -->
        <div class="divider"></div>
      </div>
    <!-- 完成按钮区域 - 移至页面右下角 -->
    <div class="pay-bottom">
      <van-button type="primary" round @click="onConfirm" class="pay-btn">完成</van-button>
    </div>
  </div>
</template>

<script>
import { Icon, Button } from 'vant'

export default {
  components: {
    [Icon.name]: Icon,
    [Button.name]: Button
  },
  data() {
    return {
      payInfo: {}
    }
  },
  mounted() {
    // 从全局状态获取支付信息
    try {
      // 优先从Vuex获取
      if (this.$store.state.ybPayInfo && Object.keys(this.$store.state.ybPayInfo).length > 0) {
        this.payInfo = this.$store.state.ybPayInfo
      } else {     
          // 备用：从路由参数获取
         const options = this.$route.query
        if (options.data) {
             const decodeData = JSON.parse(decodeURIComponent(options.data))
      this.payInfo =  decodeData
        }
        
      }
    } catch (error) {
      console.error('获取支付信息失败:', error)
    }
  },
  methods: {
    onConfirm() {
      // 跳转到首页
    this.$router.replace('/Member_wdzd')
    }
  }
}
</script>

<style scoped lang="scss">
.home {
  position: relative;
  min-height: 100vh;
  background-color: #ffffff;
  padding-top: 0;
  padding-bottom: 1.6rem; // 为底部按钮预留空间
}

// 导航栏样式
.nav-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 1.1733rem; // 44px
  padding: 0 0.4rem; // 15px → 0.4rem
  background-color: #3B71E8;
  color: white;
  position: relative;
  z-index: 10;

  .back-btn,
  .more-btn {
    width: 1.1733rem;
    height: 1.1733rem;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .nav-title {
    font-size: 0.42rem; // 18px → 0.48rem? 但限制最大 0.42rem
    font-weight: 500;
  }
}

// 蓝色背景区域
.blue-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 7rem; // 200px
  background-color: #3B71E8;
  border-radius: 0 0 2.1333rem 2.1333rem; // 80px ≈ 40% of 200px
  z-index: 1;
}

// 医院信息区域
.hos-info {
  position: relative;
  padding: 0.5333rem 0.4rem 0; // 20px, 15px
  color: white;
  z-index: 2;

  .pay-to {
    font-size: 0.39rem; // 14px → ~0.37rem, but cap at 0.3 for subtitle
    opacity: 0.8;
    margin-bottom: 0.1333rem; // 5px
    color: #a6c1ff;
   font-weight: normal;
  }

  .hos-name {
    font-size: 0.42rem; // 18px → 0.48rem → clamp to 0.42rem
    font-weight: 500;
    width: 59%;
    color: #ffffff;
  }

  .hos-icon {
    position: absolute;
    top: 0.6667rem; // 25px
    right: 0.4rem; // 15px
    width: 1.5rem; // 40px
    height: 1.5rem;

    img {
      width: 60%;
      height: 60%;
      object-fit: contain;
    }
  }
}

// 费用明细卡片
.fee-card {
  position: relative;
  z-index: 2;
  background-color: white;
  border-radius: 0.32rem; // 12px
  margin: 0.4rem; // 15px
  padding: 0.5333rem; // 20px
  box-shadow: 0 0.0533rem 0.2667rem rgba(0, 0, 0, 0.05); // 2px, 10px

  .fee-item {
    display: flex;
    justify-content: space-between;
    padding: 0.32rem 0; // 12px
    font-size: 0.4rem; // 16px → 0.4267rem → clamp to 0.3733 (~14px) or 0.4?

    // span:first-child {
    //   color: #666;
    //   font-weight: normal;
    // }

    .fee-value {
      color: #333;
      font-weight: 500;
    }

  }

  .total-fee {
    font-weight: bold;

    span:first-child {
      color: #333;
    }

    .fee-value {
      font-size: 0.52rem; // 强调总额
      font-weight: bold;
    }
  }

  .cash-pay {
    span,
    .fee-value {
      color: #3B71E8 !important;
      font-weight: bold;
      font-size: 0.42rem;
    }
  }

  .divider {
    height: 0.0267rem; // 1px
    background-color: #f5f5f5;
    margin: 0.2667rem 0; // 10px
  }
}
 .medical-payment-info {
    padding: 0.4rem 0 0.1333rem; // 15px, 5px
position: absolute;
bottom: 16vh;
width: 100%;
    .pay-icon-bottom {
      display: flex;
      justify-content: center;
      align-items: center;
      margin-bottom: 0.2667rem; // 10px

      .medical-icon {
        width: 1rem;  // 确保图标与文字大小一致
        margin-right: 0.2133rem; // 8px
        object-fit: contain;
      }

      .medical-text {
        font-size: 0.3867rem; // 与图标大小一致
        color: #999;
      }
    }
     .divider {
    height: 0.0267rem; // 1px
    background-color: #f5f5f5;
    margin: 0.2667rem 0; // 10px
  }
  }
// 完成按钮区域样式 - 调整为页面右下角
.pay-bottom {
  position: fixed;
  bottom: 2.5vh; // 15px
  right: 0.4rem;  // 15px
  z-index: 10;

  .pay-btn {
    width: 3.2rem; // 120px
    height: 1.0667rem; // 40px
    background: linear-gradient(135deg, #3B71E8 0%, #2A57C4 100%);
    color: white;
    font-size: 0.4rem; // 16px
    border-radius: 0.5333rem; // 20px
    border: none;
    box-shadow: none;
  }
}

// 保留底部支付栏样式作为兼容，但默认不使用
.bottom-pay-bar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 1.6rem; // 60px
  background-color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 0.4rem; // 15px
  box-shadow: 0 -0.0533rem 0.2667rem rgba(0, 0, 0, 0.05);
  z-index: 10;

  .amount-to-pay {
    font-size: 0.3467rem; // 14px
    color: #666;

    .amount-value {
      font-size: 0.42rem; // 18px
      color: #3B71E8;
      font-weight: bold;
      margin-left: 0.1333rem; // 5px
    }
  }
}
</style>