<template>
  <div class="crop-cd-calculator">
    <div class="header">
      <h1>籽粒移除含量计算器</h1>
      <p>评估作物镉含量及籽粒移除的影响，助力农业安全生产</p>
    </div>
    
    <div class="card-container">
      <div class="card">
        <div class="card-header">
          <i class="fas fa-leaf"></i>
          <h2>作物镉模型计算</h2>
        </div>
        
        <div class="card-body">
          <div v-if="!inputsEnabled" class="enable-section">
            <p>首次使用请点击下方按钮启用计算功能</p>
            <button class="enable-btn" @click="enableInputs">
              <i class="fas fa-calculator"></i> 启用作物镉模型计算
            </button>
          </div>
          
          <div v-if="inputsEnabled" class="input-section">
            <div class="input-group">
              <label for="yieldPerMu">
                <i class="fas fa-weight-hanging"></i> 作物亩产量 (斤)
              </label>
              <input 
                type="number" 
                id="yieldPerMu" 
                v-model.number="yieldPerMu" 
                placeholder="800"
                min="0"
              >
            </div>
            
            <div class="button-group">
              <button class="calculate-btn" @click="showStrawRemovalMessage">
                <i class="fas fa-calculator"></i> 计算籽粒移除含量
              </button>
              <button class="reset-btn" @click="resetInputs">
                <i class="fas fa-redo"></i> 重置作物镉模型计算
              </button>
            </div>
          </div>
          
          <div v-if="cropCd > 0" class="result-section">
            <div class="result-card">
              <h3>作物镉模型计算结果</h3>
              <div class="result-content">
                <div class="result-item">
                  <span>作物镉含量:</span>
                  <span class="highlight">{{ cropCd.toFixed(4) }} mg/kg</span>
                </div>
                <div class="result-item">
                  <span>国家标准限值:</span>
                  <span>0.2 mg/kg</span>
                </div>
                <div class="result-status" :class="{'safe': cropCd <= 0.2, 'warning': cropCd > 0.2}">
                  <i :class="cropCd <= 0.2 ? 'fas fa-check-circle' : 'fas fa-exclamation-triangle'"></i>
                  {{ cropCd <= 0.2 ? '符合安全标准' : '超出安全标准' }}
                </div>
              </div>
            </div>
          </div>
        </div>
        
        <div class="card-footer">
          <p>安全标准依据: GB 2762-2022 食品安全国家标准</p>
        </div>
      </div>
    </div>
    
    <div class="info-section">
      <h3><i class="fas fa-info-circle"></i> 使用说明</h3>
      <ol>
        <li>首次使用请点击"启用作物镉模型计算"按钮</li>
        <li>输入土壤镉含量、作物镉富集系数和作物亩产量</li>
        <li>点击"计算作物镉含量"按钮获取结果</li>
        <li>"重置作物镉模型计算"按钮用于重置所有输入数据</li>
      </ol>
      
      <h3><i class="fas fa-lightbulb"></i> 计算原理</h3>
      <p>作物镉含量 = 土壤镉含量 × 作物镉富集系数</p>
      <p>计算结果与国家食品安全标准(0.2 mg/kg)对比评估安全性</p>
    </div>
  </div>
</template>

<script>
export default {
  name: 'CropCdCalculator',
  data() {
    return {
      inputsEnabled: false,
      yieldPerMu: 800,
      cropCd: 0
    };
  },
  methods: {
    enableInputs() {
      this.inputsEnabled = true;
    },
    calculateCropCd() {
      // 假设土壤镉含量和作物镉富集系数默认值分别为 0.5 和 0.05
      const soilCd = 0.5;
      const enrichmentFactor = 0.05;
      // 作物镉含量计算模型
      this.cropCd = soilCd * enrichmentFactor;
    },
    resetInputs() {
      this.yieldPerMu = 800;
      this.cropCd = 0;
    },
    showStrawRemovalMessage() {
      alert("计算秸秆移除含量功能未启用");
    }
  }
};
</script>

