<template>
  <div class="screen-common-component">
    <ScreenComHeader :module-id="moduleId" title="每日产量统计" />
    <div ref="chartRef" class="charts-container"></div>
  </div>
</template>

<script lang="ts" setup>
import ScreenComHeader from "@/views/screens/configs/screenComHeader.vue";
import * as echarts from "echarts";
import { dailyProduction } from "@/api/screens";
import { allChartColors } from "@/views/screens/configs/chartsConfig";

const chartRef = ref(null);

onMounted(async () => {
  const chart = echarts.init(chartRef.value, "dark");
  let res: any = await dailyProduction(7);
  const option = {
    color: allChartColors,
    backgroundColor: "transparent",
    xAxis: {
      type: "category",
      data: res?.data?.map((item: any) => item.dateStr),
    },
    yAxis: {
      type: "value",
    },
    series: [
      {
        data: res?.data?.map((item: any) => item.count),
        type: "bar",
      },
    ],
  };
  chart.setOption(option);
});

const props = defineProps({
  moduleId: {
    type: String,
    required: true,
  },
});
</script>

<style lang="scss" scoped></style>
