已添加3个文件
已修改7个文件
3866 ■■■■■ 文件已修改
src/api/productionManagement/productProcessRoute.js 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/productionManagement/productionReporting.js 27 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/basicData/parameterMaintenance/index.vue 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/costAccounting/standardCostImport/index.vue 336 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/index.vue 2125 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/productionManagement/productionReporting/detailDialog.vue 527 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/productionManagement/productionReporting/index.vue 326 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/productionManagement/productionReporting/reportingDialog.vue 224 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/qualityManagement/rawMaterialInspection/components/detailDialog.vue 250 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/qualityManagement/rawMaterialInspection/index.vue 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/productionManagement/productProcessRoute.js
@@ -98,4 +98,12 @@
    method: "post",
    data: data,
  });
}
// ç”Ÿäº§æŠ¥å·¥-编辑
export function productionRecordEditSubmit(data) {
  return request({
    url: "/productionRecord/edit",
    method: "post",
    data: data,
  });
}
src/api/productionManagement/productionReporting.js
@@ -33,11 +33,28 @@
    data: query,
  });
}
// ç”Ÿäº§æŠ¥å·¥-删除
export function productionReportDelete(query) {
// ç”Ÿäº§æŠ¥å·¥-分页查询
export function productionReportListPage(query) {
  return request({
    url: "/productionProductMain/delete",
    method: "delete",
    data: query,
    url: "/productionProductMain/listPage",
    method: "get",
    params: query,
  });
}
// ç”Ÿäº§æŠ¥å·¥-详情
export function productionReportDetail(id) {
  return request({
    url: "/productionRecord/detail/" + id,
    method: "get",
  });
}
// ç”Ÿäº§æŠ¥å·¥-删除
export function productionReportDelete(id) {
  return request({
    url: `/productionRecord/`+id,
    method: "delete",
  });
}
src/views/basicData/parameterMaintenance/index.vue
@@ -86,6 +86,17 @@
                      prop="paramFormat">
          <el-input v-model="formData.paramFormat"
                    placeholder="请输入取值格式" />
          <!-- <el-select v-model="formData.paramFormat"
                     placeholder="请选择取值模式">
            <el-option label="#.00000"
                       value="#.00000" />
            <el-option label="#.0000"
                       value="#.0000" />
            <el-option label="#.000"
                       value="#.000" />
            <el-option label="#.00"
                       value="#.00" />
          </el-select> -->
        </el-form-item>
        <el-form-item label="下拉字典"
                      v-else-if="formData.paramType == '3'"
@@ -348,7 +359,7 @@
  // const isProductTypeEdit = ref(false);
  const handleParamTypeChange = () => {
    if (formData.paramType === "1") {
      formData.paramFormat = "#.0000";
      formData.paramFormat = "#.00000";
    } else if (formData.paramType === "4") {
      formData.paramFormat = "YYYY-MM-DD HH:mm:ss";
    } else {
@@ -497,6 +508,7 @@
      row.valueMode !== undefined ? String(row.valueMode) : "1";
    formData.unit = row.unit || "";
    formData.remark = row.remark || "";
    formData.paramFormat = row.paramFormat || "";
    dialogVisible.value = true;
  };
src/views/costAccounting/standardCostImport/index.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,336 @@
// æ ‡å‡†æˆæœ¬å¯¼å…¥
<template>
  <div class="standard-cost-ledger-page">
    <el-card shadow="never" class="query-card">
      <el-form :inline="true" :model="queryForm">
        <el-form-item label="导入月份">
          <el-date-picker
            v-model="queryForm.month"
            type="month"
            value-format="YYYY-MM"
            placeholder="选择月份"
            @change="handleQuery"
          />
        </el-form-item>
        <el-form-item label="批次号">
          <el-select
            v-model="queryForm.batchNo"
            clearable
            filterable
            placeholder="全部批次"
            style="width: 220px"
            @change="handleQuery"
          >
            <el-option
              v-for="item in batchOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleQuery">查询</el-button>
          <el-button @click="handleReset">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card shadow="never" class="ledger-card">
      <template #header>
        <div class="card-header">
          <span>标准成本导入台账</span>
          <span class="meta">共 {{ filteredLedgerRows.length }} æ¡å¯¼å…¥è®°å½•</span>
        </div>
      </template>
      <el-table
        :data="filteredLedgerRows"
        border
        highlight-current-row
        @current-change="handleLedgerRowChange"
      >
        <el-table-column prop="month" label="月份" width="120" />
        <el-table-column prop="batchNo" label="批次号" width="180" />
        <el-table-column prop="importTime" label="导入时间" min-width="180" />
        <el-table-column prop="importUser" label="导入人" width="120" />
        <el-table-column prop="remark" label="备注" min-width="220" show-overflow-tooltip />
      </el-table>
    </el-card>
    <el-card shadow="never" class="matrix-card">
      <template #header>
        <div class="card-header">
          <span>标准成本明细({{ activeLedgerRow?.month || "-" }})</span>
          <span class="meta">批次:{{ activeLedgerRow?.batchNo || "-" }}</span>
        </div>
      </template>
      <el-table :data="matrixRows" border class="matrix-table" :row-class-name="getRowClassName">
        <el-table-column prop="itemName" label="项目名称" min-width="180" />
        <el-table-column
          v-for="column in productColumns"
          :key="column.key"
          :prop="column.key"
          :label="column.label"
          min-width="130"
          align="right"
        >
          <template #default="{ row }">
            {{ formatNumber(row[column.key]) }}
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>
<script setup>
import { computed, ref } from "vue";
const getCurrentMonth = () => {
  const now = new Date();
  const year = now.getFullYear();
  const month = String(now.getMonth() + 1).padStart(2, "0");
  return `${year}-${month}`;
};
const queryForm = ref({
  month: getCurrentMonth(),
  batchNo: "",
});
const ledgerRows = ref([
  {
    id: 1,
    month: "2026-01",
    batchNo: "SC-202601-001",
    importTime: "2026-01-05 09:18:22",
    importUser: "王会计",
    remark: "月初标准成本导入",
    matrix: buildMatrixData(),
  },
  {
    id: 2,
    month: "2026-02",
    batchNo: "SC-202602-001",
    importTime: "2026-02-03 10:08:16",
    importUser: "李会计",
    remark: "按产品更新人工与费用口径",
    matrix: buildMatrixData({
      yieldA35: 1050,
      yieldA50: 920,
      yieldBoard: 840,
      directMaterialA35: 12.4,
      directMaterialA50: 11.9,
      directMaterialBoard: 9.2,
    }),
  },
  {
    id: 3,
    month: "2026-03",
    batchNo: "SC-202603-001",
    importTime: "2026-03-04 14:32:09",
    importUser: "王会计",
    remark: "按月导入标准成本",
    matrix: buildMatrixData({
      yieldA35: 1100,
      yieldA50: 960,
      yieldBoard: 900,
      directMaterialA35: 12.9,
      directMaterialA50: 12.1,
      directMaterialBoard: 9.6,
    }),
  },
]);
const activeLedgerId = ref(ledgerRows.value[0]?.id || null);
const batchOptions = computed(() => {
  return ledgerRows.value.map((row) => ({
    label: `${row.batchNo}(${row.month})`,
    value: row.batchNo,
  }));
});
const filteredLedgerRows = computed(() => {
  return ledgerRows.value.filter((row) => {
    const byMonth = !queryForm.value.month || row.month === queryForm.value.month;
    const byBatch = !queryForm.value.batchNo || row.batchNo === queryForm.value.batchNo;
    return byMonth && byBatch;
  });
});
const activeLedgerRow = computed(() => {
  const list = filteredLedgerRows.value;
  const target = list.find((row) => row.id === activeLedgerId.value);
  return target || list[0] || null;
});
const matrixRows = computed(() => activeLedgerRow.value?.matrix || []);
const productColumns = [
  { key: "a35", label: "加气块-A3.5" },
  { key: "a50", label: "加气块-A5.0" },
  { key: "board", label: "板材" },
  { key: "total", label: "综合" },
];
function buildMatrixData(override = {}) {
  const yieldA35 = override.yieldA35 ?? 980;
  const yieldA50 = override.yieldA50 ?? 860;
  const yieldBoard = override.yieldBoard ?? 800;
  const directMaterialA35 = override.directMaterialA35 ?? 12.6;
  const directMaterialA50 = override.directMaterialA50 ?? 11.7;
  const directMaterialBoard = override.directMaterialBoard ?? 9.1;
  const manufacturingA35 = 3.2;
  const manufacturingA50 = 3.5;
  const manufacturingBoard = 2.8;
  const mgmtA35 = 1.4;
  const mgmtA50 = 1.2;
  const mgmtBoard = 1.0;
  const salesA35 = 0.9;
  const salesA50 = 0.8;
  const salesBoard = 0.7;
  const financeA35 = 0.4;
  const financeA50 = 0.3;
  const financeBoard = 0.2;
  const offSeasonA35 = 1.1;
  const offSeasonA50 = 1.0;
  const offSeasonBoard = 0.8;
  const subtotalA35 = directMaterialA35 + manufacturingA35;
  const subtotalA50 = directMaterialA50 + manufacturingA50;
  const subtotalBoard = directMaterialBoard + manufacturingBoard;
  const totalA35 = subtotalA35 + mgmtA35 + salesA35 + financeA35 + offSeasonA35;
  const totalA50 = subtotalA50 + mgmtA50 + salesA50 + financeA50 + offSeasonA50;
  const totalBoard = subtotalBoard + mgmtBoard + salesBoard + financeBoard + offSeasonBoard;
  return [
    {
      itemName: "产量",
      a35: yieldA35,
      a50: yieldA50,
      board: yieldBoard,
      total: yieldA35 + yieldA50 + yieldBoard,
    },
    {
      itemName: "直接材料单方成本",
      a35: directMaterialA35,
      a50: directMaterialA50,
      board: directMaterialBoard,
      total: (directMaterialA35 + directMaterialA50 + directMaterialBoard) / 3,
    },
    {
      itemName: "制造费用",
      a35: manufacturingA35,
      a50: manufacturingA50,
      board: manufacturingBoard,
      total: (manufacturingA35 + manufacturingA50 + manufacturingBoard) / 3,
    },
    {
      itemName: "生产成本小计",
      a35: subtotalA35,
      a50: subtotalA50,
      board: subtotalBoard,
      total: (subtotalA35 + subtotalA50 + subtotalBoard) / 3,
      isSubtotal: true,
    },
    {
      itemName: "管理费用",
      a35: mgmtA35,
      a50: mgmtA50,
      board: mgmtBoard,
      total: (mgmtA35 + mgmtA50 + mgmtBoard) / 3,
    },
    {
      itemName: "销售费用",
      a35: salesA35,
      a50: salesA50,
      board: salesBoard,
      total: (salesA35 + salesA50 + salesBoard) / 3,
    },
    {
      itemName: "财务费用",
      a35: financeA35,
      a50: financeA50,
      board: financeBoard,
      total: (financeA35 + financeA50 + financeBoard) / 3,
    },
    {
      itemName: "淡季费用-生产成本",
      a35: offSeasonA35,
      a50: offSeasonA50,
      board: offSeasonBoard,
      total: (offSeasonA35 + offSeasonA50 + offSeasonBoard) / 3,
    },
    {
      itemName: "合计",
      a35: totalA35,
      a50: totalA50,
      board: totalBoard,
      total: (totalA35 + totalA50 + totalBoard) / 3,
    },
  ];
}
function handleQuery() {
  if (filteredLedgerRows.value.length > 0) {
    activeLedgerId.value = filteredLedgerRows.value[0].id;
    return;
  }
  activeLedgerId.value = null;
}
function handleReset() {
  queryForm.value.month = getCurrentMonth();
  queryForm.value.batchNo = "";
  handleQuery();
}
function handleLedgerRowChange(row) {
  if (!row) return;
  activeLedgerId.value = row.id;
}
function getRowClassName({ row }) {
  return row.isSubtotal ? "is-subtotal-row" : "";
}
function formatNumber(value) {
  if (typeof value !== "number") return "-";
  if (Number.isInteger(value)) return value.toLocaleString("zh-CN");
  return value.toLocaleString("zh-CN", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
}
</script>
<style scoped>
.standard-cost-ledger-page {
  padding: 16px;
  background: #f6f8fa;
  min-height: calc(100vh - 100px);
}
.query-card,
.ledger-card,
.matrix-card {
  margin-bottom: 16px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 16px;
  font-weight: 600;
}
.meta {
  font-size: 13px;
  color: #909399;
  font-weight: 400;
}
.matrix-table :deep(.is-subtotal-row td) {
  background: #fff200 !important;
}
</style>
src/views/index.vue
@@ -1,1263 +1,1124 @@
<template>
  <div class="dashboard">
    <!-- é¡¶éƒ¨æ¨ªå‘两栏 -->
    <div class="dashboard-top">
      <!-- å·¦ï¼šä¼ä¸šä¿¡æ¯+三大数据卡片(上下排列) -->
      <div class="top-left">
        <div class="company-info">
          <!-- é¡¶éƒ¨é—®å€™æ¡ -->
          <div class="welcome-banner">
            <div class="welcome-title">
              <span class="welcome-user">{{ userStore.roleName || '系统管理员' }}</span>
              <span> æ‚¨å¥½ï¼ç¥æ‚¨å¼€å¿ƒæ¯ä¸€å¤©</span>
            </div>
            <div class="welcome-time">登录于: {{ userStore.currentLoginTime }}</div>
          </div>
          <!-- ç”¨æˆ·ä¿¡æ¯å¡ç‰‡ -->
          <div class="user-card">
            <img :src="userStore.avatar" class="avatar" alt="" />
            <div class="user-card-main">
              <div class="user-name">{{ userStore.name }}</div>
              <div class="user-role">{{ userStore.roleName }}</div>
              <div class="user-meta">
                <span>{{ userStore.phoneNumber || '123456789' }}</span>
                <span class="sep">|</span>
                <span>{{ userStore.deptName || '组织架构' }}</span>
                <span class="sep">|</span>
                <span>{{ userStore.postName || '岗位名' }}</span>
              </div>
            </div>
          </div>
  <div class="home-page">
    <div class="top-bar">
      <div class="user-box">
        <img :src="userStore.avatar" class="avatar" alt="" />
        <div>
          <div class="hello">{{ userStore.roleName || "系统管理员" }},你好</div>
          <div class="sub">登录时间:{{ userStore.currentLoginTime }}</div>
        </div>
      </div>
      <div class="data-cards">
        <div class="data-card sales">
          <div class="data-title">销售数据</div>
          <div class="data-num">
            <div>
              <div class="data-desc">本月销售额/元</div>
              <div class="data-value">{{ businessInfo.monthSaleMoney }}</div>
            </div>
            <div>
              <div class="data-desc">未开票金额/元</div>
              <div class="data-value">{{ businessInfo.monthSaleHaveMoney }}</div>
            </div>
          </div>
        </div>
        <div class="data-card purchase">
          <div class="data-title">采购数据</div>
          <div class="data-num">
            <div>
              <div class="data-desc">本月采购额/元</div>
              <div class="data-value">{{ businessInfo.monthPurchaseMoney }}</div>
            </div>
            <div>
              <div class="data-desc">待付款金额/元</div>
              <div class="data-value">{{ businessInfo.monthPurchaseHaveMoney }}</div>
            </div>
          </div>
        </div>
        <div class="data-card inventory">
          <div class="data-title">库存数据</div>
          <div class="data-num">
            <div>
              <div class="data-desc">当前库存总量/ä»¶</div>
              <div class="data-value">{{ businessInfo.inventoryNum }}</div>
            </div>
            <div>
              <div class="data-desc">今日入库/ä»¶</div>
              <div class="data-value">{{ businessInfo.todayInventoryNum }}</div>
            </div>
          </div>
        </div>
      </div>
      <!-- å³ï¼šå¾…办事项 -->
      <div class="todo-panel">
        <div class="section-title">待办事项</div>
        <ul class="todo-list" v-if="todoList.length > 0">
          <li v-for="item in todoList" :key="item.id">
            <div style="display: flex;flex-direction: column;justify-content: space-between;width: 100%;gap: 20px">
              <div style="display: flex;justify-content: space-between;align-items: center;">
                <div class="todo-title">待办编号:{{ item.approveId }}</div>
                <div class="todo-division">部门:{{ item.approveDeptName }}</div>
                <div class="todo-time">{{ item.approveTime }}</div>
              </div>
              <div class="todo-division">待办事由:{{ item.approveReason }}</div>
            </div>
          </li>
        </ul>
        <div v-else style="text-align: center">
          æš‚无数据
        </div>
      <div class="top-actions">
        <span class="refresh-time">数据更新时间:{{ lastUpdatedAt || "-" }}</span>
        <el-button size="small" type="primary" plain @click="refreshDashboardData">刷新数据</el-button>
        <el-button size="small" plain @click="configDialogVisible = true">首页配置</el-button>
      </div>
    </div>
    <div class="dashboard-row">
      <div class="main-panel process-panel">
        <div class="process-panel__header">
          <div class="section-title">工序数据生产统计明细</div>
          <div style="display: flex; gap: 10px; align-items: center;">
            <el-button type="primary" size="small" plain icon="Filter" @click="openProcessDialog">选择工序</el-button>
            <el-button type="info" size="small" plain icon="Refresh" @click="resetProcessFilter">重置</el-button>
            <el-radio-group v-model="processRange" size="small" @change="refreshProcessStats">
              <el-radio-button :value="1">日</el-radio-button>
              <el-radio-button :value="2">周</el-radio-button>
              <el-radio-button :value="3">月</el-radio-button>
    <div class="content-grid">
      <div class="left-col">
        <section class="section-card">
          <div class="section-title-row">
            <div class="section-title">快捷操作</div>
            <el-button size="small" type="primary" link @click="openShortcutDialog">添加快捷入口</el-button>
          </div>
          <div class="quick-grid">
            <el-button
              v-for="item in shortcuts"
              :key="`${item.label}-${item.path}`"
              :type="item.invalid ? 'danger' : 'default'"
              @click="goTo(item.path)"
            >
              {{ item.label }}
            </el-button>
          </div>
        </section>
        <section class="section-card">
          <div class="section-title">重点待办</div>
          <div class="todo-row" v-for="todo in todos" :key="todo.title">
            <el-tag size="small" :type="todo.type">{{ todo.level }}</el-tag>
            <span>{{ todo.title }}</span>
          </div>
        </section>
        <section class="section-card">
          <div class="section-title">经营关注</div>
          <div class="focus-row" v-for="item in businessFocus" :key="item.name">
            <span class="focus-name">{{ item.name }}</span>
            <span class="focus-value">{{ item.value }}</span>
          </div>
        </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="all">全部</el-radio-button>
              <el-radio-button label="mine">我的</el-radio-button>
              <el-radio-button label="high">高优先</el-radio-button>
            </el-radio-group>
          </div>
        </div>
        <div class="process-panel__body">
          <div class="process-panel__chart">
            <Echarts :chartStyle="{ width: '100%', height: '100%' }" :grid="processGrid" :series="processSeries"
              :tooltip="processTooltip" :xAxis="processXAxis" :yAxis="processYAxis" style="height: 100%"
              @click="handleChartClick" />
          <div class="task-row" v-for="task in filteredPendingTasks" :key="task.id">
            <div class="task-left">
              <el-tag size="small" :type="task.type">{{ task.level }}</el-tag>
              <span class="task-title">{{ task.title }}</span>
            </div>
            <el-button link type="primary" @click="goTo(task.path)">去处理</el-button>
          </div>
          <el-empty v-if="filteredPendingTasks.length === 0" description="暂无待处理事项" :image-size="80" />
        </section>
      </div>
          <div class="process-panel__aside">
            <div class="process-legend">
              <div class="process-legend__item">
                <span class="dot dot-blue"></span><span>投入量</span>
      <div class="right-col">
        <section class="section-card" v-if="isSectionVisible('trendCards')">
          <div class="section-title">最近7天关键指标趋势</div>
          <div class="trend-cards">
            <div class="trend-card clickable" v-for="card in recentTrendCards" :key="card.key" @click="handleTrendCardClick(card)">
              <div class="trend-head">
                <span class="trend-label">{{ card.label }}</span>
                <span class="trend-rate" :class="trendClass(card.change)">
                  {{ card.change > 0 ? "+" : "" }}{{ card.change.toFixed(1) }}%
                </span>
              </div>
              <div class="process-legend__item">
                <span class="dot dot-yellow"></span><span>报废量</span>
              </div>
              <div class="process-legend__item">
                <span class="dot dot-teal"></span><span>产出量</span>
              </div>
            </div>
            <div class="process-card process-card--name">{{ processAside.processName }}</div>
            <div class="process-card">
              <div class="process-card__label">累计总投入</div>
              <div class="process-card__value">{{ formatAmount(processAside.totalInput) }}
              </div>
            </div>
            <div class="process-card">
              <div class="process-card__label">累计总报废</div>
              <div class="process-card__value">{{ formatAmount(processAside.totalScrap) }}
              </div>
            </div>
            <div class="process-card">
              <div class="process-card__label">累计总产出</div>
              <div class="process-card__value">{{ formatAmount(processAside.totalOutput) }}
              <div class="trend-value">{{ card.latest }} {{ card.unit }}</div>
              <div class="sparkline">
                <span
                  v-for="(v, idx) in card.values"
                  :key="`${card.key}-${idx}`"
                  class="sparkline-bar"
                  :style="{ height: `${calcBarHeight(v, card.values)}%` }"
                />
              </div>
            </div>
          </div>
        </section>
        <section class="section-card" v-if="isSectionVisible('planTrend')">
          <div class="section-title-row">
            <div class="section-title">计划与生产趋势</div>
            <el-radio-group v-model="chartRangePlan" size="small" @change="loadPlanTrend">
              <el-radio-button :label="1">日</el-radio-button>
              <el-radio-button :label="2">周</el-radio-button>
              <el-radio-button :label="3">月</el-radio-button>
            </el-radio-group>
          </div>
          <Echarts
            :chartStyle="chartStyle"
            :legend="planLegend"
            :grid="grid"
            :tooltip="lineTooltip"
            :xAxis="planXAxis"
            :yAxis="valueYAxis"
            :series="planSeries"
            style="height: 300px"
          />
        </section>
        <div class="row-two" v-if="isSectionVisible('qualityChart') || isSectionVisible('costChart')">
          <section class="section-card" v-if="isSectionVisible('qualityChart')">
            <div class="section-title-row">
              <div class="section-title">质检异常分布</div>
              <el-radio-group v-model="chartRangeQuality" size="small" @change="loadQualityData">
                <el-radio-button :label="1">周</el-radio-button>
                <el-radio-button :label="2">月</el-radio-button>
                <el-radio-button :label="3">季度</el-radio-button>
              </el-radio-group>
            </div>
            <Echarts
              :chartStyle="chartStyle"
              :grid="grid"
              :tooltip="barTooltip"
              :xAxis="qualityXAxis"
              :yAxis="valueYAxis"
              :series="qualitySeries"
              style="height: 260px"
            />
          </section>
          <section class="section-card" v-if="isSectionVisible('costChart')">
            <div class="section-title">能耗与成本结构</div>
            <Echarts
              :chartStyle="chartStyle"
              :legend="costLegend"
              :tooltip="pieTooltip"
              :series="costSeries"
              style="height: 260px"
            />
          </section>
        </div>
        <section class="section-card" v-if="isSectionVisible('warningCenter')">
          <div class="section-title">异常预警中心</div>
          <div class="warning-row" v-for="item in warningList" :key="item.id">
            <div class="warning-left">
              <el-tag size="small" :type="item.levelType">{{ item.levelText }}</el-tag>
              <span class="warning-title">{{ item.title }}</span>
            </div>
            <el-button link type="danger" @click="goTo(item.path)">处理</el-button>
          </div>
          <el-empty v-if="warningList.length === 0" description="暂无异常预警" :image-size="80" />
        </section>
        <section class="section-card mini-table-wrap" v-if="isSectionVisible('planTable')">
          <div class="section-title">生产计划执行明细</div>
          <el-table :data="planTable" size="small" stripe>
            <el-table-column prop="planNo" 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="状态" min-width="100" />
            <el-table-column 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>
              </template>
            </el-table-column>
          </el-table>
        </section>
      </div>
    </div>
    <!-- å·¥åºé€‰æ‹©å¼¹çª— -->
    <el-dialog v-model="processDialogVisible" title="选择工序" width="500px" append-to-body>
      <div class="process-selection-wrapper">
        <el-checkbox-group v-model="tempProcessIds">
          <div class="process-grid">
            <el-checkbox v-for="item in processOptions" :key="item.id" :label="item.id" border>
              {{ item.name }}
            </el-checkbox>
          </div>
        </el-checkbox-group>
    <el-dialog v-model="shortcutDialogVisible" title="添加快捷入口(最多6个)" width="680px">
      <div class="shortcut-form-row">
        <el-tree-select
          v-model="selectedPagePath"
          placeholder="请选择页面(目录不可选)"
          filterable
          clearable
          check-strictly
          node-key="value"
          :data="menuTreeOptions"
          :props="{ label: 'label', value: 'value', children: 'children', disabled: 'disabled' }"
          style="grid-column: span 2"
        />
        <el-button type="success" @click="addShortcutBySelect">选择添加</el-button>
      </div>
      <el-table :data="shortcuts" size="small" border>
        <el-table-column prop="label" label="名称" min-width="220" />
        <el-table-column label="状态" min-width="80">
          <template #default="{ row }">
            <el-tag size="small" :type="row.invalid ? 'danger' : 'success'">{{ row.invalid ? "无效" : "有效" }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" min-width="90" align="center">
          <template #default="{ $index }">
            <el-button link type="danger" @click="removeShortcut($index)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <el-dialog v-model="configDialogVisible" title="首页模块配置" width="520px">
      <el-checkbox-group v-model="enabledSectionKeys" class="config-check-group">
        <el-checkbox v-for="item in sectionConfigOptions" :key="item.key" :label="item.key">
          {{ item.label }}
        </el-checkbox>
      </el-checkbox-group>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="processDialogVisible = false">取消</el-button>
          <el-button type="primary" @click="handleProcessDialogConfirm">确认</el-button>
        </span>
        <el-button @click="configDialogVisible = false">取消</el-button>
        <el-button type="primary" @click="saveSectionConfig">保存</el-button>
      </template>
    </el-dialog>
    <!-- ä¸­éƒ¨æ¨ªå‘两栏 -->
    <div class="dashboard-row">
      <div class="main-panel">
        <div class="section-title">客户合同金额分析</div>
        <div class="contract-summary">
          <div class="contract-info">
            <img src="../assets/images/khtitle.png" alt="" style="width: 42px" />
            <div class="contract-card">
              <div class="contract-name">总合同金额(元)</div>
              <div class="contract-meta">
                <div class="main-amount">{{ sum }}</div>
                <div>周同比: <span class="up">{{ yny }}% </span> æ—¥çŽ¯æ¯”: <span class="up">{{ chain }}% </span></div>
              </div>
            </div>
          </div>
        </div>
        <div
          style="display: flex;align-items: center;gap: 20px;justify-content: space-evenly;height: 180px;margin-top: 20px">
          <div>
            <Echarts ref="chart" :legend="pieLegend" :chartStyle="chartStylePie" :series="materialPieSeries"
              :tooltip="pieTooltip"></Echarts>
          </div>
          <ul class="contract-list">
            <li v-for="item in materialPieSeries[0].data" :key="item.name">
              <div style="display: flex;align-items: center;justify-content: space-between;width: 100%">
                <div class="line" :style="{ color: item.itemStyle.color }">●{{ item.name }}</div>
                <div style="width: 70px">{{ item.rate }}%</div>
                <div>ï¿¥{{ item.value }}</div>
              </div>
            </li>
          </ul>
        </div>
      </div>
      <div class="main-panel">
        <div style="display: flex;justify-content: space-between;">
          <div class="section-title">应收应付统计</div>
          <!--                    <el-radio-group v-model="radio1" size="large" @change="statisticsReceivable">-->
          <!--                        <el-radio-button label="按周" :value="1" />-->
          <!--                        <el-radio-button label="按月" :value="2" />-->
          <!--                        <el-radio-button label="按季度" :value="3" />-->
          <!--                    </el-radio-group>-->
        </div>
        <Echarts ref="chart" :color="barColors2" :chartStyle="chartStyle" :grid="grid" :series="barSeries"
          :tooltip="tooltip" :xAxis="xAxis" :yAxis="yAxis" style="height: 260px"></Echarts>
      </div>
    </div>
    <!-- åº•部横向两栏 -->
    <div class="dashboard-row">
      <div class="main-panel">
        <div style="display: flex;justify-content: space-between;align-items: center;margin-bottom: 10px;">
          <div class="section-title" style="margin-bottom: 0;">质量统计</div>
          <el-radio-group v-model="qualityRange" size="small" @change="qualityStatisticsInfo">
            <el-radio-button :value="1">周</el-radio-button>
            <el-radio-button :value="2">月</el-radio-button>
            <el-radio-button :value="3">季度</el-radio-button>
          </el-radio-group>
        </div>
        <div class="quality-cards">
          <div class="quality-card one">原材料已检测数 <span>{{ qualityStatisticsObject.supplierNum }}ä»¶</span></div>
          <div class="quality-card two">过程检验数量 <span>{{ qualityStatisticsObject.processNum }}ä»¶</span></div>
          <div class="quality-card three">出厂已检数量 <span>{{ qualityStatisticsObject.factoryNum }}ä»¶</span></div>
        </div>
        <Echarts ref="chart" :chartStyle="chartStyle" :grid="grid" :legend="barLegend" :series="barSeries1"
          :tooltip="tooltip" :xAxis="xAxis1" :yAxis="yAxis1" style="height: 260px"></Echarts>
      </div>
      <div class="main-panel">
        <div class="section-title">回款与开票分析</div>
        <Echarts ref="invoiceChart" :chartStyle="chartStyle" :grid="grid" :legend="lineLegend" :series="lineSeries"
          :tooltip="tooltipLine" :xAxis="xAxis2" :yAxis="yAxis2" style="height: 270px;" />
      </div>
    </div>
  </div>
</template>
<script setup>
import { ref, onMounted, computed, reactive } from 'vue'
import { computed, onMounted, reactive, ref } from "vue";
import { useRouter } from "vue-router";
import { ElMessage } from "element-plus";
import Echarts from "@/components/Echarts/echarts.vue";
import * as echarts from 'echarts';
import useUserStore from "@/store/modules/user.js";
import usePermissionStore from "@/store/modules/permission";
import {
  analysisCustomerContractAmounts, getAmountHalfYear,
  getBusiness,
  expenseCompositionAnalysis,
  getProgressStatistics,
  homeTodos,
  orderCount,
  processDataProductionStatistics,
  statisticsReceivablePayable,
  qualityInspectionStatistics
  qualityInspectionStatistics,
  nonComplianceWarning,
} from "@/api/viewIndex.js";
import { list } from '@/api/productionManagement/productionProcess';
const router = useRouter();
const userStore = useUserStore();
const permissionStore = usePermissionStore();
const userStore = useUserStore()
const SHORTCUT_STORAGE_KEY = "home-shortcuts-v1";
const processOptions = ref([])
const selectedProcessIds = ref([])
const tempProcessIds = ref([])
const processDialogVisible = ref(false)
const activeProcessIndex = ref(0)
const defaultShortcuts = [
  { label: "主生产计划", path: "/productionManagement/productionPlan" },
  { label: "生产订单", path: "/productionManagement/productionOrder" },
  { label: "生产报工", path: "/productionManagement/productionReporting" },
  { label: "过程检", path: "/qualityManagement/processInspection" },
  { label: "生产能耗", path: "/energyManagement/productionEnergyConsumption" },
  { label: "生产成本", path: "/costAccounting/productionCostAccounting" },
  { label: "标准vs实际", path: "/costAccounting/stdVsActCostAnalysis" },
  { label: "决策分析", path: "/reportAnalysis/dataDashboard" },
];
const businessInfo = ref({
  inventoryNum: 0,
  monthPurchaseHaveMoney: 0,
  monthPurchaseMoney: 0,
  monthSaleHaveMoney: 0,
  monthSaleMoney: 0,
  todayInventoryNum: 0,
})
const qualityStatisticsObject = ref({
  supplierNum: 0,
  processNum: 0,
  factoryNum: 0,
})
const sum = ref(0)
const yny = ref(0)
const chain = ref(0)
const isRouteValid = (path) => {
  if (!path || !path.startsWith("/")) return false;
  const resolved = router.resolve(path);
  return resolved.matched && resolved.matched.length > 0;
};
const pieLegend = reactive({
  show: false,
})
const barSeries = ref([
  {
    type: 'bar',
    data: [],
    label: {
      show: true,
const withValidFlag = (list) =>
  list.map((item) => ({
    ...item,
    invalid: !isRouteValid(item.path),
  }));
const pageOptions = router
  .getRoutes()
  .filter((route) => {
    const hasTitle = Boolean(route.meta?.title);
    const validPath = route.path && route.path.startsWith("/") && !route.path.includes(":");
    const isVisibleMenu = !route.meta?.hidden && route.path !== "/index";
    const notSpecial =
      !route.path.includes("redirect") &&
      route.path !== "/login" &&
      route.path !== "/register" &&
      route.path !== "/401" &&
      !route.path.includes(":pathMatch");
    return hasTitle && validPath && isVisibleMenu && notSpecial;
  })
  .map((route) => ({
    title: route.meta.title,
    path: route.path,
  }))
  .sort((a, b) => a.path.localeCompare(b.path));
const normalizePath = (path) => String(path || "").replace(/\/+/g, "/");
const joinPath = (parentPath, childPath) => {
  if (!childPath) return normalizePath(parentPath || "/");
  if (String(childPath).startsWith("/")) return normalizePath(childPath);
  return normalizePath(`${parentPath || ""}/${childPath}`);
};
const buildMenuTreeOptions = (routes = [], parentPath = "") => {
  const result = [];
  routes.forEach((route) => {
    if (!route || route.hidden) return;
    const fullPath = joinPath(parentPath, route.path);
    const children = buildMenuTreeOptions(route.children || [], fullPath);
    const title = route.meta?.title;
    if (!title && children.length > 0) {
      result.push(...children);
      return;
    }
  },
])
    if (!title) return;
    result.push({
      label: title,
      value: fullPath,
      disabled: children.length > 0,
      children,
    });
  });
  return result;
};
const barSeries1 = ref([
  {
    name: '原材料不合格数',
    type: 'bar',
    barGap: 0,
    emphasis: {
      focus: 'series'
    },
    data: []
  },
  {
    name: '过程不合格数',
    type: 'bar',
    emphasis: {
      focus: 'series'
    },
    data: []
  },
  {
    name: '出厂不合格数',
    type: 'bar',
    emphasis: {
      focus: 'series'
    },
    data: []
  },
])
const chartStyle = {
  width: '100%',
  height: '100%' // è®¾ç½®å›¾è¡¨å®¹å™¨çš„高度
}
const chartStylePie = {
  width: '140%',
  height: '140%' // è®¾ç½®å›¾è¡¨å®¹å™¨çš„高度
}
const grid = {
  left: '3%',
  right: '4%',
  bottom: '3%',
  containLabel: true
}
const barLegend = {
  show: true,
  data: ['原材料不合格数', '过程不合格数', '出厂不合格数']
}
const barLegend1 = {
  show: true,
  data: ['预付账款', '应付账款', '预收账款', '应收账款']
}
const lineLegend = {
  show: true,
  data: ['开票', '回款']
}
const tooltip = {
  trigger: 'axis',
  axisPointer: {
    type: 'shadow'
  }
}
const xAxis = [{
  type: 'value',
}]
const xAxis1 = ref([{
  type: 'category',
  axisTick: { show: false },
  data: []
}])
const yAxis = [{
  type: 'category',
  data: ['应付账款', '应收账款',]
}]
const yAxis1 = [{
  type: 'value'
}]
const pieTooltip = reactive({
  trigger: 'item',
  formatter: function (params) {
    // åŠ¨æ€ç”Ÿæˆæç¤ºä¿¡æ¯ï¼ŒåŸºäºŽæ•°æ®é¡¹çš„ name å±žæ€§
    const description = params.name === '本月回款金额' ? '本月回款金额' : '应收款金额';
    return `${description} ${formatNumber(params.value)}元 ${params.percent}%`;
  },
  position: 'right'
})
const materialPieSeries = ref([
  {
    type: 'pie',
    radius: ['66%', '90%'],
    avoidLabelOverlap: false,
    itemStyle: {
      borderColor: '#fff',
      borderWidth: 2
    },
    label: {
      show: false
    },
    data: []
  }
])
const lineSeries = ref([
  {
    type: 'line',
    data: [],
    label: {
      show: true
    },
    showSymbol: true, // æ˜¾ç¤ºåœ†ç‚¹
  },
])
const tooltipLine = {
  trigger: 'axis',
}
const yAxis2 = ref([
  {
    type: 'value',
  }
])
const xAxis2 = ref([
  {
    type: 'category',
    data: [],
    axisLabel: {
      interval: 0,
      formatter: function (value) {
        return value.replace(/~/g, '\n');
      },
    }
  }
])
const menuTreeOptions = computed(() => buildMenuTreeOptions(permissionStore.sidebarRouters || []));
const selectableMenuMap = computed(() => {
  const map = new Map();
  const walk = (list = []) => {
    list.forEach((item) => {
      if (!item.disabled) map.set(item.value, item.label);
      if (item.children?.length) walk(item.children);
    });
  };
  walk(menuTreeOptions.value);
  return map;
});
// å¾…办事项
const todoList = ref([])
const radio1 = ref(1)
const qualityRange = ref(1)
const keywordMap = {
  "主生产计划": ["生产计划", "productionPlan"],
  "生产订单": ["生产订单", "productionOrder"],
  "生产报工": ["报工", "productionReporting"],
  "过程检": ["过程检", "processInspection"],
  "生产能耗": ["生产能耗", "productionEnergyConsumption"],
  "生产成本": ["生产成本", "productionCostAccounting"],
  "标准vs实际": ["标准", "实际", "stdVsActCostAnalysis"],
  "决策分析": ["决策", "看板", "dataDashboard"],
};
// å›¾è¡¨å¼•用
const barChart = ref(null)
const lineChart = ref(null)
const barColors2 = ['#5181DB', '#D369E0', '#F2CA6D', '#60CCA8']
const findRouteByKeywords = (keywords = []) => {
  const lowerKeywords = keywords.map((k) => String(k).toLowerCase());
  return pageOptions.find((item) => {
    const title = String(item.title || "").toLowerCase();
    const path = String(item.path || "").toLowerCase();
    return lowerKeywords.some((k) => title.includes(k) || path.includes(k));
  });
};
// éšæœºé¢œè‰²ç”Ÿæˆå‡½æ•°
const getRandomColor = () => {
  return '#' + Math.floor(Math.random() * 0xffffff).toString(16).padStart(6, '0');
}
const getPathByKeywords = (keywords = []) => findRouteByKeywords(keywords)?.path || "";
onMounted(() => {
  getBusinessData()
  analysisCustomer()
  todoInfoS()
  statisticsReceivable()
  qualityStatisticsInfo()
  getAmountHalfYearNum()
  getProcessList()
})
// æ•°æ®ç»Ÿè®¡
const getBusinessData = () => {
  getBusiness().then((res) => {
    businessInfo.value = { ...res.data }
  })
}
// åˆåŒé‡‘额
const analysisCustomer = () => {
  analysisCustomerContractAmounts().then((res) => {
    sum.value = res.data.sum
    yny.value = res.data.yny
    chain.value = res.data.chain
    // ä¸ºæ¯ä¸ªæ•°æ®é¡¹åˆ†é…éšæœºé¢œè‰²
    materialPieSeries.value[0].data = res.data.item.map(item => ({
      ...item,
      itemStyle: { color: getRandomColor() }
    }))
  })
}
// å¾…办事项
const todoInfoS = () => {
  homeTodos().then((res) => {
    todoList.value = res.data
  })
}
// èŽ·å–å·¥åºåˆ—è¡¨
const getProcessList = () => {
  list().then(res => {
    processOptions.value = res.data
  })
}
const openProcessDialog = () => {
  tempProcessIds.value = [...selectedProcessIds.value]
  processDialogVisible.value = true
}
const handleProcessDialogConfirm = () => {
  selectedProcessIds.value = [...tempProcessIds.value]
  processDialogVisible.value = false
  refreshProcessStats()
}
const resetProcessFilter = () => {
  selectedProcessIds.value = []
  tempProcessIds.value = []
  refreshProcessStats()
}
const handleChartClick = (params) => {
  if (params && params.dataIndex !== undefined) {
    activeProcessIndex.value = params.dataIndex
  }
}
// åº”付应收统计
const statisticsReceivable = () => {
  statisticsReceivablePayable({ type: radio1.value }).then((res) => {
    barSeries.value[0].data = [
      // { value: res.data.prepayMoney, itemStyle: { color: barColors2[0] } },
      { value: res.data.payableMoney, itemStyle: { color: barColors2[0] } },
      // { value: res.data.advanceMoney, itemStyle: { color: barColors2[2] } },
      { value: res.data.receivableMoney, itemStyle: { color: barColors2[1] } }
    ]
  })
}
// è´¨æ£€ç»Ÿè®¡
const qualityStatisticsInfo = () => {
  qualityInspectionStatistics({ type: qualityRange.value }).then((res) => {
    xAxis1.value[0].data = []
    barSeries1.value[0].data = []
    barSeries1.value[1].data = []
    barSeries1.value[2].data = []
    res.data.item.forEach(item => {
      xAxis1.value[0].data.push(item.date)
      barSeries1.value[0].data.push(item.supplierNum)
      barSeries1.value[1].data.push(item.processNum)
      barSeries1.value[2].data.push(item.factoryNum)
const getRecommendedShortcuts = () => {
  const list = defaultShortcuts
    .map((item) => {
      const matched = findRouteByKeywords(keywordMap[item.label] || [item.label]);
      return matched ? { label: item.label, path: matched.path } : null;
    })
    qualityStatisticsObject.value.supplierNum = res.data.supplierNum
    qualityStatisticsObject.value.processNum = res.data.processNum
    qualityStatisticsObject.value.factoryNum = res.data.factoryNum
  })
}
const getAmountHalfYearNum = async () => {
  const res = await getAmountHalfYear()
  console.log(res)
  const monthName = []
  const receiptAmount = []
  const invoiceAmount = []
  res.data.forEach(item => {
    monthName.push(item.month)
    receiptAmount.push(item.receiptAmount)
    invoiceAmount.push(item.invoiceAmount)
  })
  // æ­£ç¡®å“åº”式赋值:创建新的 xAxis å’Œ series å¯¹è±¡
  xAxis2.value[0].data = monthName
  xAxis2.value[0].data = monthName.map(item => item.replace(/~/g, '\n~'));
  lineSeries.value = [
    {
      name: '开票',
      type: 'line',
      data: invoiceAmount,
      stack: 'Total',
      areaStyle: {
        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
          {
            offset: 0,
            color: 'rgba(131, 207, 255, 1)'
          },
          {
            offset: 1,
            color: 'rgba(186, 228, 255, 1)'
          }
        ])
      },
      itemStyle: {
        color: '#2D99FF',
        borderColor: '#2D99FF'
      },
      emphasis: {
        focus: 'series'
      },
      lineStyle: {
        width: 0
      },
      showSymbol: true,
    },
    {
      name: '回款',
      type: 'line',
      data: receiptAmount,
      stack: 'Total',
      lineStyle: {
        width: 0
      },
      itemStyle: {
        color: '#83CFFF',
        borderColor: '#83CFFF'
      },
      showSymbol: true,
      areaStyle: {
        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
          {
            offset: 0,
            color: 'rgba(54, 153, 255, 1)'
          },
          {
            offset: 1,
            color: 'rgba(89, 169, 254, 1)'
          }
        ])
      },
      emphasis: {
        focus: 'series'
      },
    }
  ]
}
    .filter(Boolean);
  return list.length > 0 ? list : defaultShortcuts;
};
// å·¥åºæ•°æ®ç”Ÿäº§ç»Ÿè®¡æ˜Žç»†ï¼ˆå‡æ•°æ® + å›¾è¡¨ï¼‰
const processRange = ref(1)
const processChartData = ref([])
const tryRepairSavedShortcut = (item) => {
  const matched = findRouteByKeywords(keywordMap[item.label] || [item.label]);
  if (matched) return { label: item.label, path: matched.path };
  return item;
};
const processXAxis = ref([
const getSavedShortcuts = () => {
  const recommended = getRecommendedShortcuts();
  try {
    const saved = localStorage.getItem(SHORTCUT_STORAGE_KEY);
    if (!saved) return recommended;
    const parsed = JSON.parse(saved);
    if (!Array.isArray(parsed) || parsed.length === 0) return recommended;
    return parsed.map((item) => tryRepairSavedShortcut(item));
  } catch (error) {
    return recommended;
  }
};
const shortcuts = reactive(withValidFlag(getSavedShortcuts().slice(0, 6)));
const shortcutDialogVisible = ref(false);
const configDialogVisible = ref(false);
const selectedPagePath = ref("");
const lastUpdatedAt = ref("");
const pendingFilter = ref("all");
const chartRangePlan = ref(3);
const chartRangeQuality = ref(2);
const routePathMap = {
  plan: getPathByKeywords(["生产计划", "productionPlan"]),
  order: getPathByKeywords(["生产订单", "productionOrder"]),
  processInspection: getPathByKeywords(["过程检", "processInspection"]),
  meter: getPathByKeywords(["抄表", "meterCollection", "能耗"]),
  dispatch: getPathByKeywords(["生产调度", "productionDispatching"]),
};
const persistShortcuts = () => {
  localStorage.setItem(
    SHORTCUT_STORAGE_KEY,
    JSON.stringify(shortcuts.slice(0, 6).map(({ label, path }) => ({ label, path })))
  );
};
const todos = reactive([]);
const businessFocus = reactive([
  { name: "生产订单总数", value: "-" },
  { name: "已完成订单数", value: "-" },
  { name: "未完成订单数", value: "-" },
  { name: "部分完成订单数", value: "-" },
  { name: "质检总数", value: "-" },
  { name: "过程检总数", value: "-" },
]);
const pendingTasks = reactive([]);
const warningList = reactive([]);
const SECTION_CONFIG_KEY = "home-sections-v1";
const sectionConfigOptions = [
  { key: "trendCards", label: "最近7天趋势卡" },
  { key: "planTrend", label: "计划与生产趋势图" },
  { key: "qualityChart", label: "质检异常分布图" },
  { key: "costChart", label: "能耗与成本结构图" },
  { key: "warningCenter", label: "异常预警中心" },
  { key: "planTable", label: "生产计划执行明细表" },
];
const enabledSectionKeys = ref(sectionConfigOptions.map((i) => i.key));
const chartStyle = { width: "100%", height: "100%" };
const grid = { left: "3%", right: "4%", bottom: "3%", containLabel: true };
const lineTooltip = { trigger: "axis" };
const barTooltip = { trigger: "axis", axisPointer: { type: "shadow" } };
const pieTooltip = { trigger: "item" };
const valueYAxis = [{ type: "value" }];
const planXAxis = [{ type: "category", data: [] }];
const qualityXAxis = [{ type: "category", data: [] }];
const planLegend = { show: true, data: ["计划量", "下发量", "完成量"] };
const costLegend = {
  show: true,
  orient: "vertical",
  right: 10,
  top: "center",
  data: ["能耗成本", "生产成本", "质量损失成本", "其他成本"],
};
const planSeries = reactive([
  { name: "计划量", type: "line", smooth: true, data: [] },
  { name: "下发量", type: "line", smooth: true, data: [] },
  { name: "完成量", type: "line", smooth: true, data: [] },
]);
const qualitySeries = reactive([
  {
    nameTextStyle: { color: 'rgba(0,0,0,0.35)', fontSize: 12 },
    axisLabel: { color: 'rgba(0,0,0,0.35)' },
    splitLine: { lineStyle: { color: 'rgba(0,0,0,0.06)', type: 'dashed' } },
  },
])
const processYAxis = ref([
  {
    type: 'category',
    axisTick: { show: false },
    axisLine: { show: false },
    axisLabel: { color: 'rgba(0,0,0,0.45)' },
    name: "异常数",
    type: "bar",
    barWidth: 26,
    itemStyle: { color: "#e67e22", borderRadius: [6, 6, 0, 0] },
    data: [],
  },
])
]);
const processGrid = reactive({ left: 0, right: 100, top: 30, bottom: 20, containLabel: true })
const processTooltip = reactive({
  trigger: 'axis',
  axisPointer: { type: 'shadow' },
  formatter: (params) => {
    const name = params?.[0]?.name ?? ''
    const list = Array.isArray(params) ? params : []
    const lines = list
      .map((p) => {
        const colorBox = `<span style="display:inline-block;margin-right:6px;border-radius:2px;width:10px;height:10px;background:${p.color}"></span>`
        return `${colorBox}${p.seriesName} <b style="float:right;">${Number(p.value || 0).toFixed(2)}</b>`
      })
      .join('<br/>')
    return `<div style="min-width:140px;"><div style="font-weight:700;margin-bottom:6px;">${name}</div>${lines}</div>`
const costSeries = reactive([
  {
    type: "pie",
    radius: ["45%", "68%"],
    center: ["35%", "50%"],
    label: { formatter: "{b}: {d}%" },
    data: [],
  },
})
]);
const processSeries = computed(() => {
  const input = processChartData.value.map((i) => i.input)
  const scrap = processChartData.value.map((i) => i.scrap)
  const output = processChartData.value.map((i) => i.output)
const planTable = reactive([]);
const recentTrendCards = reactive([
  { key: "planIssued", label: "计划下发量", unit: "单", values: [0, 0, 0, 0, 0, 0, 0], latest: 0, change: 0 },
  { key: "qualityRaw", label: "来料检数量", unit: "条", values: [0, 0, 0, 0, 0, 0, 0], latest: 0, change: 0 },
  { key: "qualityProcess", label: "过程检数量", unit: "条", values: [0, 0, 0, 0, 0, 0, 0], latest: 0, change: 0 },
  { key: "qualityFactory", label: "成品检数量", unit: "条", values: [0, 0, 0, 0, 0, 0, 0], latest: 0, change: 0 },
]);
  return [
    {
      name: '投入量',
      type: 'bar',
      stack: 'total',
      barWidth: 22,
      itemStyle: { color: '#1E5BFF', borderRadius: [6, 0, 0, 6] },
      data: input,
    },
    {
      name: '报废量',
      type: 'bar',
      stack: 'total',
      barWidth: 22,
      itemStyle: { color: '#F7B500' },
      data: scrap,
    },
    {
      name: '产出量',
      type: 'bar',
      stack: 'total',
      barWidth: 22,
      itemStyle: { color: '#19C6C6', borderRadius: [0, 6, 6, 0] },
      data: output,
    },
  ]
})
const toNumber = (value) => {
  const num = Number(value);
  return Number.isFinite(num) ? num : 0;
};
const processAside = computed(() => {
  const list = processChartData.value
  const item = list[activeProcessIndex.value] || {}
  return {
    processName: item.name || '暂无数据',
    totalInput: item.input || 0,
    totalScrap: item.scrap || 0,
    totalOutput: item.output || 0,
const pickFirstNumber = (obj, keys = []) => {
  for (const key of keys) {
    if (obj && obj[key] !== undefined && obj[key] !== null) return toNumber(obj[key]);
  }
})
  return 0;
};
const formatAmount = (n) => {
  const num = Number(n || 0)
  return num.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })
}
const updateArray = (target, list) => {
  target.splice(0, target.length, ...list);
};
const refreshProcessStats = () => {
  processDataProductionStatistics({
    type: processRange.value,
    processIds: selectedProcessIds.value.length > 0 ? selectedProcessIds.value.join(',') : null
  }).then(res => {
    processChartData.value = res.data.map(item => ({
      name: item.processName,
      input: item.totalInput,
      scrap: item.totalScrap,
      output: item.totalOutput
    }))
    processYAxis.value[0].data = processChartData.value.map((i) => i.name)
    activeProcessIndex.value = 0
  })
}
const toFixedOne = (num) => Number(num || 0).toFixed(1);
const normalizeSeven = (list = []) => {
  const nums = list.map((i) => toNumber(i));
  if (nums.length >= 7) return nums.slice(-7);
  return [...Array(7 - nums.length).fill(0), ...nums];
};
const calcTrend = (list = []) => {
  if (!Array.isArray(list) || list.length === 0) return { latest: 0, change: 0 };
  const first = toNumber(list[0]);
  const latest = toNumber(list[list.length - 1]);
  if (first === 0) return { latest, change: latest > 0 ? 100 : 0 };
  return { latest, change: ((latest - first) / first) * 100 };
};
const setTrendCard = (key, values) => {
  const target = recentTrendCards.find((i) => i.key === key);
  if (!target) return;
  const series = normalizeSeven(values);
  const { latest, change } = calcTrend(series);
  target.values = series;
  target.latest = latest;
  target.change = Number(toFixedOne(change));
};
const trendClass = (change) => (change > 0 ? "up" : change < 0 ? "down" : "flat");
const calcBarHeight = (value, list) => {
  const max = Math.max(...list, 1);
  return Math.max(18, Math.round((toNumber(value) / max) * 100));
};
const filteredPendingTasks = computed(() => {
  if (pendingFilter.value === "high") return pendingTasks.filter((i) => i.level === "高");
  if (pendingFilter.value === "mine") {
    const currentUserName = String(userStore?.name || "").toLowerCase();
    const currentUserId = String(userStore?.userId || "");
    return pendingTasks.filter((i) => {
      const ownerName = String(i.ownerName || "").toLowerCase();
      const ownerId = String(i.ownerId || "");
      return (currentUserName && ownerName && ownerName.includes(currentUserName)) || (currentUserId && ownerId === currentUserId);
    });
  }
  return pendingTasks;
});
const isSectionVisible = (key) => enabledSectionKeys.value.includes(key);
const goTo = (path) => {
  if (!isRouteValid(path)) {
    ElMessage.warning("当前菜单未配置该页面或无访问权限");
    return;
  }
  router.push(path);
};
const handleTrendCardClick = (card) => {
  const mapping = {
    planIssued: routePathMap.plan || routePathMap.order,
    qualityRaw: routePathMap.processInspection,
    qualityProcess: routePathMap.processInspection,
    qualityFactory: routePathMap.processInspection,
  };
  const target = mapping[card.key];
  if (!target) {
    ElMessage.warning("未配置可跳转页面");
    return;
  }
  const query =
    card.key === "planIssued"
      ? { dateType: String(chartRangePlan.value), source: "homeTrend" }
      : { dateType: String(chartRangeQuality.value), source: "homeTrend" };
  router.push({ path: target, query });
};
const openShortcutDialog = () => {
  shortcutDialogVisible.value = true;
};
const addShortcutBySelect = () => {
  if (shortcuts.length >= 6) {
    ElMessage.warning("快捷入口最多只能添加6个");
    return;
  }
  if (!selectedPagePath.value) {
    ElMessage.warning("请先选择页面");
    return;
  }
  if (shortcuts.some((item) => item.path === selectedPagePath.value)) {
    ElMessage.warning("该快捷入口已存在");
    return;
  }
  const label = selectableMenuMap.value.get(selectedPagePath.value);
  if (!label) {
    ElMessage.warning("请选择可添加的页面,目录节点不可选");
    return;
  }
  shortcuts.push({
    label,
    path: selectedPagePath.value,
    invalid: !isRouteValid(selectedPagePath.value),
  });
  persistShortcuts();
  selectedPagePath.value = "";
};
const removeShortcut = (index) => {
  shortcuts.splice(index, 1);
  persistShortcuts();
  ElMessage.success("已删除快捷入口");
};
const loadHomeTodos = async () => {
  try {
    const res = await homeTodos();
    const list = Array.isArray(res?.data) ? res.data : [];
    const mapped = list.slice(0, 4).map((item, idx) => {
      const text = item?.approveReason || item?.approveTypeName || `待处理事项 ${idx + 1}`;
      const levelType = idx === 0 ? "danger" : idx <= 2 ? "warning" : "success";
      const level = idx === 0 ? "高" : idx <= 2 ? "中" : "低";
      return { level, title: text, type: levelType };
    });
    updateArray(todos, mapped);
    const pendingMapped = list.slice(0, 4).map((item, idx) => {
      const title = item?.approveReason || item?.approveTypeName || `待处理事项 ${idx + 1}`;
      const path = inferTodoPath(item);
      return {
        id: item?.id || `${idx}-${title}`,
        title,
        level: idx === 0 ? "高" : idx <= 2 ? "中" : "低",
        type: idx === 0 ? "danger" : idx <= 2 ? "warning" : "success",
        path,
        ownerId: item?.approveUserId || item?.userId || "",
        ownerName: item?.approveUserName || item?.userName || "",
      };
    });
    updateArray(pendingTasks, pendingMapped);
  } catch (error) {
    console.error("homeTodos接口获取失败:", error);
  }
};
const loadOrderAndProgress = async () => {
  try {
    const [orderRes, progressRes] = await Promise.allSettled([orderCount(), getProgressStatistics()]);
    if (orderRes.status === "fulfilled") {
      const items = Array.isArray(orderRes.value?.data) ? orderRes.value.data : [];
      const byName = Object.fromEntries(
        items.map((i) => [String(i?.name || "").replace(/\s/g, ""), i?.value])
      );
      businessFocus[0].value = `${pickFirstNumber(byName, ["生产订单数", "生产订单总数", "总订单数"]) || 0} å•`;
      businessFocus[1].value = `${pickFirstNumber(byName, ["已完成订单数"]) || 0} å•`;
      businessFocus[2].value = `${pickFirstNumber(byName, ["待生产订单数", "未完成订单数"]) || 0} å•`;
      businessFocus[3].value = `${pickFirstNumber(byName, ["部分完成订单数"]) || 0} å•`;
    }
    if (progressRes.status === "fulfilled") {
      const p = progressRes.value?.data || {};
      const detail = Array.isArray(p.completedOrderDetails) ? p.completedOrderDetails : [];
      const rows = detail.slice(0, 6).map((item, index) => {
        const qty = pickFirstNumber(item, ["quantity", "planQuantity"]);
        const done = pickFirstNumber(item, ["completeQuantity", "completedQuantity"]);
        return {
          planNo: item.npsNo || item.productionPlanNo || `NO-${index + 1}`,
          product: item.productCategory || item.productName || "-",
          qty,
          issued: done,
          status: qty > 0 && done >= qty ? "已完成" : done > 0 ? "执行中" : "待下发",
        };
      });
      updateArray(planTable, rows);
      setTrendCard(
        "planIssued",
        detail.slice(-7).map((i) => pickFirstNumber(i, ["completeQuantity", "completedQuantity", "issueNum"]))
      );
    }
  } catch (error) {
    console.error("orderCount/getProgressStatistics接口获取失败:", error);
  }
};
const inferTodoPath = (todo) => {
  const text = `${todo?.approveTypeName || ""}${todo?.approveReason || ""}`.toLowerCase();
  if (text.includes("计划")) return routePathMap.plan || routePathMap.order;
  if (text.includes("订单")) return routePathMap.order || routePathMap.plan;
  if (text.includes("过程检") || text.includes("质检")) return routePathMap.processInspection || routePathMap.plan;
  if (text.includes("能耗") || text.includes("抄表")) return routePathMap.meter || routePathMap.plan;
  return routePathMap.plan || routePathMap.order || "";
};
const loadPlanTrend = async () => {
  try {
    const res = await processDataProductionStatistics({ type: chartRangePlan.value });
    const list = Array.isArray(res?.data) ? res.data : [];
    planXAxis[0].data = list.map((i, index) => i.processName || `工序${index + 1}`);
    planSeries[0].data = list.map((i) => pickFirstNumber(i, ["totalInput", "input", "planNum"]));
    planSeries[1].data = list.map((i) => pickFirstNumber(i, ["totalOutput", "output", "issueNum"]));
    planSeries[2].data = list.map((i) => pickFirstNumber(i, ["totalScrap", "scrap", "completeNum"]));
  } catch (error) {
    console.error("processDataProductionStatistics接口获取失败:", error);
  }
};
const loadQualityData = async () => {
  try {
    const res = await qualityInspectionStatistics({ type: chartRangeQuality.value });
    const data = res?.data || {};
    const items = Array.isArray(data.item) ? data.item : [];
    if (items.length > 0) {
      qualityXAxis[0].data = items.map((i) => i.date || i.name || "-");
      qualitySeries[0].data = items.map((i) =>
        pickFirstNumber(i, ["supplierNum", "processNum", "factoryNum", "totalNum"])
      );
      setTrendCard("qualityRaw", items.map((i) => pickFirstNumber(i, ["supplierNum"])));
      setTrendCard("qualityProcess", items.map((i) => pickFirstNumber(i, ["processNum"])));
      setTrendCard("qualityFactory", items.map((i) => pickFirstNumber(i, ["factoryNum"])));
    } else {
      qualityXAxis[0].data = ["来料检", "过程检", "成品检"];
      qualitySeries[0].data = [
        pickFirstNumber(data, ["supplierNum"]),
        pickFirstNumber(data, ["processNum"]),
        pickFirstNumber(data, ["factoryNum"]),
      ];
      setTrendCard("qualityRaw", [pickFirstNumber(data, ["supplierNum"])]);
      setTrendCard("qualityProcess", [pickFirstNumber(data, ["processNum"])]);
      setTrendCard("qualityFactory", [pickFirstNumber(data, ["factoryNum"])]);
    }
    businessFocus[4].value = `${pickFirstNumber(data, ["supplierNum", "totalNum"])} æ¡`;
    businessFocus[5].value = `${pickFirstNumber(data, ["processNum"])} æ¡`;
  } catch (error) {
    console.error("qualityInspectionStatistics接口获取失败:", error);
  }
};
const loadWarningCenter = async () => {
  try {
    const res = await nonComplianceWarning();
    const list = Array.isArray(res?.data) ? res.data : [];
    const mapped = list.slice(0, 6).map((item, idx) => {
      const levelNum = toNumber(item.level ?? item.warningLevel ?? 2);
      const levelType = levelNum >= 3 ? "danger" : levelNum === 2 ? "warning" : "info";
      const levelText = levelNum >= 3 ? "高" : levelNum === 2 ? "中" : "低";
      const title = item.name || item.title || item.paramName || `异常预警 ${idx + 1}`;
      const text = `${title}${item.processName || ""}${item.orderNo || ""}`.toLowerCase();
      const path = text.includes("质检")
        ? routePathMap.processInspection
        : text.includes("订单")
          ? routePathMap.order
          : routePathMap.processInspection || routePathMap.order || routePathMap.plan;
      return { id: item.id || `${idx}-${title}`, levelType, levelText, title, path };
    });
    updateArray(warningList, mapped);
  } catch (error) {
    console.error("nonComplianceWarning接口获取失败:", error);
    updateArray(warningList, []);
  }
};
const initSectionConfig = () => {
  try {
    const raw = localStorage.getItem(SECTION_CONFIG_KEY);
    if (!raw) return;
    const parsed = JSON.parse(raw);
    if (Array.isArray(parsed) && parsed.length > 0) {
      enabledSectionKeys.value = parsed.filter((k) => sectionConfigOptions.some((i) => i.key === k));
    }
  } catch (error) {
    console.error("读取首页配置失败:", error);
  }
};
const saveSectionConfig = () => {
  if (enabledSectionKeys.value.length === 0) {
    ElMessage.warning("至少保留一个模块");
    return;
  }
  localStorage.setItem(SECTION_CONFIG_KEY, JSON.stringify(enabledSectionKeys.value));
  configDialogVisible.value = false;
  ElMessage.success("首页配置已保存");
};
const loadCostComposition = async () => {
  try {
    const res = await expenseCompositionAnalysis({ type: 1 });
    const list = Array.isArray(res?.data) ? res.data : [];
    const mapped = list.map((i) => ({
      name: i.name || "未命名",
      value: pickFirstNumber(i, ["value", "amount", "cost"]),
    }));
    costSeries[0].data = mapped;
  } catch (error) {
    console.error("expenseCompositionAnalysis接口获取失败:", error);
  }
};
const refreshDashboardData = () => {
  loadHomeTodos();
  loadOrderAndProgress();
  loadPlanTrend();
  loadQualityData();
  loadCostComposition();
  loadWarningCenter();
  lastUpdatedAt.value = new Date().toLocaleString();
};
onMounted(() => {
  getBusinessData()
  analysisCustomer()
  todoInfoS()
  statisticsReceivable()
  qualityStatisticsInfo()
  getAmountHalfYearNum()
  refreshProcessStats()
})
  initSectionConfig();
  refreshDashboardData();
});
</script>
<style scoped>
.dashboard {
  background: #f5f7fa;
.home-page {
  min-height: 100vh;
  background: #f5f7fb;
  padding: 20px;
  box-sizing: border-box;
}
.dashboard-top {
.top-bar {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
  align-items: flex-start;
  justify-content: space-evenly;
}
.company-info {
  padding: 0;
  overflow: hidden;
  border-radius: 12px;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  background: #fff;
  height: 100%;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}
.welcome-banner {
  padding: 10px 10px;
  background: linear-gradient(135deg, rgba(229, 240, 255, 0.9), rgba(214, 232, 255, 0.7), rgba(207, 236, 255, 0.9));
}
.welcome-title {
  font-size: 18px;
  font-weight: 700;
  color: #222;
  line-height: 1.3;
}
.welcome-user {
  margin-right: 6px;
}
.welcome-time {
  margin-top: 10px;
  font-size: 16px;
  color: rgba(0, 0, 0, 0.55);
}
.user-card {
.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 22px;
}
.user-card-main {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}
.user-name {
  font-size: 16px;
  font-weight: bold;
  color: #111;
  letter-spacing: 1px;
}
.user-role {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 20px;
  padding: 5px 10px;
  background: rgba(245, 246, 248, 1);
  color: #333;
  width: fit-content;
  font-weight: 600;
}
.user-meta {
.refresh-time {
  font-size: 12px;
  color: rgba(0, 0, 0, 0.55);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #7b8794;
}
.user-meta .sep {
  margin: 0 10px;
  color: rgba(0, 0, 0, 0.25);
.user-box {
  display: flex;
  align-items: center;
  gap: 12px;
}
.avatar {
  width: 90px;
  height: 90px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  object-fit: cover;
  flex: 0 0 auto;
}
.data-cards {
  width: 50%;
  display: flex;
  gap: 16px;
  justify-content: flex-start;
  background: #ffffff;
  border-radius: 12px;
  padding: 20px;
}
.data-title {
  font-weight: 700;
  font-size: 26px;
  color: #FFFFFF;
}
.data-num {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 20px;
}
.data-card {
  background: #fff;
  border-radius: 12px;
  padding: 14px 10px 10px 10px;
  min-width: 160px;
  box-shadow: 0 2px 8px #eee;
  display: flex;
  flex-direction: column;
  width: 32%;
  height: 140px;
}
.data-card.sales {
  background-image: url("../assets/images/xioashoushuju.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
.data-card.purchase {
  background-image: url("../assets/images/caigou.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
.data-card.inventory {
  background-image: url("../assets/images/kucun.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
.data-desc {
  font-weight: 500;
  font-size: 13px;
  color: #FFFFFF;
}
.data-value {
.hello {
  font-size: 18px;
  font-weight: 500;
  margin: 10px 0;
  color: #FFFFFF;
  font-weight: 700;
  color: #1f2d3d;
}
.top-left {
  display: flex;
  flex-direction: column;
  gap: 20px;
  height: 180px;
  width: 20%;
}
.todo-panel {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  height: 180px;
  width: 30%;
}
.todo-list {
  height: 100px;
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 15px;
  overflow-y: auto;
}
.todo-list li {
  border-radius: 8px;
  margin-bottom: 12px;
  padding: 8px 20px;
  height: 74px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(225, 227, 250, 0.62);
}
.todo-title {
  font-weight: 400;
  font-size: 12px;
  color: #000000;
  position: relative;
}
.todo-title::before {
  content: '';
  /* å¿…需,表示这里有一个内容 */
  position: absolute;
  left: -10px;
  /* å®šä½åˆ°å·¦ä¾§ */
  top: 50%;
  /* åž‚直居中 */
  transform: translateY(-50%);
  /* å¾®è°ƒåž‚直居中 */
  width: 6px;
  /* åœ†çš„直径 */
  height: 6px;
  /* åœ†çš„直径 */
  background: #498CEB;
  border-radius: 50%;
  /* è®©å…¶å˜æˆåœ†å½¢ */
}
.todo-division {
  font-weight: 400;
  font-size: 12px;
  color: #000000;
}
.todo-time {
  font-weight: 400;
  font-size: 12px;
  color: #000000;
}
.todo-meta {
  color: #888;
.sub {
  margin-top: 4px;
  color: #6b7785;
  font-size: 13px;
}
.dashboard-row {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
.content-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  align-items: stretch;
}
.main-panel {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  flex: 1;
  min-width: 0;
.left-col,
.right-col {
  display: flex;
  flex-direction: column;
}
.section-card {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 2px 10px rgba(20, 35, 90, 0.06);
}
.flex-fill-card {
  flex: 1;
}
.section-title {
  position: relative;
  font-size: 18px;
  color: #333;
  padding-left: 10px;
  margin-bottom: 10px;
  margin-bottom: 14px;
  font-size: 16px;
  font-weight: 700;
  color: #243447;
}
.section-title::before {
  position: absolute;
  left: 0;
  top: 4px;
  content: '';
  width: 4px;
  height: 18px;
  background-color: #002FA7;
  border-radius: 2px;
}
.contract-info {
  display: flex;
  align-items: center;
  gap: 20px;
  height: 90px;
  background: rgba(245, 245, 245, 0.59);
  width: 100%;
  border-radius: 10px;
  padding: 10px 30px;
}
.contract-summary {
  display: flex;
  align-items: center;
  gap: 30px;
}
.contract-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.contract-name {
  font-weight: 400;
  font-size: 14px;
  color: #050505;
}
.contract-meta {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 80px;
}
.main-amount {
  font-size: 24px;
  color: rgba(51, 50, 50, 0.85);
}
.up {
  color: #e57373;
}
.contract-list {
  margin-top: 16px;
  font-size: 14px;
  color: #666;
  list-style: none;
  padding: 0;
  height: 190px;
  overflow-y: auto;
  width: 460px;
}
.line {
  position: relative;
  width: 230px;
}
.line::after {
  content: '';
  position: absolute;
  right: 2px;
  top: 0;
  bottom: 0;
  width: 1px;
  background-color: #C9C5C5;
  border-radius: 2px;
}
.contract-list li {
  margin-top: 10px;
}
.quality-cards {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}
.quality-card {
  border-radius: 8px;
  padding: 15px 10px 10px 50px;
  font-weight: 400;
  font-size: 12px;
  color: rgba(0, 0, 0, 0.67);
  width: 236px;
  height: 49px;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
.quality-card.one {
  background-image: url("../assets/images/yuancailiao.png");
}
.quality-card.two {
  background-image: url("../assets/images/guocheng.png");
}
.quality-card.three {
  background-image: url("../assets/images/chuchang.png");
}
.quality-card span {
  color: #4fc3f7;
  font-weight: bold;
  margin-left: 6px;
}
.chart {
  width: 100%;
  height: 220px;
  margin-top: 10px;
}
.process-panel {
  padding-bottom: 10px;
}
.process-panel__header {
.section-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.process-panel__body {
  display: flex;
  gap: 24px;
  align-items: stretch;
  margin-top: 10px;
.section-title::before {
  content: "";
  position: absolute;
  left: 0;
  top: 4px;
  width: 4px;
  height: 16px;
  border-radius: 2px;
  background: #409eff;
}
.process-panel__chart {
  flex: 1;
  min-width: 0;
  padding: 6px 0;
}
.process-panel__aside {
  width: 260px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.process-legend {
  display: flex;
  flex-direction: column;
.quick-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  align-items: flex-start;
  padding: 8px 6px;
}
.process-legend__item {
.quick-grid :deep(.el-button) {
  margin-left: 0;
}
.shortcut-form-row {
  display: grid;
  grid-template-columns: 1fr 1.5fr auto;
  gap: 10px;
  margin-bottom: 12px;
}
.todo-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: rgba(0, 0, 0, 0.55);
}
.dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}
.dot-blue {
  background: #1E5BFF;
}
.dot-yellow {
  background: #F7B500;
}
.dot-teal {
  background: #19C6C6;
}
.process-card {
  background: rgba(245, 247, 250, 0.9);
  border-radius: 10px;
  padding: 16px 16px;
}
.process-card--name {
  background: rgba(235, 242, 255, 1);
  color: #1E5BFF;
  font-weight: 800;
  font-size: 14px;
}
.process-card__label {
  font-size: 13px;
  color: rgba(0, 0, 0, 0.55);
  gap: 10px;
  margin-bottom: 10px;
  font-size: 13px;
  color: #3b4a5b;
}
.process-card__value {
  font-size: 24px;
  font-weight: 800;
  color: rgba(0, 0, 0, 0.8);
.focus-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px dashed #e8edf5;
}
.process-card__value .unit {
  font-size: 12px;
  font-weight: 600;
  color: rgba(0, 0, 0, 0.45);
  margin-left: 6px;
.focus-row:last-child {
  border-bottom: none;
}
@media (max-width: 1200px) {
  .process-panel__body {
    flex-direction: column;
  }
  .process-panel__aside {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
  }
  .process-card {
    flex: 1;
    min-width: 220px;
  }
.focus-name {
  font-size: 13px;
  color: #516174;
}
.process-selection-wrapper {
  max-height: 400px;
  overflow-y: auto;
  padding: 10px;
.focus-value {
  font-weight: 700;
  color: #1f2d3d;
}
.process-grid {
.task-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px dashed #e8edf5;
}
.task-row:last-child {
  border-bottom: none;
}
.task-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.task-title {
  font-size: 13px;
  color: #3d4d5f;
}
.row-two {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.trend-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
:deep(.el-checkbox.is-bordered) {
  margin-left: 0 !important;
  width: 100%;
.trend-card {
  border: 1px solid #e8edf5;
  border-radius: 10px;
  padding: 12px;
}
.trend-card.clickable {
  cursor: pointer;
  transition: all 0.2s ease;
}
.trend-card.clickable:hover {
  border-color: #8eb8ff;
  background: #f6f9ff;
}
.trend-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.trend-label {
  font-size: 13px;
  color: #5f6b7a;
}
.trend-rate {
  font-size: 12px;
  font-weight: 700;
}
.trend-rate.up {
  color: #67c23a;
}
.trend-rate.down {
  color: #f56c6c;
}
.trend-rate.flat {
  color: #909399;
}
.trend-value {
  margin-top: 6px;
  font-size: 20px;
  color: #1f2d3d;
  font-weight: 700;
}
.sparkline {
  margin-top: 10px;
  height: 48px;
  display: flex;
  align-items: flex-end;
  gap: 4px;
}
.sparkline-bar {
  flex: 1;
  min-height: 6px;
  border-radius: 3px 3px 0 0;
  background: linear-gradient(180deg, #82b1ff 0%, #409eff 100%);
}
.warning-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px dashed #e8edf5;
}
.warning-row:last-child {
  border-bottom: none;
}
.warning-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.warning-title {
  font-size: 13px;
  color: #3d4d5f;
}
.config-check-group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 16px;
}
.mini-table-wrap :deep(.el-table th) {
  background: #f8fbff;
}
@media (max-width: 1100px) {
  .content-grid {
    grid-template-columns: 1fr;
  }
  .row-two {
    grid-template-columns: 1fr;
  }
  .trend-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
</style>
src/views/productionManagement/productionReporting/detailDialog.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,527 @@
<template>
  <el-dialog v-model="dialogVisible"
             :title="dialogTitle"
             width="1000px"
             :close-on-click-modal="false"
             custom-class="custom-dialog">
    <div class="detail-container">
      <!-- åŸºç¡€ä¿¡æ¯ -->
      <div class="detail-section">
        <h3 class="section-title">基础信息</h3>
        <el-descriptions :column="3"
                         border>
          <el-descriptions-item label="生产订单号">{{ detailData.npsNo || '-' }}</el-descriptions-item>
          <el-descriptions-item label="班组"><el-tag :type="detailData.schedule == '白班' ? 'primary' : 'warning'">{{ detailData.schedule || '-' }}</el-tag></el-descriptions-item>
          <el-descriptions-item label="岗位人员">{{ detailData.postName || '-' }}</el-descriptions-item>
          <el-descriptions-item label="产品编码">{{ detailData.materialCode || '-' }}</el-descriptions-item>
          <el-descriptions-item label="产品名称">{{ detailData.productName || '-' }}</el-descriptions-item>
          <el-descriptions-item label="规格">{{ detailData.model || '-' }}</el-descriptions-item>
          <el-descriptions-item label="合格数量"><span class="num2">{{ detailData.qualifiedQuantity || 0 }}</span> <span class="unit">方</span></el-descriptions-item>
          <el-descriptions-item label="不合格数量"><span class="num3">{{ detailData.unqualifiedQuantity || 0 }}</span> <span class="unit">方</span></el-descriptions-item>
          <el-descriptions-item label="总数量"><span class="num1">{{ detailData.quantity || 0 }}</span> <span class="unit">方</span></el-descriptions-item>
          <el-descriptions-item label="报工时间">{{ formatTime(detailData.reportingTime) }}</el-descriptions-item>
          <el-descriptions-item label="创建时间">{{ formatTime(detailData.createTime) }}</el-descriptions-item>
          <el-descriptions-item label="更新时间">{{ formatTime(detailData.updateTime) }}</el-descriptions-item>
        </el-descriptions>
      </div>
      <!-- å·¥åºä¿¡æ¯ -->
      <div class="detail-section"
           v-if="detailData.productionProductRouteItemDtoList && detailData.productionProductRouteItemDtoList.length > 0">
        <h3 class="section-title">工序信息</h3>
        <div v-for="(process, index) in detailData.productionProductRouteItemDtoList"
             :key="process.id"
             class="process-item">
          <div class="process-header">
            <h4 class="process-title">{{ process.processName || '-' }}</h4>
            <div class="process-info">
              <span class="process-label">岗位人员:{{ process.postName || '-' }}</span>
              <span class="process-label">工序ID:{{ process.processNo || '-' }}</span>
            </div>
          </div>
          <!-- å·¥åºåŸºæœ¬ä¿¡æ¯ -->
          <div class="process-details">
            <el-descriptions :column="2"
                             border>
              <el-descriptions-item label="设备异常情况">{{ process.equipmentMalfunction || '-' }}</el-descriptions-item>
              <el-descriptions-item label="当班设备处置">{{ process.equipmentDisposal || '-' }}</el-descriptions-item>
              <el-descriptions-item label="工艺人员交待"
                                    :span="2">{{ process.processExplained || '-' }}</el-descriptions-item>
            </el-descriptions>
          </div>
          <!-- å·¥åºå‚æ•° -->
          <div v-if="process.productionProductRouteItemParamDtoList && process.productionProductRouteItemParamDtoList.length > 0">
            <!-- BOM信息 -->
            <div class="param-section"
                 v-if="getBomList(process.productionProductRouteItemParamDtoList).length > 0">
              <h5 class="param-title">投入品信息</h5>
              <el-table :data="getBomList(process.productionProductRouteItemParamDtoList)"
                        style="width: 100%"
                        size="small">
                <el-table-column prop="paramName"
                                 label="产品名称"
                                 min-width="120"></el-table-column>
                <el-table-column prop="model"
                                 label="规格型号"
                                 min-width="120"></el-table-column>
                <el-table-column prop="productValue"
                                 label="投入量"
                                 min-width="100"></el-table-column>
                <el-table-column prop="unit"
                                 label="单位"
                                 width="80"></el-table-column>
              </el-table>
            </div>
            <!-- å‚数信息 -->
            <div class="param-section"
                 v-if="getParamList(process.productionProductRouteItemParamDtoList).length > 0">
              <h5 class="param-title">生产记录</h5>
              <div v-for="(group, sort) in getParamGroups(process.productionProductRouteItemParamDtoList)"
                   :key="sort"
                   class="param-group">
                <div class="group-header">
                  <span class="group-title">生产记录组 {{ sort }}</span>
                </div>
                <div class="param-grid">
                  <div v-for="param in group"
                       :key="param.id"
                       class="param-item">
                    <span class="param-label">{{ param.paramName || '-' }}:</span>
                    <span class="param-value">{{ param.paramValue || '-' }}</span>
                    <span v-if="param.unit && param.unit !== '/'"
                          class="param-unit">{{ param.unit }}</span>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <!-- ä¸Šä¼ æ–‡ä»¶ -->
          <div class="file-section"
               v-if="process.fileList && process.fileList.length > 0">
            <h5 class="file-title">上传文件</h5>
            <div class="file-grid">
              <div v-for="file in process.fileList"
                   :key="file.id"
                   class="file-item">
                <el-image style="width: 100px; height: 100px"
                          v-if="file.fileUrl"
                          :src="baseUrl + file.fileUrl"
                          :zoom-rate="1.2"
                          :max-scale="7"
                          :alt="file.fileName"
                          :min-scale="0.2"
                          :preview-src-list="formatFileList(process.fileList)"
                          show-progress
                          :initial-index="4"
                          fit="cover" />
                <div class="file-info">
                  <span class="file-name">{{ file.fileName || '-' }}</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogVisible = false">关闭</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script setup>
  import { ref, computed, watch } from "vue";
  import dayjs from "dayjs";
  const baseUrl = import.meta.env.VITE_APP_BASE_API;
  const props = defineProps({
    visible: {
      type: Boolean,
      default: false,
    },
    data: {
      type: Object,
      default: () => ({}),
    },
  });
  const emit = defineEmits(["update:visible"]);
  const dialogVisible = computed({
    get: () => props.visible,
    set: value => emit("update:visible", value),
  });
  const dialogTitle = computed(() => "生产报工详情");
  const detailData = ref(props.data);
  // æ ¼å¼åŒ–æ—¶é—´
  const formatTime = time => {
    return time ? dayjs(time).format("YYYY-MM-DD HH:mm:ss") : "-";
  };
  // æ ¼å¼åŒ–文件列表
  const formatFileList = fileList => {
    return fileList.map(file => ({
      name: file.fileName,
      url: baseUrl + file.fileUrl,
      size: file.fileSize,
    }));
  };
  // å¤„理文件预览
  const handleFilePreview = file => {
    if (file.fileUrl) {
      window.open(baseUrl + file.fileUrl, "_blank");
    } else {
      console.log("文件没有URL,无法预览");
    }
  };
  // èŽ·å–BOM列表
  const getBomList = paramList => {
    return paramList.filter(item => item.bomId);
  };
  // èŽ·å–å‚æ•°åˆ—è¡¨
  const getParamList = paramList => {
    return paramList.filter(item => !item.bomId);
  };
  // æŒ‰sourceSort分组参数
  const getParamGroups = paramList => {
    const params = getParamList(paramList);
    const groups = {};
    params.forEach(param => {
      const sort = param.sourceSort || 1;
      if (!groups[sort]) {
        groups[sort] = [];
      }
      groups[sort].push(param);
    });
    return groups;
  };
  // ç›‘听数据变化
  watch(
    () => props.data,
    newData => {
      detailData.value = newData;
    },
    { deep: true }
  );
</script>
<style scoped>
  .detail-container {
    max-height: 600px;
    overflow-y: auto;
    padding: 0 16px;
  }
  .detail-section {
    margin-bottom: 28px;
    background-color: #ffffff;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  }
  .section-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    color: #1a1a1a;
    border-bottom: 2px solid #409eff;
    padding-bottom: 10px;
  }
  .process-item {
    margin-bottom: 24px;
    padding: 20px;
    background-color: #ffffff;
    border-radius: 8px;
    border: 1px solid #ebeef5;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  }
  .process-header {
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid #f0f2f5;
  }
  .process-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 12px;
    color: #1a1a1a;
    display: flex;
    align-items: center;
  }
  .process-title::before {
    content: "";
    display: inline-block;
    width: 4px;
    height: 16px;
    background-color: #409eff;
    margin-right: 8px;
    border-radius: 2px;
  }
  .process-info {
    display: flex;
    gap: 20px;
    font-size: 13px;
    color: #606266;
  }
  .process-label {
    padding: 4px 12px;
    background-color: #ecf5ff;
    border-radius: 4px;
    color: #409eff;
    font-weight: 500;
  }
  .process-details {
    margin-bottom: 20px;
  }
  .param-section {
    margin-bottom: 20px;
    background-color: #f9f9f9;
    border-radius: 6px;
    padding: 16px;
    border: 1px solid #f0f2f5;
  }
  .param-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 14px;
    color: #1a1a1a;
    padding-bottom: 8px;
    border-bottom: 1px solid #e8e8e8;
  }
  .file-section {
    margin-top: 20px;
    background-color: #f9f9f9;
    border-radius: 6px;
    padding: 16px;
    border: 1px solid #f0f2f5;
  }
  .file-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 14px;
    color: #1a1a1a;
    padding-bottom: 8px;
    border-bottom: 1px solid #e8e8e8;
  }
  .file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 16px;
  }
  .file-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #ffffff;
    border: 1px solid #e8e8e8;
    border-radius: 6px;
    padding: 10px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
  }
  .file-item:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    border-color: #409eff;
    transform: translateY(-2px);
  }
  .file-image {
    width: 100px;
    height: 100px;
    object-fit: cover;
    border-radius: 4px;
    cursor: pointer;
    margin-bottom: 8px;
  }
  :deep(.el-image) {
    border-radius: 4px;
    overflow: hidden;
  }
  :deep(.el-image__inner) {
    transition: transform 0.3s ease;
  }
  .file-item:hover :deep(.el-image__inner) {
    transform: scale(1.05);
  }
  .file-info {
    width: 100%;
    text-align: center;
  }
  .file-name {
    font-size: 12px;
    color: #606266;
    word-break: break-all;
    line-height: 1.4;
  }
  .param-group {
    margin-bottom: 16px;
    padding: 14px;
    background-color: #ffffff;
    border-radius: 6px;
    border: 1px solid #e8e8e8;
  }
  .group-header {
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #f0f2f5;
  }
  .num1 {
    color: #1107cc;
    font-weight: 600;
  }
  .num2 {
    color: #0fcf25;
    font-weight: 600;
  }
  .num3 {
    color: #d31818;
    font-weight: 600;
  }
  .unit {
    font-size: 12px;
    color: #5d5a66;
  }
  .group-title {
    font-size: 14px;
    font-weight: 600;
    color: #303133;
  }
  .param-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
  }
  .param-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid #f5f7fa;
  }
  .param-item:last-child {
    border-bottom: none;
  }
  .param-label {
    font-size: 13px;
    color: #606266;
    min-width: 100px;
    font-weight: 500;
  }
  .param-value {
    font-size: 13px;
    color: #1a1a1a;
    font-weight: 600;
    flex: 1;
  }
  .param-unit {
    font-size: 12px;
    color: #909399;
    background-color: #f0f2f5;
    padding: 2px 6px;
    border-radius: 3px;
  }
  .dialog-footer {
    text-align: center;
    padding: 20px;
    border-top: 1px solid #ebeef5;
  }
  .dialog-footer .el-button {
    min-width: 100px;
    padding: 8px 20px;
  }
  /* è‡ªå®šä¹‰å¯¹è¯æ¡†æ ·å¼ */
  :deep(.custom-dialog) {
    border-radius: 12px;
    overflow: hidden;
  }
  :deep(.custom-dialog .el-dialog__header) {
    background-color: #f5f7fa;
    padding: 20px;
    border-bottom: 1px solid #ebeef5;
  }
  :deep(.custom-dialog .el-dialog__title) {
    font-size: 18px;
    font-weight: 600;
    color: #1a1a1a;
  }
  :deep(.custom-dialog .el-dialog__body) {
    padding: 20px;
  }
  /* è¡¨æ ¼æ ·å¼ä¼˜åŒ– */
  :deep(.el-table) {
    border-radius: 6px;
    overflow: hidden;
  }
  :deep(.el-table th) {
    background-color: #f5f7fa;
    font-weight: 600;
    color: #303133;
  }
  :deep(.el-table tr:hover > td) {
    background-color: #ecf5ff !important;
  }
  /* æè¿°åˆ—表样式优化 */
  :deep(.el-descriptions) {
    border-radius: 6px;
    overflow: hidden;
  }
  :deep(.el-descriptions__label) {
    font-weight: 500;
    color: #606266;
  }
  :deep(.el-descriptions__content) {
    color: #1a1a1a;
    font-weight: 500;
  }
</style>
src/views/productionManagement/productionReporting/index.vue
@@ -4,14 +4,14 @@
      <el-form :model="searchForm"
               :inline="true">
        <el-form-item label="生产订单号:">
          <el-input v-model="searchForm.orderNo"
          <el-input v-model="searchForm.npsNo"
                    placeholder="请输入"
                    clearable
                    style="width: 160px;"
                    @keyup.enter="handleQuery" />
        </el-form-item>
        <el-form-item label="班组:">
          <el-select v-model="searchForm.teamName"
          <el-select v-model="searchForm.schedule"
                     placeholder="请选择"
                     clearable
                     style="width: 160px;"
@@ -21,7 +21,7 @@
            <el-option label="夜班"
                       value="夜班" />
          </el-select>
          <!-- <el-input v-model="searchForm.teamName"
          <!-- <el-input v-model="searchForm.schedule"
                    placeholder="请输入""
                    @keyup.enter="handleQuery" /> -->
        </el-form-item>
@@ -54,17 +54,20 @@
                :isSelection="false"
                @selection-change="handleSelectionChange"
                @pagination="pagination">
        <template #outputVolume="{ row }">
          <span style="font-weight: bold;color: #409eff;">{{ row.outputVolume }}</span><span style="margin-left: 5px;color: #909399;">方</span>
        <template #totalQuantity="{ row }">
          <span style="font-weight: bold;color: #409eff;">{{ row.totalQuantity }}</span><span style="margin-left: 5px;color: #909399;">方</span>
        </template>
        <template #unqualifiedVolume="{ row }">
          <span style="font-weight: bold;color: #b43434;">{{ row.unqualifiedVolume }}</span><span style="margin-left: 5px;color: #909399;">方</span>
        <template #scrapQty="{ row }">
          <span style="font-weight: bold;color: #b43434;">{{ row.scrapQty }}</span><span style="margin-left: 5px;color: #909399;">方</span>
        </template>
        <template #completedVolume="{ row }">
          <span style="font-weight: bold;color: #28e431;">{{ row.completedVolume }}</span><span style="margin-left: 5px;color: #909399;">方</span>
        <template #quantity="{ row }">
          <span style="font-weight: bold;color: #28e431;">{{ row.quantity }}</span><span style="margin-left: 5px;color: #909399;">方</span>
        </template>
      </PIMTable>
    </div>
    <!-- è¯¦æƒ…弹窗 -->
    <detail-dialog v-model:visible="detailDialogVisible"
                   :data="detailData" />
  </div>
</template>
@@ -74,24 +77,28 @@
  import { ElMessage, ElMessageBox } from "element-plus";
  import dayjs from "dayjs";
  import {
    workListPage,
    productionReport,
    productionReportUpdate,
    productionReportDelete,
    productionReportDetail,
    productionReportListPage,
  } from "@/api/productionManagement/productionReporting.js";
  import PIMTable from "@/components/PIMTable/PIMTable.vue";
  import DetailDialog from "./detailDialog.vue";
  const router = useRouter();
  const { proxy } = getCurrentInstance();
  const tableColumn = ref([
    {
      label: "报工编号",
      prop: "productNo",
    },
    {
      label: "生产订单号",
      prop: "orderNo",
      prop: "npsNo",
    },
    {
      label: "班组",
      prop: "teamName",
      prop: "schedule",
      width: "120px",
      dataType: "tag",
      formatType: params => {
@@ -101,46 +108,51 @@
    {
      label: "产品编码",
      prop: "materialCode",
      width: "150px",
    },
    {
      label: "产品名称",
      prop: "productName",
      width: "150px",
    },
    {
      label: "规格",
      prop: "specification",
      width: "120px",
      className: "specification-cell",
      prop: "productModelName",
      className: "productModelName-cell",
    },
    {
      label: "强度",
      prop: "strength",
      dataType: "tag",
      formatType: params => {
        return params == "A3.5" ? "primary" : "warning";
      },
    },
    {
      label: "产出方量",
      prop: "outputVolume",
      width: "120px",
      prop: "totalQuantity",
      width: "100px",
      align: "right",
      dataType: "slot",
      slot: "outputVolume",
      slot: "totalQuantity",
    },
    {
      label: "不合格方量",
      prop: "unqualifiedVolume",
      width: "120px",
      prop: "scrapQty",
      width: "100px",
      align: "right",
      dataType: "slot",
      slot: "unqualifiedVolume",
      slot: "scrapQty",
    },
    {
      label: "完成方量",
      prop: "completedVolume",
      width: "120px",
      prop: "quantity",
      width: "100px",
      align: "right",
      dataType: "slot",
      slot: "completedVolume",
      slot: "quantity",
    },
    {
      label: "创建人",
      prop: "createBy",
      prop: "postName",
      width: "120px",
      dataType: "tag",
    },
@@ -190,170 +202,41 @@
  });
  const searchForm = reactive({
    orderNo: "",
    teamName: "",
    npsNo: "",
    schedule: "",
    productName: "",
  });
  const mockData = [
    {
      id: 1,
      orderNo: "PO202401001",
      teamName: "白班",
      materialCode: "PC001",
      productName: "标准砌块",
      specification: "600×240×200",
      outputVolume: 120.5,
      unqualifiedVolume: 2.3,
      completedVolume: 118.2,
      createBy: "张三",
      createTime: "2024-01-15 08:30:00",
    },
    {
      id: 2,
      orderNo: "PO202401002",
      teamName: "夜班",
      materialCode: "PC002",
      productName: "标准砌块",
      specification: "600×240×200",
      outputVolume: 150.8,
      unqualifiedVolume: 1.5,
      completedVolume: 149.3,
      createBy: "李四",
      createTime: "2024-01-15 09:15:00",
    },
    {
      id: 3,
      orderNo: "PO202401003",
      teamName: "白班",
      materialCode: "PC003",
      productName: "加气砌块",
      specification: "600×240×250",
      outputVolume: 95.2,
      unqualifiedVolume: 0.8,
      completedVolume: 94.4,
      createBy: "王五",
      createTime: "2024-01-15 10:00:00",
    },
    {
      id: 4,
      orderNo: "PO202401004",
      teamName: "白班",
      materialCode: "PC004",
      productName: "标准砌块",
      specification: "600×240×200",
      outputVolume: 180.6,
      unqualifiedVolume: 3.2,
      completedVolume: 177.4,
      createBy: "赵六",
      createTime: "2024-01-15 14:20:00",
    },
    {
      id: 5,
      orderNo: "PO202401005",
      teamName: "夜班",
      materialCode: "PC005",
      productName: "加气砌块",
      specification: "600×240×250",
      outputVolume: 110.3,
      unqualifiedVolume: 1.1,
      completedVolume: 109.2,
      createBy: "孙七",
      createTime: "2024-01-15 15:45:00",
    },
    {
      id: 6,
      orderNo: "PO202401006",
      teamName: "白班",
      materialCode: "PC006",
      productName: "标准砌块",
      specification: "600×240×200",
      outputVolume: 135.7,
      unqualifiedVolume: 2.5,
      completedVolume: 133.2,
      createBy: "周八",
      createTime: "2024-01-16 08:00:00",
    },
    {
      id: 7,
      orderNo: "PO202401007",
      teamName: "白班",
      materialCode: "PC007",
      productName: "加气砌块",
      specification: "600×240×250",
      outputVolume: 88.4,
      unqualifiedVolume: 0.6,
      completedVolume: 87.8,
      createBy: "吴九",
      createTime: "2024-01-16 09:30:00",
    },
    {
      id: 8,
      orderNo: "PO202401008",
      teamName: "夜班",
      materialCode: "PC008",
      productName: "标准砌块",
      specification: "600×240×200",
      outputVolume: 165.2,
      unqualifiedVolume: 2.8,
      completedVolume: 162.4,
      createBy: "郑十",
      createTime: "2024-01-16 11:00:00",
    },
    {
      id: 9,
      orderNo: "PO202401009",
      teamName: "白班",
      materialCode: "PC009",
      productName: "加气砌块",
      specification: "600×240×250",
      outputVolume: 102.5,
      unqualifiedVolume: 1.3,
      completedVolume: 101.2,
      createBy: "钱十一",
      createTime: "2024-01-16 13:15:00",
    },
    {
      id: 10,
      orderNo: "PO202401010",
      teamName: "白班",
      materialCode: "PC010",
      productName: "标准砌块",
      specification: "600×240×200",
      outputVolume: 142.8,
      unqualifiedVolume: 2.1,
      completedVolume: 140.7,
      createBy: "刘十二",
      createTime: "2024-01-16 15:00:00",
    },
  ];
  const form = reactive({
    id: undefined,
    orderId: "",
    orderNo: "",
    teamName: "",
    npsNo: "",
    schedule: "",
    materialCode: "",
    productName: "",
    specification: "",
    outputVolume: 0,
    unqualifiedVolume: 0,
    completedVolume: 0,
    productModelName: "",
    totalQuantity: 0,
    scrapQty: 0,
    quantity: 0,
    processId: "",
    params: {},
  });
  const selectedRows = ref([]);
  const detailDialogVisible = ref(false);
  const detailData = ref({});
  const getList = () => {
    tableLoading.value = true;
    setTimeout(() => {
    productionReportListPage({
      current: page.current,
      size: page.size,
      ...searchForm,
    }).then(res => {
      tableData.value = res.data.records;
      page.total = res.data.total;
      tableLoading.value = false;
      const start = (page.current - 1) * page.size;
      const end = start + page.size;
      tableData.value = mockData.slice(start, end);
      page.total = mockData.length;
    }, 500);
    });
  };
  const handleQuery = () => {
@@ -362,8 +245,8 @@
  };
  const handleReset = () => {
    searchForm.orderNo = "";
    searchForm.teamName = "";
    searchForm.npsNo = "";
    searchForm.schedule = "";
    searchForm.productName = "";
    page.current = 1;
    getList();
@@ -381,16 +264,17 @@
  const handleAdd = () => {
    Object.assign(form, {
      type: "add",
      id: undefined,
      orderId: "",
      orderNo: "",
      teamName: "",
      npsNo: "",
      schedule: "",
      materialCode: "",
      productName: "",
      specification: "",
      outputVolume: 0,
      unqualifiedVolume: 0,
      completedVolume: 0,
      productModelName: "",
      totalQuantity: 0,
      scrapQty: 0,
      quantity: 0,
      processId: "",
      params: {},
    });
@@ -401,30 +285,58 @@
  };
  const handleEdit = row => {
    Object.assign(form, {
      id: row.id,
      orderId: row.orderId || "",
      orderNo: row.orderNo,
      teamName: row.teamName,
      materialCode: row.materialCode,
      productName: row.productName,
      specification: row.specification,
      outputVolume: row.outputVolume,
      unqualifiedVolume: row.unqualifiedVolume,
      completedVolume: row.completedVolume,
      createBy: row.createBy || "",
      createTime: row.createTime || new Date(),
      processId: row.processId || "",
      params: row.params || {},
    });
    router.push({
      path: "/productionManagement/ReportingDialog",
      query: { data: JSON.stringify(form) },
    });
    // è°ƒç”¨è¯¦æƒ…接口获取完整数据
    productionReportDetail(row.id)
      .then(res => {
        if (res.code === 200) {
          const detailData = res.data;
          // æž„建编辑表单数据
          const editForm = {
            id: row.id,
            type: "edit",
            orderId: detailData.productOrderId || "",
            npsNo: detailData.npsNo || "",
            schedule: detailData.schedule || "",
            materialCode: detailData.materialCode || "",
            productName: detailData.productName || "",
            productModelName: detailData.model || "",
            totalQuantity: detailData.quantity || 0,
            scrapQty: detailData.unqualifiedQuantity || 0,
            quantity: detailData.qualifiedQuantity || 0,
            createBy: detailData.postName || "",
            createTime: detailData.createTime || new Date(),
            processId: "",
            params: {},
            // ä¼ é€’工序信息
            productionProductRouteItemDtoList:
              detailData.productionProductRouteItemDtoList || [],
          };
          router.push({
            path: "/productionManagement/ReportingDialog",
            query: { data: JSON.stringify(editForm) },
          });
        } else {
          ElMessage.error("获取详情失败");
        }
      })
      .catch(() => {
        ElMessage.error("获取详情失败");
      });
  };
  const handleDetail = row => {
    ElMessage.info("详情功能待实现");
    productionReportDetail(row.id)
      .then(res => {
        if (res.code === 200) {
          detailData.value = res.data;
          detailDialogVisible.value = true;
        } else {
          ElMessage.error("获取详情失败");
        }
      })
      .catch(() => {
        ElMessage.error("获取详情失败");
      });
  };
  const handleDelete = row => {
@@ -434,7 +346,7 @@
      type: "warning",
    })
      .then(() => {
        productionReportDelete({ id: row.id })
        productionReportDelete(row.id)
          .then(() => {
            ElMessage.success("删除成功");
            getList();
@@ -552,7 +464,7 @@
  }
</style>
<style lang="scss">
  .specification-cell {
  .productModelName-cell {
    color: #7a7d81;
    font-style: italic;
  }
src/views/productionManagement/productionReporting/reportingDialog.vue
@@ -305,10 +305,10 @@
                                    :label="`${item.productName} ${item.model}`"
                                    class="form-item">
                        <div class="consumable-input-group">
                          <el-input-number v-model="getProcessInfo(parseInt(activeProcessId)).consumables[item.id]"
                          <el-input-number v-model="getProcessInfo(parseInt(activeProcessId)).consumables[item.productModelId]"
                                           :min="0"
                                           :model-value="getConsumableValue(parseInt(activeProcessId), item.id)"
                                           @change="val => getProcessInfo(parseInt(activeProcessId)).consumables[item.id] = val"
                                           :model-value="getConsumableValue(parseInt(activeProcessId), item.productModelId)"
                                           @change="val => getProcessInfo(parseInt(activeProcessId)).consumables[item.productModelId] = val"
                                           class="consumable-input" />
                          <span class="consumable-unit">{{ item.unit }}</span>
                        </div>
@@ -353,7 +353,7 @@
                    </div>
                    <div class="card-body">
                      <div class="param-grid">
                        <el-form-item v-for="param in params"
                        <el-form-item v-for="param in params[activeProcessId] || []"
                                      :key="param.id"
                                      :label="param.paramName"
                                      :label-width="120"
@@ -362,9 +362,10 @@
                          <template v-if="param.paramType == '1'">
                            <!-- æ•°å­—类型 -->
                            <div class="param-input-group">
                              <!-- :precision="getPrecision(param.paramFormat)" -->
                              <el-input-number v-model="form.paramGroups[activeProcessId][index][param.id]"
                                               controls-position="right"
                                               :precision="getPrecision(param.paramFormat)"
                                               :key="param.id"
                                               class="param-input" />
                              <span v-if="param.unit && param.unit != '/'"
                                    class="param-unit">
@@ -376,6 +377,7 @@
                            <!-- æ–‡æœ¬ç±»åž‹ -->
                            <div class="param-input-group">
                              <el-input v-model="form.paramGroups[activeProcessId][index][param.id]"
                                        :key="param.id"
                                        class="param-input" />
                              <span v-if="param.unit && param.unit != '/'"
                                    class="param-unit">
@@ -388,6 +390,7 @@
                            <div class="param-input-group">
                              <el-select v-model="form.paramGroups[activeProcessId][index][param.id]"
                                         placeholder="请选择"
                                         :key="param.id"
                                         class="param-select"
                                         style="width: 100%">
                                <el-option v-for="option in dictOptions[param.paramFormat] || []"
@@ -406,6 +409,7 @@
                            <div class="param-input-group">
                              <el-date-picker :value-format="param.paramFormat"
                                              :format="param.paramFormat"
                                              :key="param.id"
                                              :type="param.paramFormat=='YYYY-MM-DD'?'date':'datetime'"
                                              v-model="form.paramGroups[activeProcessId][index][param.id]"
                                              class="param-input" />
@@ -419,6 +423,7 @@
                            <!-- å…¶ä»–类型 -->
                            <div class="param-input-group">
                              <el-input v-model="form.paramGroups[activeProcessId][index][param.id]"
                                        :key="param.id"
                                        class="param-input" />
                              <span v-if="param.unit && param.unit != '/'"
                                    class="param-unit">
@@ -453,7 +458,7 @@
                      </template>
                    </el-table-column>
                    <!-- å‚数列 -->
                    <el-table-column v-for="param in params"
                    <el-table-column v-for="param in params[activeProcessId] || []"
                                     :key="param.id"
                                     :min-width="200">
                      <template #header>
@@ -462,20 +467,23 @@
                      <template #default="{ row }">
                        <template v-if="param.paramType == '1'">
                          <!-- æ•°å­—类型 -->
                          <!-- :precision="getPrecision(param.paramFormat)" -->
                          <el-input-number v-model="row[param.id]"
                                           controls-position="right"
                                           :precision="getPrecision(param.paramFormat)"
                                           :key="param.id"
                                           class="table-input" />
                        </template>
                        <template v-else-if="param.paramType == '2'">
                          <!-- æ–‡æœ¬ç±»åž‹ -->
                          <el-input v-model="row[param.id]"
                                    :key="param.id"
                                    class="table-input" />
                        </template>
                        <template v-else-if="param.paramType == '3'">
                          <!-- å­—典类型 -->
                          <el-select v-model="row[param.id]"
                                     placeholder="请选择"
                                     :key="param.id"
                                     class="table-select">
                            <el-option v-for="option in dictOptions[param.paramFormat] || []"
                                       :key="option.dictValue"
@@ -487,6 +495,7 @@
                          <!-- æ—¥æœŸç±»åž‹ -->
                          <el-date-picker :value-format="param.paramFormat"
                                          :format="param.paramFormat"
                                          :key="param.id"
                                          width="100%"
                                          :type="param.paramFormat=='YYYY-MM-DD'?'date':'datetime'"
                                          v-model="row[param.id]"
@@ -610,6 +619,7 @@
  import {
    productionRecordAdd,
    productionRecordAddSubmit,
    productionRecordEditSubmit,
  } from "@/api/productionManagement/productProcessRoute.js";
  import { userListNoPage } from "@/api/system/user.js";
  import { getInfo } from "@/api/login.js";
@@ -623,7 +633,9 @@
  const route = useRoute();
  const data = route.query.data ? JSON.parse(route.query.data) : {};
  const dialogTitle = computed(() => (data.id ? "编辑报工" : "新增报工"));
  const dialogTitle = computed(() =>
    form.type === "edit" ? "编辑报工" : "新增报工"
  );
  const formRef = ref(null);
  const isSubmitting = ref(false);
@@ -656,20 +668,23 @@
  const useTableView = ref(false); // æŽ§åˆ¶æ˜¯å¦ä½¿ç”¨è¡¨æ ¼è§†å›¾
  const form = reactive({
    type: data.type || "add",
    id: data.id || undefined,
    orderId: data.orderId || "",
    orderId: data.productOrderId || "",
    npsNo: data.npsNo || "",
    teamName: data.teamName || "白班",
    teamName: data.schedule || data.teamName || "白班",
    materialCode: data.materialCode || "",
    productName: data.productName || "",
    specification: data.specification || "",
    outputVolume: data.outputVolume || 0,
    unqualifiedVolume: data.unqualifiedVolume || 0,
    completedVolume: data.completedVolume || 0,
    createBy: data.createBy || "当前登录人",
    specification: data.productModelName || "",
    outputVolume: data.totalQuantity || data.outputVolume || 0,
    unqualifiedVolume: data.scrapQty || data.unqualifiedQuantity || 0,
    completedVolume: data.quantity || data.completedVolume || 0,
    createBy: data.createBy || data.postName || "当前登录人",
    createTime: data.createTime || new Date(),
    paramGroups: data.paramGroups || {}, // å­˜å‚¨æ¯ä¸ªå·¥åºçš„参数组
    processInfo: data.processInfo || {}, // å­˜å‚¨æ¯ä¸ªå·¥åºçš„基本信息
    productionProductRouteItemDtoList:
      data.productionProductRouteItemDtoList || [], // å·¥åºä¿¡æ¯
  });
  const rules = {
@@ -783,6 +798,7 @@
        processExplained: "",
        files: [],
        consumables: {},
        delFileIds: [], // å­˜å‚¨è¦åˆ é™¤çš„æ–‡ä»¶id
      };
    }
    return form.processInfo[processId];
@@ -796,12 +812,12 @@
  };
  // èŽ·å–æ¶ˆè€—å“æ•°é‡ï¼Œé»˜è®¤ä¸º0
  const getConsumableValue = (processId, itemId) => {
  const getConsumableValue = (processId, productModelId) => {
    const processInfo = getProcessInfo(processId);
    if (!processInfo.consumables[itemId]) {
      processInfo.consumables[itemId] = 0;
    if (!processInfo.consumables[productModelId]) {
      processInfo.consumables[productModelId] = 0;
    }
    return processInfo.consumables[itemId];
    return processInfo.consumables[productModelId];
  };
  // å¤„理文件预览
@@ -848,13 +864,16 @@
    const processId = parseInt(activeProcessId.value);
    if (processId) {
      const processInfo = getProcessInfo(processId);
      // è®°å½•被删除的文件id(只有编辑模式下的现有文件才需要记录)
      if (file.uid && !file.tempId) {
        processInfo.delFileIds.push(file.uid);
      }
      processInfo.files = fileList;
    }
  };
  // å¤„理文件变更
  const handleFileChange = async (file, fileList) => {
    console.log(file, fileList);
    const formData = new FormData();
    formData.append("file", file.raw);
@@ -867,7 +886,6 @@
        Authorization: `Bearer ${getToken()}`,
      },
    });
    console.log(uploadRes);
    if (uploadRes.code === 200) {
      const tempId = uploadRes.data.tempId;
      // å°†tempId存储到file对象中
@@ -905,16 +923,84 @@
      p => p.processId === parseInt(processId)
    );
    if (process) {
      params.value = process.orderRouteItemParaVos || [];
      params.value[processId] = process.orderRouteItemParaVos || [];
      // åˆå§‹åŒ–参数组
      if (!form.paramGroups[processId]) {
        form.paramGroups[processId] = [];
      }
      // æ£€æŸ¥æ˜¯å¦æœ‰ç¼–辑数据
      if (
        form.productionProductRouteItemDtoList &&
        form.productionProductRouteItemDtoList.length > 0
      ) {
        const editProcess = form.productionProductRouteItemDtoList.find(
          p => p.processId === parseInt(processId)
        );
        if (editProcess && editProcess.productionProductRouteItemParamDtoList) {
          // æŒ‰sourceSort分组参数
          const paramGroups = {};
          editProcess.productionProductRouteItemParamDtoList.forEach(param => {
            if (!param.bomId) {
              // åªå¤„理非BOM参数
              const sort = param.sourceSort || 1;
              if (!paramGroups[sort]) {
                paramGroups[sort] = {};
              }
              paramGroups[sort][param.orderItemParamId] = param.paramValue || "";
              // å¦‚果是字典类型参数,获取字典数据
              if (param.paramType == "3" && param.paramFormat) {
                getDictOptions(param.paramFormat);
              }
            }
          });
          // è½¬æ¢ä¸ºæ•°ç»„
          form.paramGroups[processId] = Object.values(paramGroups);
          // åˆå§‹åŒ–工序基本信息
          if (editProcess) {
            const processInfo = getProcessInfo(parseInt(processId));
            processInfo.postName = editProcess.postName || "";
            processInfo.equipmentMalfunction =
              editProcess.equipmentMalfunction || "";
            processInfo.equipmentDisposal = editProcess.equipmentDisposal || "";
            processInfo.id = editProcess.id || "";
            processInfo.processExplained = editProcess.processExplained || "";
            // å¤„理文件
            if (editProcess.fileList) {
              processInfo.files = editProcess.fileList.map(file => ({
                name: file.fileName,
                url: file.fileUrl,
                uid: file.id,
              }));
            }
            // å¤„理BOM信息
            if (editProcess.productionProductRouteItemParamDtoList) {
              editProcess.productionProductRouteItemParamDtoList.forEach(
                param => {
                  // console.log(form.processStructures[processId], "========");
                  if (param.bomId) {
                    // ä½¿ç”¨bomId作为key,因为getProcessStructures返回的item.id是bomId
                    form.processStructures[processId].forEach(item => {
                      if (item.productModelId == param.productId) {
                        processInfo.consumables[param.productId] =
                          param.productValue || 0;
                      }
                    });
                  }
                }
              );
            }
          }
        }
      }
      // å¦‚果没有参数组,添加一个默认参数组
      if (form.paramGroups[processId].length === 0) {
        const defaultGroup = {};
        for (const param of params.value) {
        for (const param of params.value[processId]) {
          defaultGroup[param.id] = param.standardValue || "";
          // å¦‚果是字典类型参数,获取字典数据
          if (param.paramType == "3" && param.paramFormat) {
@@ -962,7 +1048,6 @@
        // æž„建请求参数
        const order = orderList.value.find(item => item.id === form.orderId);
        console.log(order, "order");
        const submitParams = {
          productOrderId: form.orderId,
          productId: order ? order.productId : null,
@@ -976,7 +1061,6 @@
            const processInfo = getProcessInfo(process.processId);
            const paramGroups = form.paramGroups[process.processId] || [];
            const productionProductRouteItemParamDtoList = [];
            // æ·»åŠ å‚æ•°ç»„
            paramGroups.forEach((group, index) => {
              Object.entries(group).forEach(([paramId, value]) => {
@@ -990,16 +1074,18 @@
                    )
                  : null;
                if (param) {
                  console.log(param, "param");
                  productionProductRouteItemParamDtoList.push({
                    id: parseInt(paramId),
                    standardValue: param.standardValue,
                    minValue: param.minValue,
                    maxValue: param.maxValue,
                    // standardValue: param.standardValue,
                    // minValue: param.minValue,
                    // maxValue: param.maxValue,
                    productId: param.productId,
                    productValue: value,
                    paramValue: value,
                    // productValue: value,
                    sourceSort: index + 1,
                    unit: param.unit,
                    isRequired: param.isRequired,
                    // isRequired: param.isRequired,
                  });
                }
              });
@@ -1007,11 +1093,10 @@
            // æ·»åŠ BOM信息
            const structures = getProcessStructures(process.processId);
            console.log(structures, "structures");
            structures.forEach(structure => {
              const consumableValue = getConsumableValue(
                process.processId,
                structure.id
                structure.productModelId
              );
              if (consumableValue > 0) {
                productionProductRouteItemParamDtoList.push({
@@ -1023,35 +1108,66 @@
                });
              }
            });
            const fileIds = [];
            processInfo.files.forEach(file => {
              if (file.tempId) {
                fileIds.push(file.tempId);
              }
            });
            console.log(processInfo, "processInfo");
            return {
              postName: processInfo.postName,
              id: processInfo.id,
              equipmentMalfunction: processInfo.equipmentMalfunction,
              equipmentDisposal: processInfo.equipmentDisposal,
              processExplained: processInfo.processExplained,
              processId: process.processId,
              delFileIds: [...(processInfo.delFileIds || [])],
              productionProductRouteItemParamDtoList,
              files: processInfo.files.map(file => file.tempId || file.uid),
              // files: processInfo.files.map(file => file.tempId || file.uid),
              files: fileIds,
            };
          }),
        };
        console.log(submitParams, "submitParams");
        isSubmitting.value = false;
        // è°ƒç”¨API进行提交
        productionRecordAddSubmit(submitParams)
          .then(res => {
            if (res.code === 200) {
              ElMessage.success(data.id ? "修改成功" : "新增成功");
              router.back();
            } else {
              ElMessage.error(res.msg || "提交失败");
            }
          })
          .catch(error => {
            ElMessage.error("提交失败,请稍后重试");
            console.error("提交错误:", error);
          })
          .finally(() => {
            isSubmitting.value = false;
          });
        if (form.type === "edit") {
          submitParams.productMainId = form.id;
          productionRecordEditSubmit(submitParams)
            .then(res => {
              if (res.code === 200) {
                ElMessage.success(form.type === "edit" ? "修改成功" : "新增成功");
                router.back();
              } else {
                ElMessage.error(res.msg || "提交失败");
              }
            })
            .catch(error => {
              ElMessage.error("提交失败,请稍后重试");
              console.error("提交错误:", error);
            })
            .finally(() => {
              isSubmitting.value = false;
            });
        } else {
          productionRecordAddSubmit(submitParams)
            .then(res => {
              if (res.code === 200) {
                ElMessage.success(form.type === "edit" ? "修改成功" : "新增成功");
                router.back();
              } else {
                ElMessage.error(res.msg || "提交失败");
              }
            })
            .catch(error => {
              ElMessage.error("提交失败,请稍后重试");
              console.error("提交错误:", error);
            })
            .finally(() => {
              isSubmitting.value = false;
            });
        }
      }
    });
  };
@@ -1119,16 +1235,16 @@
    loadUsers();
    getCurrentUser();
    if (data.id) {
    if (form.type === "edit") {
      // ç¼–辑时设置表单数据
      Object.assign(form, data);
      // è®¾ç½®orderId
      orderId.value = data.orderId || "";
      orderId.value = form.orderId || "";
      // å¦‚果有订单ID,加载工序和参数
      if (data.orderId) {
      if (form.orderId) {
        // æ¨¡æ‹Ÿé€‰æ‹©è®¢å•的操作,触发数据加载
        setTimeout(() => {
          handleOrderChange(data.orderId);
          handleOrderChange(form.orderId);
        }, 100);
      }
    } else {
src/views/qualityManagement/rawMaterialInspection/components/detailDialog.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,250 @@
<template>
  <el-dialog v-model="dialogVisible"
             :title="dialogTitle"
             width="800px"
             :close-on-click-modal="false"
             custom-class="custom-dialog">
    <div class="detail-container">
      <!-- åŸºç¡€ä¿¡æ¯ -->
      <div class="detail-section">
        <h3 class="section-title">基础信息</h3>
        <el-descriptions :column="3"
                         border>
          <el-descriptions-item label="检测日期">{{ formatTime(detailData.checkTime) }}</el-descriptions-item>
          <el-descriptions-item label="供应商">{{ detailData.supplier || '-' }}</el-descriptions-item>
          <el-descriptions-item label="检验员"><span style="color: #eb9113;">{{ detailData.checkName || '-' }}</span></el-descriptions-item>
          <el-descriptions-item label="产品名称"><span style="color: hsl(210, 100%, 63%);">{{ detailData.productName || '-' }}</span></el-descriptions-item>
          <el-descriptions-item label="规格型号"><span style="">{{ detailData.model || '-' }}</span></el-descriptions-item>
          <el-descriptions-item label="单位"><span style="">{{ detailData.unit || '-' }}</span></el-descriptions-item>
          <el-descriptions-item label="数量">{{ detailData.quantity || 0 }}</el-descriptions-item>
          <el-descriptions-item label="试样编号">{{ detailData.sampleCode || '-' }}</el-descriptions-item>
          <el-descriptions-item label="车牌号">{{ detailData.licensePlateNumber || '-' }}</el-descriptions-item>
          <el-descriptions-item label="试样状态"><el-tag>{{ detailData.sampleState || '-' }}</el-tag></el-descriptions-item>
          <el-descriptions-item label="检测性质"><el-tag type="info">{{ detailData.inspectNature || '-' }}</el-tag></el-descriptions-item>
          <el-descriptions-item label="指标选择"><el-tag type="warning">{{ detailData.testStandardName || detailData.testStandardId || '-' }}</el-tag></el-descriptions-item>
          <el-descriptions-item label="取样日期">{{ formatTime(detailData.sampleTime) }}</el-descriptions-item>
          <el-descriptions-item label="检测单位">{{ detailData.checkCompany || '-' }}</el-descriptions-item>
          <el-descriptions-item label="检测结果"><el-tag :type="detailData.checkResult == '合格' ? 'success' : 'danger'">{{ detailData.checkResult || '-' }}</el-tag></el-descriptions-item>
          <el-descriptions-item label="提交状态"><el-tag :type="detailData.inspectState ? 'success' : 'danger'">{{ detailData.inspectState ? '已提交' : '未提交' }}</el-tag></el-descriptions-item>
        </el-descriptions>
      </div>
      <!-- æŒ‡æ ‡ä¿¡æ¯ -->
      <div class="detail-section"
           v-if="detailData.qualityInspectParams && detailData.qualityInspectParams.length > 0">
        <h3 class="section-title">指标信息</h3>
        <el-table :data="detailData.qualityInspectParams"
                  style="width: 100%"
                  border>
          <el-table-column prop="parameterItem"
                           label="指标"
                           min-width="150"></el-table-column>
          <el-table-column prop="unit"
                           label="单位"
                           width="100"></el-table-column>
          <el-table-column prop="standardValue"
                           label="标准值"
                           width="120"></el-table-column>
          <el-table-column prop="controlValue"
                           label="内控值"
                           width="120"></el-table-column>
          <el-table-column prop="testValue"
                           label="检验值"
                           width="120">
            <template #default="scope">
              <span style="color: hsl(210, 100%, 63%);">{{ scope.row.testValue || '-' }}</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogVisible = false">关闭</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script setup>
  import { ref, computed, watch } from "vue";
  import dayjs from "dayjs";
  import {
    qualityInspectDetailByProductId,
    getQualityTestStandardParamByTestStandardId,
  } from "@/api/qualityManagement/metricMaintenance.js";
  import { qualityInspectParamInfo } from "@/api/qualityManagement/qualityInspectParam.js";
  const props = defineProps({
    visible: {
      type: Boolean,
      default: false,
    },
    data: {
      type: Object,
      default: () => ({}),
    },
  });
  const emit = defineEmits(["update:visible"]);
  const dialogVisible = computed({
    get: () => props.visible,
    set: value => emit("update:visible", value),
  });
  const dialogTitle = computed(() => "原材料检验详情");
  const detailData = ref(props.data);
  const loading = ref(false);
  // æ ¼å¼åŒ–æ—¶é—´
  const formatTime = time => {
    return time ? dayjs(time).format("YYYY-MM-DD HH:mm:ss") : "-";
  };
  // åŠ è½½æŒ‡æ ‡é€‰æ‹©å’Œè¡¨æ ¼æ•°æ®
  const loadIndicatorData = async () => {
    if (!detailData.value.productId) return;
    loading.value = true;
    try {
      // åŠ è½½æŒ‡æ ‡é€‰æ‹©åˆ—è¡¨
      const params = {
        productId: detailData.value.productId,
        inspectType: 0,
      };
      const standardRes = await qualityInspectDetailByProductId(params);
      if (standardRes.data && standardRes.data.length > 0) {
        // æŸ¥æ‰¾å½“前选择的指标名称
        const selectedStandard = standardRes.data.find(
          item => item.id == detailData.value.testStandardId
        );
        if (selectedStandard) {
          detailData.value.testStandardName =
            selectedStandard.standardName || selectedStandard.standardNo;
        }
      }
      // åŠ è½½å‚æ•°æ•°æ®ï¼ˆä¸Žç¼–è¾‘é¡µé¢ä¿æŒä¸€è‡´ï¼‰
      if (detailData.value.id) {
        getQualityInspectParamList(detailData.value.id);
      }
    } catch (error) {
      console.error("加载指标数据失败:", error);
    } finally {
      loading.value = false;
    }
  };
  const getQualityInspectParamList = id => {
    qualityInspectParamInfo(id).then(res => {
      detailData.value.qualityInspectParams = res.data;
    });
  };
  // ç›‘听数据变化
  watch(
    () => props.data,
    newData => {
      detailData.value = newData;
    },
    { deep: true }
  );
  // æš´éœ²æ–¹æ³•给父组件
  defineExpose({
    loadIndicatorData,
  });
</script>
<style scoped>
  .detail-container {
    max-height: 600px;
    overflow-y: auto;
    padding: 0 16px;
  }
  .detail-section {
    margin-bottom: 28px;
    background-color: #ffffff;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  }
  .section-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    color: #1a1a1a;
    border-bottom: 2px solid #409eff;
    padding-bottom: 10px;
  }
  .dialog-footer {
    text-align: center;
    padding: 20px;
    border-top: 1px solid #ebeef5;
  }
  .dialog-footer .el-button {
    min-width: 100px;
    padding: 8px 20px;
  }
  /* è‡ªå®šä¹‰å¯¹è¯æ¡†æ ·å¼ */
  :deep(.custom-dialog) {
    border-radius: 12px;
    overflow: hidden;
  }
  :deep(.custom-dialog .el-dialog__header) {
    background-color: #f5f7fa;
    padding: 20px;
    border-bottom: 1px solid #ebeef5;
  }
  :deep(.custom-dialog .el-dialog__title) {
    font-size: 18px;
    font-weight: 600;
    color: #1a1a1a;
  }
  :deep(.custom-dialog .el-dialog__body) {
    padding: 20px;
  }
  /* æè¿°åˆ—表样式优化 */
  :deep(.el-descriptions) {
    border-radius: 6px;
    overflow: hidden;
  }
  :deep(.el-descriptions__label) {
    font-weight: 500;
    color: #606266;
  }
  :deep(.el-descriptions__content) {
    color: #1a1a1a;
    font-weight: 500;
  }
  /* è¡¨æ ¼æ ·å¼ä¼˜åŒ– */
  :deep(.el-table) {
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  }
  :deep(.el-table th) {
    background-color: #f5f7fa;
    font-weight: 600;
    color: #303133;
  }
  :deep(.el-table tr:hover > td) {
    background-color: #ecf5ff !important;
  }
  :deep(.el-table td) {
    color: #303133;
  }
</style>
src/views/qualityManagement/rawMaterialInspection/index.vue
@@ -49,6 +49,10 @@
             @close="handleQuery"></FormDia>
    <files-dia ref="filesDia"
               @close="handleQuery"></files-dia>
    <DetailDialog ref="detailDialog"
                  v-model:visible="detailDialogVisible"
                  :data="detailDialogData"
                  @close="handleQuery"></DetailDialog>
    <el-dialog v-model="dialogFormVisible"
               title="编辑检验员"
               width="30%"
@@ -93,6 +97,7 @@
  } from "vue";
  import InspectionFormDia from "@/views/qualityManagement/rawMaterialInspection/components/inspectionFormDia.vue";
  import FormDia from "@/views/qualityManagement/rawMaterialInspection/components/formDia.vue";
  import DetailDialog from "@/views/qualityManagement/rawMaterialInspection/components/detailDialog.vue";
  import { ElMessageBox } from "element-plus";
  import {
    downloadQualityInspect,
@@ -255,6 +260,13 @@
          },
        },
        {
          name: "详情",
          type: "text",
          clickFun: row => {
            openDetailDialog(row);
          },
        },
        {
          name: "附件",
          type: "text",
          clickFun: row => {
@@ -318,6 +330,9 @@
  const formDia = ref();
  const filesDia = ref();
  const inspectionFormDia = ref();
  const detailDialog = ref();
  const detailDialogVisible = ref(false);
  const detailDialogData = ref({});
  const { proxy } = getCurrentInstance();
  const userStore = useUserStore();
  const changeDaterange = value => {
@@ -372,6 +387,20 @@
    });
  };
  // æ‰“开详情弹框
  const openDetailDialog = row => {
    // ç¡®ä¿qualityInspectParams字段存在
    if (!row.qualityInspectParams) {
      row.qualityInspectParams = [];
    }
    detailDialogData.value = row;
    detailDialogVisible.value = true;
    // æ‰“开弹窗后加载指标数据
    setTimeout(() => {
      detailDialog.value?.loadIndicatorData();
    }, 100);
  };
  // åˆ é™¤
  const handleDelete = () => {
    let ids = [];