yyb
15 小时以前 34181c0a1eb1aaf37d8942e36d11ab539d9f306c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
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>