<template>
  <view class="detail-container">
    <!-- 头部信息卡片 -->
    <view class="header-card">
      <view class="header-title">
        <text class="title-text">钢卷信息</text>
        <text class="coil-no">{{ coilInfo.currentCoilNo || '-' }}</text>
      </view>
      <view class="header-subtitle">
        <text class="subtitle-text">入场钢卷号: {{ coilInfo.enterCoilNo || '-' }}</text>
      </view>
    </view>
    
    <!-- 基础信息 -->
    <view class="info-section">
      <view class="section-title">
        <text class="title-icon">📋</text>
        <text class="title-text">基础信息</text>
      </view>
      <view class="info-grid">
        <view class="info-item">
          <text class="label">厂家卷号</text>
          <text class="value">{{ coilInfo.factoryCoilNo || '-' }}</text>
        </view>
        <view class="info-item">
          <text class="label">物料类型</text>
          <text class="value">{{ coilInfo.itemType || '-' }}</text>
        </view>
        <view class="info-item">
          <text class="label">产品名称</text>
          <text class="value">{{ coilInfo.itemName || '-' }}</text>
        </view>
        <view class="info-item">
          <text class="label">规格</text>
          <text class="value">{{ coilInfo.specification || '-' }}</text>
        </view>
        <view class="info-item">
          <text class="label">材质</text>
          <text class="value">{{ coilInfo.material || '-' }}</text>
        </view>
        <view class="info-item">
          <text class="label">厂家</text>
          <text class="value">{{ coilInfo.manufacturer || '-' }}</text>
        </view>
      </view>
    </view>
    
    <!-- 库存信息 -->
    <view class="info-section">
      <view class="section-title">
        <text class="title-icon">📦</text>
        <text class="title-text">库存信息</text>
      </view>
      <view class="info-grid">
        <view class="info-item">
          <text class="label">逻辑库区</text>
          <text class="value">{{ coilInfo.warehouseName || '-' }}</text>
        </view>
        <view class="info-item">
          <text class="label">实际库区</text>
          <text class="value">{{ coilInfo.actualWarehouseName || '-' }}</text>
        </view>
        <view class="info-item">
          <text class="label">净重(吨)</text>
          <text class="value">{{ coilInfo.netWeight || '-' }}</text>
        </view>
        <view class="info-item">
          <text class="label">毛重(吨)</text>
          <text class="value">{{ coilInfo.grossWeight || '-' }}</text>
        </view>
        <view class="info-item">
          <text class="label">长度(米)</text>
          <text class="value">{{ coilInfo.length || '-' }}</text>
        </view>
        <view class="info-item">
          <text class="label">质量状态</text>
          <text class="value" :class="getQualityClass(coilInfo.qualityStatus)">
            {{ coilInfo.qualityStatus || '-' }}
          </text>
        </view>
      </view>
    </view>
    
    <!-- 加工信息 -->
    <view class="info-section">
      <view class="section-title">
        <text class="title-icon">⚙️</text>
        <text class="title-text">加工信息</text>
      </view>
      <view class="info-grid">
        <view class="info-item">
          <text class="label">表面处理</text>
          <text class="value">{{ coilInfo.surfaceTreatment || '-' }}</text>
        </view>
        <view class="info-item">
          <text class="label">镀层质量</text>
          <text class="value">{{ coilInfo.coatingWeight || '-' }}</text>
        </view>
        <view class="info-item">
          <text class="label">包装要求</text>
          <text class="value">{{ coilInfo.packaging || '-' }}</text>
        </view>
        <view class="info-item">
          <text class="label">切边</text>
          <text class="value">{{ coilInfo.cuttingEdge || '-' }}</text>
        </view>
        <view class="info-item">
          <text class="label">班组</text>
          <text class="value">{{ coilInfo.team || '-' }}</text>
        </view>
        <view class="info-item">
          <text class="label">备注</text>
          <text class="value">{{ coilInfo.remark || '-' }}</text>
        </view>
      </view>
    </view>
    
    <!-- 操作信息 -->
    <view class="info-section">
      <view class="section-title">
        <text class="title-icon">👤</text>
        <text class="title-text">操作信息</text>
      </view>
      <view class="info-list">
        <view class="list-item">
          <text class="label">创建人</text>
          <text class="value">{{ coilInfo.creator || '-' }}</text>
        </view>
        <view class="list-item">
          <text class="label">创建时间</text>
          <text class="value">{{ coilInfo.createTime || '-' }}</text>
        </view>
        <view class="list-item">
          <text class="label">更新人</text>
          <text class="value">{{ coilInfo.updater || '-' }}</text>
        </view>
        <view class="list-item">
          <text class="label">更新时间</text>
          <text class="value">{{ coilInfo.updateTime || '-' }}</text>
        </view>
      </view>
    </view>
    
    <!-- 底部操作栏 -->
    <view class="footer-bar" v-if="actionId">
      <button class="btn btn-primary" @click="handleComplete">
        <text class="btn-icon">✓</text>
        <text class="btn-text">完成待办</text>
      </button>
    </view>
  </view>
