添加生成逻辑以支持标准和实际成本对比分析,优化数据结构和模板下载功能
已修改1个文件
133 ■■■■ 文件已修改
src/views/costAccounting/stdVsActCostAnalysis/index.vue 133 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/costAccounting/stdVsActCostAnalysis/index.vue
@@ -271,35 +271,103 @@
const largeChartVisible = ref(false);
const currentChartOption = ref(null);
const actualCostSource = ref([
  { month: "2026-01", category: "瓷砖", costType: "能耗成本", actualCost: 182000 },
  { month: "2026-01", category: "瓷砖", costType: "生产成本", actualCost: 465000 },
  { month: "2026-01", category: "水泥", costType: "能耗成本", actualCost: 138500 },
  { month: "2026-01", category: "水泥", costType: "生产成本", actualCost: 398000 },
  { month: "2026-02", category: "瓷砖", costType: "能耗成本", actualCost: 191500 },
  { month: "2026-02", category: "瓷砖", costType: "生产成本", actualCost: 472500 },
  { month: "2026-02", category: "水泥", costType: "能耗成本", actualCost: 142300 },
  { month: "2026-02", category: "水泥", costType: "生产成本", actualCost: 407000 },
  { month: "2026-03", category: "砂浆", costType: "能耗成本", actualCost: 95800 },
  { month: "2026-03", category: "砂浆", costType: "生产成本", actualCost: 265400 },
  { month: "2026-03", category: "瓷砖", costType: "能耗成本", actualCost: 189800 },
  { month: "2026-03", category: "瓷砖", costType: "生产成本", actualCost: 469900 },
]);
// ------------------------------
// 假数据:用于先联调页面渲染
// ------------------------------
const actualCostSource = ref([]);
const standardCostSource = ref([]);
const standardCostSource = ref([
  { month: "2026-01", category: "瓷砖", costType: "能耗成本", standardCost: 176000 },
  { month: "2026-01", category: "瓷砖", costType: "生产成本", standardCost: 452000 },
  { month: "2026-01", category: "水泥", costType: "能耗成本", standardCost: 136000 },
  { month: "2026-01", category: "水泥", costType: "生产成本", standardCost: 392000 },
  { month: "2026-02", category: "瓷砖", costType: "能耗成本", standardCost: 186000 },
  { month: "2026-02", category: "瓷砖", costType: "生产成本", standardCost: 458000 },
  { month: "2026-02", category: "水泥", costType: "能耗成本", standardCost: 139000 },
  { month: "2026-02", category: "水泥", costType: "生产成本", standardCost: 401000 },
  { month: "2026-03", category: "砂浆", costType: "能耗成本", standardCost: 93000 },
  { month: "2026-03", category: "砂浆", costType: "生产成本", standardCost: 259000 },
  { month: "2026-03", category: "瓷砖", costType: "能耗成本", standardCost: 185000 },
  { month: "2026-03", category: "瓷砖", costType: "生产成本", standardCost: 461000 },
]);
const fakeMonths = ["2026-01", "2026-02", "2026-03"];
const fakeCategories = [
  "粉煤灰",
  "石灰",
  "水泥",
  "铝粉膏",
  "脱模剂",
  "石膏",
  "打包带",
  "防腐剂(板材用)",
  "氧化镁(板材用)",
  "冷挤丝(板材用)",
  "卡扣(板材用)",
  "材料小计",
  "水",
  "电",
  "蒸汽",
];
const fakeCostType = (category) => (["水", "电", "蒸汽"].includes(category) ? "能耗成本" : "生产成本");
// 每个类别的标准成本基准值(仅用于假数据)
const baseStandardCostByCategory = {
  粉煤灰: 98000,
  石灰: 52000,
  水泥: 175000,
  铝粉膏: 32000,
  脱模剂: 21000,
  石膏: 41000,
  打包带: 14500,
  "防腐剂(板材用)": 12500,
  "氧化镁(板材用)": 22000,
  "冷挤丝(板材用)": 9800,
  "卡扣(板材用)": 8600,
  材料小计: 420000,
  水: 6800,
  电: 26000,
  蒸汽: 52000,
};
// 月份波动系数(让图表看起来更“真实”一些)
const monthFactorByMonth = {
  "2026-01": 1.0,
  "2026-02": 1.06,
  "2026-03": 0.97,
};
// 实际成本相对标准成本的偏移比例(用于测试正负差异展示)
const diffRatioByCategory = {
  粉煤灰: 0.05,
  石灰: -0.01,
  水泥: 0.03,
  铝粉膏: 0.0,
  脱模剂: -0.04,
  石膏: 0.02,
  打包带: -0.03,
  "防腐剂(板材用)": 0.06,
  "氧化镁(板材用)": -0.02,
  "冷挤丝(板材用)": 0.01,
  "卡扣(板材用)": -0.05,
  材料小计: 0.02,
  水: -0.01,
  电: 0.04,
  蒸汽: -0.03,
};
const buildFakeSources = () => {
  const stdRows = [];
  const actRows = [];
  for (const month of fakeMonths) {
    const monthFactor = monthFactorByMonth[month] ?? 1;
    const monthAdj = month === "2026-02" ? 0.005 : month === "2026-03" ? -0.006 : 0;
    for (const category of fakeCategories) {
      const costType = fakeCostType(category);
      const base = baseStandardCostByCategory[category] ?? 0;
      const standardCost = Math.round(base * monthFactor);
      const diffRatio = (diffRatioByCategory[category] ?? 0) + monthAdj;
      const actualCost = Math.round(standardCost * (1 + diffRatio));
      stdRows.push({ month, category, costType, standardCost });
      actRows.push({ month, category, costType, actualCost });
    }
  }
  standardCostSource.value = stdRows;
  actualCostSource.value = actRows;
};
buildFakeSources();
const categoryOptions = computed(() => {
  const all = [...actualCostSource.value, ...standardCostSource.value];
@@ -614,10 +682,11 @@
const downloadTemplate = () => {
  const sample = [
    { 月份: "2026-03", 产品类别: "瓷砖", 成本类型: "标准能耗成本", 标准成本: 185000 },
    { 月份: "2026-03", 产品类别: "瓷砖", 成本类型: "标准生产成本", 标准成本: 461000 },
    { 月份: "2026-03", 产品类别: "水泥", 成本类型: "标准能耗成本", 标准成本: 140000 },
    { 月份: "2026-03", 产品类别: "水泥", 成本类型: "标准生产成本", 标准成本: 405000 },
    { 月份: "2026-03", 产品类别: "粉煤灰", 成本类型: "标准生产成本", 标准成本: 98000 },
    { 月份: "2026-03", 产品类别: "水泥", 成本类型: "标准生产成本", 标准成本: 175000 },
    { 月份: "2026-03", 产品类别: "电", 成本类型: "标准能耗成本", 标准成本: 26000 },
    { 月份: "2026-03", 产品类别: "蒸汽", 成本类型: "标准能耗成本", 标准成本: 52000 },
    { 月份: "2026-03", 产品类别: "水", 成本类型: "标准能耗成本", 标准成本: 6800 },
  ];
  const ws = XLSX.utils.json_to_sheet(sample);
  const wb = XLSX.utils.book_new();