<template>
  <view class="container">
    <!-- 顶部导航 -->
    <view class="nav-bar">
      <view class="back" @tap="goBack">
        <text class="iconfont">←</text>
      </view>
      <text class="title">质检报告</text>
    </view>
    <view class="subtitle">该报告由「潮海回收」质检查验出具</view>

    <!-- 检测类型标签 -->
    <view class="check-types">
      <view class="type-tag">
        <text class="check-icon">✓</text>
        <text>透明检</text>
      </view>
      <view class="type-tag">
        <text class="check-icon">✓</text>
        <text>专业验</text>
      </view>
      <view class="type-tag">
        <text class="check-icon">✓</text>
        <text>公正评</text>
      </view>
      <view class="type-tag">
        <text class="check-icon">✓</text>
        <text>逐件验</text>
      </view>
    </view>

    <!-- 详细内容 -->
    <view class="content">
      <view class="detail-section">
        <text class="section-title">详细内容</text>
        
        <!-- 检测结果 -->
        <view class="result-section">
          <text class="label">检测结果</text>
          <view :class="['result-tag', isQualified ? 'qualified' : 'unqualified']">
            {{ isQualified ? '合格' : '不合格' }}
          </view>
        </view>

        <!-- 结果说明 -->
        <view class="result-desc">
          <text>{{ resultDescription }}</text>
        </view>

        <!-- 回收信息 -->
        <view class="info-item">
          <text class="label">回收编号</text>
          <text class="value">{{ orderNo }}</text>
        </view>
        <view class="info-item">
          <text class="label">回收时间</text>
          <text class="value">{{ pickupTime }}</text>
        </view>

        <!-- 不合格原因列表 -->
        <block v-if="!isQualified">
          <text class="section-subtitle">不合格原因</text>
          <view class="reason-grid">
            <view class="reason-item" v-for="(reason, index) in reasons" :key="index">
              <text class="close-icon">×</text>
              <text class="reason-title">{{ reason.title }}</text>
              <text class="detail-link" @tap="viewDetail(reason)">查看详情 ></text>
            </view>
          </view>
          <view class="bottom-note">
            感谢您的理解与支持！期待您再次参与我们的旧衣回收活动，共同为环保贡献力量。
          </view>
        </block>

        <!-- 合格说明 -->
        <block v-else>
          <text class="section-subtitle">回收去向</text>
          <view class="qualified-desc">
            <view class="desc-item">
              <text class="dot">•</text>
              <text>可捐赠衣物：部分品相较好的衣物将捐赠给有需要的群体，为他们送去温暖与关怀。</text>
            </view>
            <view class="desc-item">
              <text class="dot">•</text>
              <text>可再生利用衣物：部分衣物将进入再生利用流程，转化为其他有用的产品，如清洁用品、保温材料等。</text>
            </view>
          </view>
          <view class="bottom-note success">
            再次感谢您的环保行动，您的小小举动为地球环保做出了大大的贡献！
          </view>
        </block>
      </view>
    </view>

    <!-- 底部按钮 -->
    <view class="bottom-btn" v-if="!isQualified">
      <button class="reorder-btn" @tap="reorder">再次预约下单</button>
    </view>
  </view>
</template>

<script>
import pullRefreshMixin from '@/pages/mixins/pullRefreshMixin.js'