</template>

<script>
import { getMaterialCoil } from '@/api/wms/coil'

export default {
  data() {
    return {
      coilId: null,
      actionId: null,
      coilInfo: {},
      loading: false
    }
  },
  onLoad(options) {
    this.coilId = options.coilId
    this.actionId = options.actionId
    if (this.coilId) {
      this.fetchDetail()
    } else {
      uni.showToast({
        title: '参数错误',
        icon: 'none'
      })
      setTimeout(() => {
        uni.navigateBack()
      }, 1500)
    }
  },
  methods: {
    async fetchDetail() {
      this.loading = true
      try {
        const res = await getMaterialCoil(this.coilId)
        this.coilInfo = res.data || {}
      } catch (error) {
        console.error('获取详情失败:', error)
        uni.showToast({
          title: '获取详情失败: ' + (error.message || '未知错误'),
          icon: 'none'
        })
      } finally {
        this.loading = false
      }
    },
    
    getQualityClass(status) {
      if (!status) return ''
      const statusMap = {
        'A': 'quality-a',
        'B': 'quality-b',
        'C': 'quality-c',
        'D': 'quality-d'
      }
      return statusMap[status] || ''
    },
    
    async handleComplete() {
      uni.showToast({
        title: '功能开发中',
        icon: 'none'
      })
    }
  }
}
</script>

<style scoped lang="scss">
.detail-container {
  min-height: 100vh;
  background: #f5f7fa;
  padding-bottom: 140rpx;
  
  .header-card {
    background: linear-gradient(135deg, #1a73e8 0%, #4285f4 100%);
    padding: 40rpx 30rpx;
    
    .header-title {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 16rpx;
      
      .title-text {
        font-size: 32rpx;
        color: rgba(255, 255, 255, 0.8);
      }
      
      .coil-no {
        font-size: 36rpx;
        color: #ffffff;
        font-weight: 600;
      }
    }
    
    .header-subtitle {
      .subtitle-text {
        font-size: 26rpx;
        color: rgba(255, 255, 255, 0.7);
      }
    }
  }
  
  .info-section {
    background: #ffffff;
    margin: 20rpx;
    border-radius: 16rpx;
    overflow: hidden;
    box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
    
    .section-title {
      display: flex;
      align-items: center;
      padding: 24rpx 30rpx;
      border-bottom: 1rpx solid #f0f0f0;
      
      .title-icon {
        font-size: 32rpx;
        margin-right: 12rpx;
      }
      
      .title-text {
        font-size: 30rpx;
        font-weight: 600;
        color: #333333;
      }
    }
    
    .info-grid {
      display: flex;
      flex-wrap: wrap;
      padding: 20rpx;
      
      .info-item {
        width: 50%;
        padding: 16rpx 10rpx;
        box-sizing: border-box;
        
        .label {
          display: block;
          font-size: 24rpx;
          color: #999999;
          margin-bottom: 8rpx;
        }
        
        .value {
          font-size: 28rpx;
          color: #333333;
          font-weight: 500;
          
          &.quality-a {
            color: #52c41a;
          }
          
          &.quality-b {
            color: #1890ff;
          }
          
          &.quality-c {
            color: #faad14;
          }
          
          &.quality-d {
            color: #ff4d4f;
          }
        }
      }
    }
    
    .info-list {
      padding: 0 30rpx;
      
      .list-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 24rpx 0;
        border-bottom: 1rpx solid #f0f0f0;
        
        &:last-child {
          border-bottom: none;
        }
        
        .label {
          font-size: 28rpx;
          color: #666666;
        }
        
        .value {
          font-size: 28rpx;
          color: #333333;
        }
      }
    }
  }
  
  .footer-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #ffffff;
    padding: 20rpx 30rpx;
    padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
    box-shadow: 0 -2rpx 12rpx rgba(0, 0, 0, 0.06);
    
    .btn {
      width: 100%;
      height: 88rpx;
      line-height: 88rpx;
      background: #1a73e8;
      color: #ffffff;
      font-size: 32rpx;
      font-weight: 600;
      border-radius: 12rpx;
      border: none;
      display: flex;
      align-items: center;
      justify-content: center;
      
      &::after {
        border: none;
      }
      
      .btn-icon {
        font-size: 32rpx;
        margin-right: 12rpx;
      }
      
      .btn-text {
        font-size: 32rpx;
      }
    }
  }
}
</style>
