<template>
  <div class="lineBottom" style="height: 160px; width: 100%">
    <operatingLineBarSaleSingle :refName="'totalOperating'" :chartData="chartD" style="height: 99%; width: 100%" />
  </div>
</template>

<script>
import operatingLineBarSaleSingle from './operatingLineBarSaleSingle.vue';

export default {
  name: "Container",
  components: { operatingLineBarSaleSingle },
  props: ["detailData"],
  data() {
    return {
    };
  },
  computed: {
    locations() {
      return ['预算', '实际'];
    },
    chartD() {
      // 背景图片路径（若不需要可注释）
      // const bgImageUrl = require('@/assets/img/labelBg.png');
      const rate = this.detailData?.rate || 0
      const diff = this.detailData?.diff || 0
      console.log('diff', diff);

      const seriesData = [
        {
          value: this.detailData?.budget || 0,
          flag: 1, // 实际项：达标（绿色）
          label: {
            show: true,
            position: 'top',
            offset: [0, 0],
          },
          itemStyle: {
            color: {
              type: 'linear',
              x: 0, y: 0, x2: 0, y2: 1,
              colorStops: [
                { offset: 0, color: 'rgba(130, 204, 255, 1)' },
                { offset: 1, color: 'rgba(75, 157, 255, 1)' }
              ]
            },
            borderRadius: [4, 4, 0, 0],
            borderWidth: 0
          },
        },
        {
          value: this.detailData?.real || 0,
          flag: this.detailData?.flag, // 实际项：达标（绿色）
          label: {
            show: true,
            position: 'top',
            offset: [0, 0],
          },
          itemStyle: {
            borderRadius: [4, 4, 0, 0],
            borderWidth: 0
          },
        }
      ];

      const data = {
        allPlaceNames: ['预算', '实际'],
        series: [
          {
            type: 'bar',
            barWidth: 60,
            barCategoryGap: '50%',
            data: seriesData,
            itemStyle: {
              color: (params) => {
                const currentFlag = params.data.flag || 0;
                return currentFlag === 1
                  ? {
                    type: 'linear',
                    x: 0, y: 0, x2: 0, y2: 1,
                    colorStops: [
                      { offset: 0, color: 'rgba(174, 239, 224, 1)' },
                      { offset: 1, color: 'rgba(118, 218, 190, 1)' }
                    ]
                  }
                  : {
                    type: 'linear',
                    x: 0, y: 0, x2: 0, y2: 1,
                    colorStops: [
                      { offset: 0, color: 'rgba(253, 209, 129, 1)' },
                      { offset: 1, color: 'rgba(249, 164, 74, 1)' }
                    ]
                  };
              }
            },
          },
        ],
      };
      console.log('data', data);

      return data;
    }
  },
  methods: {},
};
</script>

<style scoped lang="scss">
.coreBar {
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 12px;

  .barTop {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 16px;
    width: 100%;

    .title {
      height: 18px;
      font-family: PingFangSC, PingFangSC;
      font-weight: 400;
      font-size: 18px;
      color: #000000;
      line-height: 18px;
      letter-spacing: 1px;
      text-align: left;
      font-style: normal;
      white-space: nowrap;
    }

    .right-container {
      display: flex;
      align-items: center;
      gap: 24px;
      margin-right: 46px;
    }

    .legend {
      display: flex;
      gap: 16px;
      align-items: center;
      margin: 0;
    }

    .legend-item {
      display: flex;
      align-items: center;
      gap: 8px;
      font-family: PingFangSC;
      font-weight: 400;
      font-size: 14px;
      color: rgba(0, 0, 0, 0.8);
      text-align: left;
      font-style: normal;
      white-space: nowrap;
    }

    .legend-icon {
      display: inline-block;
    }

    .legend-icon.line {
      width: 12px;
      height: 2px;
      position: relative;

      &::before {
        position: absolute;
        content: "";
        top: -2px;
        left: 3px;
        width: 6px;
        border-radius: 50%;
        height: 6px;
        background-color: rgba(40, 138, 255, 1);
      }
    }

    .legend-icon.square {
      width: 8px;
      height: 8px;
    }

    .yield {
      background: rgba(40, 138, 255, 1);
    }

    .target {
      background: #2889FF;
    }

    .achieved {
      background: rgba(40, 203, 151, 1);
    }

    .unachieved {
      background: rgba(255, 132, 0, 1);
    }

    .button-group {
      display: flex;
      position: relative;
      gap: 2px;
      width: 283px;
      align-items: center;
      height: 24px;
      background: #ecf4fe;
      border-radius: 12px;
      margin: 0;

      .item-button {
        cursor: pointer;
        width: 142px;
        height: 24px;
        font-family: PingFangSC;
        font-weight: 400;
        font-size: 12px;
        color: #0b58ff;
        line-height: 24px;
        text-align: center;
        font-style: normal;
        letter-spacing: 8px;
        padding-left: 8px;
      }

      .item-button.active {
        width: 142px;
        height: 24px;
        background: #3071ff;
        border-radius: 12px;
        color: #ffffff;
        font-weight: 500;
      }
    }
  }
}
</style>
