src/views/index.vue
@@ -61,13 +61,21 @@
        </section>
        <section class="section-card flex-fill-card">
          <div class="section-title-row">
            <div class="section-title">今年销售金额分析</div>
            <el-radio-group v-model="pendingFilter"
                            size="small">
              <el-radio-button label="mine">板材</el-radio-button>
              <el-radio-button label="high">砌块</el-radio-button>
            <div class="section-title">区域销售金额分析</div>
            <el-radio-group v-model="chartProductType2"
                            size="small"
                            @change="fetchSalesAmountChartData">
              <el-radio-button label="板材">板材</el-radio-button>
              <el-radio-button label="砌块">砌块</el-radio-button>
            </el-radio-group>
          </div>
          <Echarts :chartStyle="chartStyle"
                   :grid="grid"
                   :tooltip="barTooltip"
                   :xAxis="salesAmountXAxis"
                   :yAxis="salesAmountYAxis"
                   :series="salesAmountSeries"
                   style="height: 90%" />
        </section>
      </div>
      <div class="right-col">
@@ -160,37 +168,50 @@
        </section> -->
        <section class="section-card mini-table-wrap"
                 v-if="isSectionVisible('planTable')">
          <div class="section-title">生产计划执行明细</div>
          <el-table :data="planTable"
          <div class="section-title">最近报工</div>
          <el-table :data="reportingTable"
                    size="small"
                    stripe>
            <el-table-column prop="planNo"
                             label="计划单号"
                    stripe
                    :loading="reportingTableLoading">
            <el-table-column prop="productNo"
                             label="报工编号"
                             min-width="150" />
            <el-table-column prop="product"
                             label="产品"
                             min-width="120" />
            <el-table-column prop="qty"
                             label="计划量"
                             min-width="90" />
            <el-table-column prop="issued"
                             label="已下发"
                             min-width="90" />
            <el-table-column prop="status"
                             label="状态"
            <el-table-column prop="schedule"
                             label="班组"
                             min-width="80">
              <template #default="{ row }">
                <el-tag :type="row.schedule === '白班' ? 'primary' : 'warning'">{{ row.schedule || '-' }}</el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="postName"
                             label="创建人"
                             min-width="100" />
            <el-table-column label="操作"
            <el-table-column prop="createTime"
                             label="报工时间"
                             min-width="150">
              <template #default="{ row }">
                {{ row.createTime ? dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') : '' }}
              </template>
            </el-table-column>
            <el-table-column prop="productName"
                             label="产品"
                             min-width="120">
              <template #default="{ row }">
                <el-button link
                           type="primary"
                           @click="goTo(routePathMap.plan)">查看</el-button>
                <el-button v-if="row.status !== '已完成'"
                           link
                           type="success"
                           @click="goTo(routePathMap.dispatch)">
                  下发
                </el-button>
                <el-tag :type="row.productName === '砌块' ? 'primary' : 'warning'">{{ row.productName || '-' }}</el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="totalQuantity"
                             label="生产数量"
                             min-width="100">
              <template #default="{ row }">
                <span style="color:rgba(18, 148, 212, 0.8);">{{ row.totalQuantity || '-' }}</span> 方
              </template>
            </el-table-column>
            <el-table-column prop="quantity"
                             label="合格数量"
                             min-width="100">
              <template #default="{ row }">
                <span style="color:rgba(0, 228, 99, 0.8);">{{ row.quantity || '-' }}</span> 方
              </template>
            </el-table-column>
          </el-table>
@@ -272,8 +293,12 @@
    processDataProductionStatistics,
    qualityInspectionStatistics,
    nonComplianceWarning,
    getManageStatistics,
  } from "@/api/viewIndex.js";
  import { energyConsumptionDetailStatistics } from "@/api/energyManagement/energyType";
  import { getSalesAmountAnalysis } from "@/api/reportAnalysis/salesStatistics";
  import { productionReportListPage } from "@/api/productionManagement/productionReporting.js";
  import dayjs from "dayjs";
  const router = useRouter();
  const userStore = useUserStore();
@@ -456,8 +481,8 @@
    { name: "已完成订单数", value: "-" },
    { name: "未完成订单数", value: "-" },
    { name: "部分完成订单数", value: "-" },
    { name: "质检总数", value: "-" },
    { name: "过程检总数", value: "-" },
    { name: "来料检总数", value: "-" },
    // { name: "过程检总数", value: "-" },
  ]);
  const pendingTasks = reactive([]);
