<template>
  <div style="flex: 1">
    <Container :name="title" icon="cockpitItemIcon" size="operatingRevenueBg" topSize="middle">
      <!-- 1. 移除 .kpi-content 的固定高度，改为自适应 -->
      <div class="kpi-content" style="padding: 14px 16px; display: flex; width: 100%;">
        <!-- 新增：topItem 专属包裹容器，统一控制样式和布局 -->
        <div class="topItem-container" style="display: flex; gap: 8px;">
          <div class="dashboard">
            <div class="title">
              累计完成率
            </div>
            <div class="number">
              <div class="yield">
                {{ formatRate(factoryData?.completeRate) }}%
              </div>
              <div class="mom">
                同比{{ formatRate(factoryData?.thb) }}%
                <img v-if="factoryData?.thb >= 0" class="arrow" src="../../../assets/img/topArrow.png" alt="上升">
                <img v-else class="arrow" src="../../../assets/img/downArrow.png" alt="下降">
              </div>
            </div>
            <div class="electricityGauge">
              <!-- 传递包含flag的factoryData给仪表盘组件 -->
              <electricityGauge id="year" :detailData="factoryData"></electricityGauge>
            </div>
          </div>
          <div class="line" style="padding: 0px;">
            <!-- 传递包含flag的factoryData给柱状图组件 -->
            <verticalBarChart :detailData="factoryData"></verticalBarChart>
          </div>
        </div>
      </div>
    </Container>
  </div>
</template>
<script>
import Container from './container.vue'
import electricityGauge from './electricityGauge.vue'
import verticalBarChart from './verticalBarChart.vue'

// import * as echarts from 'echarts'
// import rawItem from './raw-Item.vue'

export default {
  name: 'ProductionStatus',
  components: { Container, electricityGauge, verticalBarChart },
  props: {
    totalData: {
      type: Object,
      default: () => ({})
    },
    title: {
      type: String,
      default: ''
    },
    month: {
      type: String,
      default: ''
    },
  },
  data() {
    return {
      chart: null,
    }
  },
  computed: {
    /**
     * 自动提取monData中的工厂数据，并新增flag字段
     */
    factoryData() {      // 整合原始数据 + 计算flag
      return {
        completeRate: Number(this.totalData.proportion),
        diff: this.totalData.diffValue,
        real: this.totalData.value,
        target: this.totalData.targetValue,
        thb: this.totalData.thb,
        // ...rawData,
        flag: this.totalData.completed // 新增flag字段
      };
    }
  },
  methods: {
    /**
     * 格式化百分比数值：处理空值/非数字，兜底为0
     */
    formatRate(value) {
      if (isNaN(value) || value === null || value === undefined) {
        return 0;
      }
      return value;
    },
    /**
     * 判断完成率对应的flag值（<100为0，≥100为1）
     * @param {number} rate 完成率（原始值，如89代表89%）
     * @returns {0|1} flag值
     */
  }
}
</script>

<style lang='scss' scoped>
/* 3. 核心：滚动容器样式（固定高度+溢出滚动+隐藏滚动条） */
.scroll-container {
  /* 1. 固定容器高度：根据页面布局调整（示例300px，超出则滚动） */
  max-height: 210px;
  /* 2. 溢出滚动：内容超出高度时显示滚动功能 */
  overflow-y: auto;
  /* 3. 隐藏横向滚动条（防止设备名过长导致横向滚动） */
  overflow-x: hidden;
  /* 4. 内边距：与标题栏和容器边缘对齐 */
  padding: 10px 0;

  /* 5. 隐藏滚动条（兼容主流浏览器） */
  /* Chrome/Safari */
  &::-webkit-scrollbar {
    display: none;
  }

  /* Firefox */
  scrollbar-width: none;
  /* IE/Edge */
  -ms-overflow-style: none;
}

.dashboard {
  width: 264px;
  height: 205px;
  background: #F9FCFF;
  padding: 16px 0 0 10px;
  .title {
    // width: 190px;
    height: 18px;
    font-family: PingFangSC, PingFang SC;
    font-weight: 400;
    font-size: 18px;
    color: #000000;
    line-height: 18px;
    letter-spacing: 1px;
    text-align: left;
    font-style: normal;
    letter-spacing: 2px;
  }

  .number {
    display: flex;
    align-items: center;
    gap: 6px;
    // width: 190px;
    height: 32px;
    font-family: YouSheBiaoTiHei;
    font-size: 32px;
    color: #0B58FF;
    line-height: 32px;
    letter-spacing: 2px;
    text-align: left;
    font-style: normal;
    white-space: nowrap;
  }

  .mom {
    width: 120px;
    height: 18px;
    font-family: PingFangSC, PingFang SC;
    font-weight: 400;
    font-size: 18px;
    color: #000000;
    line-height: 18px;
    letter-spacing: 1px;
    text-align: left;
    font-style: normal;
    z-index: 1000;
  }
}

.line {
  width: 500px;
  height: 205px;
  background: #F9FCFF;
}

// .leftTitle {
//   .item {
//     width: 67px;
//     height: 180px;
//     padding: 37px 23px;
//     background: #F9FCFF;
//     font-family: PingFangSC, PingFang SC;
//     font-weight: 400;
//     font-size: 18px;
//     color: #000000;
//     line-height: 25px;
//     letter-spacing: 1px;
//     // text-align: left;
//     font-style: normal;
//   }
// }
</style>

<!-- <style>
/* 全局 tooltip 样式（不使用 scoped，确保生效） */
.production-status-chart-tooltip {
  background: #0a2b4f77 !important;
  border: none !important;
  backdrop-filter: blur(12px);
}

.production-status-chart-tooltip * {
  color: #fff !important;
}
</style> -->