export default {
  mixins: [pullRefreshMixin],
  data() {
    return {
      isQualified: false, // 是否合格
      orderNo: 'RE82738127861525', // 回收编号
      pickupTime: '2025-04-20 11:00', // 回收时间
      resultDescription: '感谢您参与旧衣回收活动，支持环保事业。', // 结果说明
      reasons: [
        {
          title: '大面积破损',
          detail: '破损无法修复'
        },
        {
          title: '污渍无法清除',
          detail: '严重污渍'
        },
        {
          title: '附件缺失',
          detail: '重要配件缺失'
        },
        {
          title: '带有危险物品',
          detail: '不符合安全标准'
        },
        {
          title: '尺寸过小',
          detail: '不符合回收标准'
        },
        {
          title: '尺寸过大',
          detail: '超出处理范围'
        }
      ]
    }
  },
  onLoad(options) {
    // 根据传入参数设置检测结果
    if (options.status) {
      this.isQualified = options.status === 'qualified'
      this.resultDescription = this.isQualified
        ? '我们已收到您的旧衣，并完成质检。很高兴地通知您，此次回收的旧衣全部符合回收标准。'
        : '感谢您参与旧衣回收活动，支持环保事业。我们已收到您的旧衣，并完成质检。遗憾地通知您，此次回收的部分旧衣不符合回收标准。'
    }
  },
  methods: {
    async onRefresh() {
      // 模拟刷新数据
      await new Promise(resolve => setTimeout(resolve, 1000))
      this.stopPullRefresh()
    },
    goBack() {
      uni.navigateBack()
    },
    viewDetail(reason) {
      // 查看详情逻辑
      uni.showModal({
        title: reason.title,
        content: reason.detail,
        showCancel: false
      })
    },
    reorder() {
      // 跳转到预约页面
      uni.navigateTo({
        url: '/pages/pickup/index'
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.container {
  min-height: 100vh;
  background: #4A332D;
  padding-bottom: v-bind('isQualified ? "0" : "calc(120rpx + env(safe-area-inset-bottom))"');
}

.nav-bar {
  display: flex;
  align-items: center;
  height: 88rpx;
  padding: 0 30rpx;

  .back {
    padding: 20rpx;
    margin-left: -20rpx;
    color: #fff;
  }

  .title {
    flex: 1;
    text-align: center;
    font-size: 34rpx;
    font-weight: 500;
    color: #fff;
  }

  .right-btns {
    display: flex;
    gap: 30rpx;
    
    .more, .share {
      font-size: 40rpx;
      color: #fff;
    }
  }
}

.subtitle {
  text-align: center;
  font-size: 24rpx;
  color: rgba(255, 255, 255, 0.8);
  margin-bottom: 30rpx;
}

.check-types {
  display: flex;
  justify-content: space-between;
  padding: 0 30rpx;
  margin-bottom: 30rpx;

  .type-tag {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 30rpx;
    padding: 10rpx 20rpx;
    display: flex;
    align-items: center;
    gap: 8rpx;
    color: #fff;
    font-size: 24rpx;

    .check-icon {
      font-size: 24rpx;
    }
  }
}

.content {
  background: linear-gradient(to bottom, #fef2da,3%,#fffefb);
  border-radius: 30rpx 30rpx 0 0;
  min-height: calc(100vh - 200rpx);
  padding: 30rpx;
  
  .detail-section {
    .section-title {
      font-size: 32rpx;
      font-weight: bold;
      color: #333;
      margin-bottom: 30rpx;
    }

    .result-section {
      margin-bottom: 20rpx;

      .label {
        font-size: 28rpx;
        color: #666;
        margin-bottom: 10rpx;
        display: block;
      }

      .result-tag {
        display: inline-block;
        padding: 4rpx 20rpx;
        border-radius: 8rpx;
        font-size: 26rpx;
        
        &.qualified {
          background: #4CAF50;
          color: #fff;
        }
        
        &.unqualified {
          background: #FF5252;
          color: #fff;
        }
      }
    }

    .result-desc {
      font-size: 28rpx;
      color: #666;
      line-height: 1.6;
      margin-bottom: 30rpx;
    }

    .info-item {
      margin-bottom: 20rpx;

      .label {
        font-size: 28rpx;
        color: #666;
        margin-bottom: 8rpx;
        display: block;
      }

      .value {
        font-size: 28rpx;
        color: #333;
      }
    }

    .section-subtitle {
      font-size: 30rpx;
      font-weight: bold;
      color: #333;
      margin: 30rpx 0 20rpx;
    }

    .reason-grid {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 20rpx;
      padding: 20rpx 0;

      .reason-item {
        background: #fff;
        border-radius: 12rpx;
        padding: 20rpx;
        display: flex;
        flex-direction: column;
        align-items: center;
        text-align: center;
        box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
        position: relative;

        .close-icon {
          position: absolute;
          top: 70rpx;
          right: 10rpx;
          color: #FF5252;
          font-size: 32rpx;
          line-height: 1;
          font-weight: bold;
        }

        .reason-title {
          font-size: 26rpx;
          color: #333;
          margin-bottom: 10rpx;
          font-weight: 500;
          margin-top: 10rpx;
        }

        .detail-link {
          font-size: 24rpx;
          color: #999;
          display: flex;
          align-items: center;
          gap: 4rpx;

        }
      }
    }

    .qualified-desc {
      .desc-item {
        display: flex;
        margin-bottom: 20rpx;
        
        .dot {
          margin-right: 10rpx;
          color: #666;
        }
        
        text {
          font-size: 28rpx;
          color: #666;
          line-height: 1.6;
        }
      }
    }

    .bottom-note {
      font-size: 28rpx;
      color: #666;
      line-height: 1.6;
      margin-top: 40rpx;
      text-align: center;

      &.success {
        color: #4CAF50;
      }
    }
  }
}

.bottom-btn {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 20rpx 30rpx calc(20rpx + env(safe-area-inset-bottom));
  background: #fff;
  box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);

  .reorder-btn {
    width: 100%;
    height: 80rpx;
    background: #FFB74D;
    color: #fff;
    font-size: 30rpx;
    border-radius: 40rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;

    &::after {
      border: none;
    }
  }
}
</style> 