<template>
    <view class="container" style="paddingBottom:1rpx;">
      <view class="detail-card">
        <view class="card-header">
          <view class="header-icon">
            <uni-icons type="plusempty" size="24" color="#ffffff"></uni-icons>
          </view>
          <view class="header-info">
            <text class="card-name">{{ detailInfo.medicineName }}</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.code || '-' }}</text>
              </view>
              <view class="list-item">
                <text class="item-label">入库数量</text>
                <text class="item-value">{{ detailInfo.quantity || '-' }}</text>
              </view>
              <view class="list-item">
                <text class="item-label">购买时间</text>
                <text class="item-value">{{ detailInfo.purchaseDate || '-' }}</text>
              </view>
              <view class="list-item">
                <text class="item-label">使用状态</text>
                <text class="item-value">{{ detailInfo.state || '-' }}</text>
              </view>
              <view class="list-item">
                <text class="item-label">生产日期</text>
                <text class="item-value">{{ detailInfo.productionDate || '-' }}</text>
              </view>
              <view class="list-item">
                <text class="item-label">过期日期</text>
                <text class="item-value">{{ detailInfo.expiringDate || '-' }}</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.packageUnit || '-' }}</text>
              </view>
              <view class="list-item">
                <text class="item-label">规格总数</text>
                <text class="item-value">{{ detailInfo.totalCount || '-' }}</text>
              </view>
              <view class="list-item">
                <text class="item-label">规格单位</text>
                <text class="item-value">{{ detailInfo.unit || '-' }}</text>
              </view>
              <view class="list-item">
                <text class="item-label">已使用数量</text>
                <text class="item-value">{{ detailInfo.usedCount || '-' }}</text>
              </view>
              <view class="list-item">
                <text class="item-label">剩余数量</text>
                <text class="item-value">{{ detailInfo.leftCount || '-' }}</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.purchasePrice || '-' }}</text>
              </view>
              <view class="list-item">
                <text class="item-label">药品总价</text>
                <text class="item-value">{{ detailInfo.totalPrice || '-' }}</text>
              </view>
              <view class="list-item">
                <text class="item-label">年龄体重</text>
                <text class="item-value">{{ detailInfo.ageWeight || '-' }}</text>
              </view>
              <view class="list-item">
                <text class="item-label">购买地址</text>
                <text class="item-value">{{ detailInfo.purchaseAddress || '-' }}</text>
              </view>
            </view>
          </view>
          
          <view class="info-section" v-if="detailInfo.usage">
            <view class="section-title">
              <view class="title-icon"></view>
              <text>医嘱</text>
            </view>
            <view class="remark-content">
              <text>{{ detailInfo.usage }}</text>
            </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 { getMedicineStockIn } from '@/api/health/medicineStockIn'
import { getDicts } from '@/api/system/dict/data.js'
import {onLoad} from "@dcloudio/uni-app";
import {reactive ,toRefs,ref,computed }from "vue";
const id = ref('')
const data = reactive({
  detailInfo: {} 
})
const {detailInfo} = toRefs(data)
onLoad((option) => {
    id.value = option.id
    getInfo()
  })
  function getInfo() {
    getMedicineStockIn(id.value).then(res => {
          detailInfo.value = res.data

       // 类型
       getDicts('used_state').then(result => {
         detailInfo.value.state=dictStr(detailInfo.value.state, result.data)
      })
       // 类型
       getDicts('package_unit').then(result => {
         detailInfo.value.packageUnit=dictStr(detailInfo.value.packageUnit, result.data)
      })
    
       // 类型
       getDicts('medical_unit').then(result => {
         detailInfo.value.unit=dictStr(detailInfo.value.unit, result.data)
      })
       
        })
  }
  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-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;
      }
    }
  }
  
  .remark-content {
    padding: 20rpx;
    background: #f8f9fa;
    border-radius: 8rpx;
    
    text {
      color: #2c3e50;
      font-size: 26rpx;
      line-height: 1.6;
    }
  }
}
  </style>