<style scoped>
.crop-cd-calculator {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  color: #333;
  background: linear-gradient(135deg, rgba(230, 247, 255, 0.7) 0%, rgba(240, 248, 255, 0.7) 100%);
  border-radius: 15px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

.header {
  text-align: center;
  margin-bottom: 30px;
  padding: 25px;
  background: linear-gradient(135deg, rgba(38, 176, 70, 0.7) 0%, rgba(26, 122, 50, 0.7) 100%);
  border-radius: 10px;
  color: white;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.header h1 {
  font-size: 2.2rem;
  margin-bottom: 10px;
  text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.2);
}

.header p {
  font-size: 1.1rem;
  opacity: 0.9;
}

.card-container {
  margin-bottom: 30px;
}

.card {
  background: rgba(255, 255, 255, 0.9);
  border-radius: 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

.card-header {
  background: linear-gradient(135deg, rgba(52, 152, 219, 0.7) 0%, rgba(31, 111, 181, 0.7) 100%);
  color: white;
  padding: 18px 25px;
  display: flex;
  align-items: center;
  gap: 15px;
}

.card-header h2 {
  font-size: 1.6rem;
  font-weight: 600;
}

.card-header i {
  font-size: 1.8rem;
}

.card-body {
  padding: 25px;
}

.enable-section {
  text-align: center;
  padding: 30px 20px;
}

.enable-section p {
  margin-bottom: 25px;
  font-size: 1.1rem;
  color: #555;
}

.input-section {
  display: grid;
  gap: 20px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.input-group label {
  font-weight: 600;
  color: #2c3e50;
  display: flex;
  align-items: center;
  gap: 10px;
}

.input-group input {
  padding: 14px 15px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 16px;
  transition: all 0.3s;
  background: #f9fbfd;
}

.input-group input:focus {
  outline: none;
  border-color: #3498db;
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
}

.button-group {
  display: flex;
  gap: 15px;
  margin-top: 15px;
  flex-wrap: wrap;
}

button {
  padding: 14px 25px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex: 1;
  min-width: 200px;
}

.enable-btn {
  background: linear-gradient(to right, rgba(38, 176, 70, 0.7), rgba(26, 122, 50, 0.7));
  color: white;
  max-width: 350px;
  margin: 0 auto;
  box-shadow: 0 4px 10px rgba(38, 176, 70, 0.3);
}

.enable-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 15px rgba(38, 176, 70, 0.4);
}

.calculate-btn {
  background: linear-gradient(to right, rgba(52, 152, 219, 0.7), rgba(31, 111, 181, 0.7));
  color: white;
  box-shadow: 0 4px 10px rgba(52, 152, 219, 0.3);
}

.calculate-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 15px rgba(52, 152, 219, 0.4);
}

.reset-btn {
  background: linear-gradient(to right, rgba(241, 196, 15, 0.7), rgba(243, 156, 18, 0.7));
  color: white;
  box-shadow: 0 4px 10px rgba(241, 196, 15, 0.3);
}

.reset-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 15px rgba(241, 196, 15, 0.4);
}

.result-section {
  margin-top: 30px;
  border-top: 1px solid #eee;
  padding-top: 25px;
}

.result-card {
  background: rgba(249, 251, 253, 0.7);
  border-radius: 10px;
  padding: 20px;
  border-left: 4px solid #3498db;
}

.result-card h3 {
  margin-bottom: 15px;
  color: #2c3e50;
}

.result-content {
  display: grid;
  gap: 15px;
}

.result-item {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px dashed #eee;
}

.highlight {
  font-weight: 700;
  color: #e74c3c;
  font-size: 1.1rem;
}

.result-status {
  padding: 12px;
  border-radius: 8px;
  text-align: center;
  font-weight: 600;
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.result-status.safe {
  background: rgba(46, 204, 113, 0.15);
  color: #27ae60;
}

.result-status.warning {
  background: rgba(231, 76, 60, 0.15);
  color: #c0392b;
}

.card-footer {
  background: rgba(245, 247, 250, 0.7);
  padding: 15px 25px;
  text-align: center;
  color: #7f8c8d;
  font-size: 0.9rem;
  border-top: 1px solid #eee;
}

.info-section {
  background: rgba(255, 255, 255, 0.7);
  border-radius: 12px;
  padding: 25px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.info-section h3 {
  color: #2c3e50;
  margin-bottom: 15px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.info-section ol {
  padding-left: 25px;
  margin-bottom: 25px;
}

.info-section ol li {
  margin-bottom: 10px;
  line-height: 1.6;
}

.info-section p {
  line-height: 1.6;
  margin-bottom: 15px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .header {
    padding: 15px;
  }
  
  .header h1 {
    font-size: 1.8rem;
  }
  
  .card-body {
    padding: 20px;
  }
  
  .button-group {
    flex-direction: column;
  }
  
  button {
    width: 100%;
  }
}
</style>