@@ -572,6 +597,119 @@
    },
  ]);
  // 销售金额图表
  const chartProductType2 = ref("砌块");
  const salesAmountChartData = ref({
    dates: [],
    customerTrends: [],
  });
  const salesAmountXAxis = reactive({
    type: "value",
    axisLabel: {
      interval: "auto",
      formatter: value => {
        // 格式化金额,显示为更易读的形式
        if (value >= 10000) {
          return (value / 10000).toFixed(0) + "万";
        }
        return value;
      },
    },
    axisTick: {
      interval: "auto",
    },
  });
  const salesAmountYAxis = reactive({
    type: "category",
    data: [],
    axisLabel: {
      rotate: 0,
    },
  });
  const salesAmountSeries = reactive([]);
  // 获取销售金额分析图表数据
  const fetchSalesAmountChartData = async () => {
    try {
      const response = await getSalesAmountAnalysis({
        type: chartProductType2.value,
        days: "年", // 默认年
      });
      if (response?.data) {
        salesAmountChartData.value = response.data;
        updateSalesAmountChart();
      }
    } catch (error) {
      console.error("获取销售金额分析图表数据失败:", error);
      // 使用模拟数据
      salesAmountChartData.value = {
        dates: [
          "2026-01-01",
          "2025-01-01",
          "2024-01-01",
          "2023-01-01",
          "2022-01-01",
        ],
        customerTrends: [
          { 内蒙古: 100, 银川: 200, 自提: 300, 其他: 150, 全部: 750 },
          { 内蒙古: 80, 银川: 180, 自提: 280, 其他: 130, 全部: 670 },
          { 内蒙古: 90, 银川: 190, 自提: 290, 其他: 140, 全部: 710 },
          { 内蒙古: 70, 银川: 170, 自提: 270, 其他: 120, 全部: 630 },
          { 内蒙古: 110, 银川: 210, 自提: 310, 其他: 160, 全部: 790 },
        ],
      };
      updateSalesAmountChart();
    }
  };
  // 更新销售金额图表
  const updateSalesAmountChart = () => {
    const { customerTrends = [] } = salesAmountChartData.value;
    // 计算每个销售区域的总销售额(过滤掉"全部")
    const areaTotalMap = new Map();
    customerTrends.forEach(item => {
      Object.keys(item).forEach(key => {
        // 过滤掉"全部"销售区域
        if (key !== "全部") {
          const value = item[key] || 0;
          if (areaTotalMap.has(key)) {
            areaTotalMap.set(key, areaTotalMap.get(key) + value);
          } else {
            areaTotalMap.set(key, value);
          }
        }
      });
    });
    // 转换为数组
    const salesAreas = Array.from(areaTotalMap.keys());
    const colors = [
      "#00A4ED",
      "#34D8F7",
      "#4A8BFF",
      "#8A6BFF",
      "#C8C447",
      "#FF6B6B",
    ];
    // 更新Y轴数据(现在是销售区域)
    salesAmountYAxis.data = salesAreas;
    // 更新系列数据(每个销售区域的总销售额)
    salesAmountSeries.splice(0, salesAmountSeries.length);
    salesAmountSeries.push({
      name: "销售金额",
      data: salesAreas.map(area => areaTotalMap.get(area)),
      type: "bar",
      itemStyle: { color: "#00A4ED" },
    });
  };
  // 模拟能耗数据
  const energyData = reactive({
    water: 120,
@@ -662,7 +800,33 @@
      });
  };
  const planTable = reactive([]);
  // 报工表格数据
  const reportingTable = ref([]);
  const reportingTableLoading = ref(false);
  // 获取最近报工数据
  const fetchReportingData = () => {
    reportingTableLoading.value = true;
    productionReportListPage({
      current: 1,
      size: 5, // 只显示最近5条
    })
      .then(res => {
        if (res.code === 200) {
          console.log(res.data.records || []);
          reportingTable.value = res.data.records || [];
        } else {
          reportingTable.value = [];
        }
      })
      .catch(error => {
        console.error("获取报工数据失败:", error);
        reportingTable.value = [];
      })
      .finally(() => {
        reportingTableLoading.value = false;
      });
  };
  const recentTrendCards = reactive([
    {
      key: "planIssued",
@@ -1093,6 +1257,24 @@
    //   console.error("expenseCompositionAnalysis接口获取失败:", error);
    // }
  };
  const loadManageStatistics = async () => {
    try {
      const res = await getManageStatistics();
      const data = res?.data || {};
      businessFocus[0].value = `${pickFirstNumber(data, ["total"])} 条`;
      businessFocus[1].value = `${pickFirstNumber(data, ["completed"])} 条`;
      businessFocus[2].value = `${pickFirstNumber(data, ["uncompleted"])} 条`;
      businessFocus[3].value = `${pickFirstNumber(data, [
        "partialCompleted",
      ])} 条`;
      businessFocus[4].value = `${pickFirstNumber(data, [
        "materialInspection",
      ])} 条`;
      // businessFocus[5].value = `${pickFirstNumber(data, [""])} 条`;
    } catch (error) {
      console.error("manageStatistics接口获取失败:", error);
    }
  };
  const refreshDashboardData = () => {
    // loadHomeTodos();
@@ -1101,7 +1283,10 @@
    // loadQualityData();
    // loadCostComposition();
    // loadWarningCenter();
    loadManageStatistics();
    updateEnergyTypeChart();
    fetchSalesAmountChartData();
    fetchReportingData();
    lastUpdatedAt.value = new Date().toLocaleString();
  };