zhang_nuo
2026-08-25 bc79e1fae76dffb3cbc3ddfa9ba23e66e150d098
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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
<template>
  <div class="app-container">
    <div class="table_list">
      <el-row :gutter="16"
              class="content-row">
        <!-- 左侧台账 + 顶部筛选 -->
        <el-col :xs="24"
                :sm="24"
                :md="24"
                :lg="8"
                :xl="8"
                class="left-col">
          <div class="left-panel">
            <el-alert
              title="工资核算口径:仅统计审核通过的报工数据。"
              type="info"
              :closable="false"
              show-icon
            />
            <div class="left-header">
              <el-form :model="searchForm"
                       inline>
                <el-form-item label="报工人员:">
                  <el-input v-model="searchForm.schedulingUserName"
                            placeholder="请输入"
                            clearable
                            style="width: 160px"
                            @change="reloadData" />
                </el-form-item>
                <el-form-item label="工单编号:">
                  <el-input v-model="searchForm.workOrderNo"
                            placeholder="请输入"
                            clearable
                            style="width: 160px"
                            @change="reloadData" />
                </el-form-item>
                <el-form-item prop="dateType">
                  <el-radio-group v-model="searchForm.dateType"
                                  size="small"
                                  @change="handleDateTypeChange">
                    <el-radio-button label="day">日</el-radio-button>
                    <el-radio-button label="month">月</el-radio-button>
                  </el-radio-group>
                </el-form-item>
                <el-form-item label="日期:"
                              prop="dateRange">
                  <el-date-picker v-model="searchForm.dateRange"
                                  :type="searchForm.dateType === 'day' ? 'date' : 'daterange'"
                                  range-separator="至"
                                  start-placeholder="开始日期"
                                  end-placeholder="结束日期"
                                  format="YYYY-MM-DD"
                                  value-format="YYYY-MM-DD"
                                  style="width: 200px"
                                  @change="handleDateRangeChange" />
                </el-form-item>
              </el-form>
            </div>
            <PIMTable rowKey="id"
                      :column="leftTableColumn"
                      :tableData="leftTableData"
                      :tableLoading="tableLoading"
                      :page="page"
                      @row-click="handleLeftRowClick"
                      @pagination="pagination"></PIMTable>
          </div>
        </el-col>
        <!-- 右侧明细 -->
        <el-col :xs="24"
                :sm="24"
                :md="24"
                :lg="16"
                :xl="16"
                class="right-col">
          <div class="right-panel">
            <div class="right-toolbar">
              <el-button type="primary" @click="handleBatchAccounting">批量核算</el-button>
            </div>
            <PIMTable rowKey="id"
                      :column="tableColumn"
                      :tableData="tableData"
                      :page="page1"
                      :isSelection="true"
                      @selection-change="handleSelectionChange"
                      :tableLoading="tableLoading1"
                      style="margin-right: 20px;"
                      @pagination="pagination1"></PIMTable>
          </div>
        </el-col>
      </el-row>
    </div>
    <el-dialog v-model="adjustDialogVisible"
               title="单个修正"
               width="520px">
      <el-form :model="adjustForm" label-width="120px">
        <el-form-item label="报工单号">
          <el-input v-model="adjustForm.reportNo" disabled />
        </el-form-item>
        <el-form-item label="报工人员">
          <el-input v-model="adjustForm.schedulingUserName" disabled />
        </el-form-item>
        <el-form-item label="修正金额">
          <el-input-number v-model="adjustForm.wages" :min="0" :precision="2" style="width: 100%" />
        </el-form-item>
        <el-form-item label="修正说明">
          <el-input v-model="adjustForm.remark" type="textarea" :rows="3" />
        </el-form-item>
      </el-form>
      <template #footer>
        <el-button @click="adjustDialogVisible = false">取消</el-button>
        <el-button type="primary" @click="confirmAdjust">确认</el-button>
      </template>
    </el-dialog>
  </div>
</template>
 
<script setup>
  import { onMounted, ref, reactive, toRefs, getCurrentInstance } from "vue";
  import { ElMessageBox } from "element-plus";
  import dayjs from "dayjs";
  import {
    salesLedgerProductionAccountingListProductionDetails,
    salesLedgerProductionAccountingList,
    productionAccountingBatchAccounting,
    productionAccountingSingleAdjust,
  } from "@/api/productionManagement/productionCosting.js";
  const { proxy } = getCurrentInstance();
 
  const formatTag = (val, map) => {
    const item = map[String(val)];
    if (!item) return "-";
    return item.label;
  };
 
  const tableColumn = ref([
    {
      label: "报工单号",
      prop: "reportNo",
      minWidth: 140,
    },
    {
      label: "生产日期",
      prop: "schedulingDate",
      minWidth: 100,
    },
    {
      label: "生产人",
      prop: "schedulingUserName",
      minWidth: 100,
    },
    {
      label: "审核状态",
      prop: "auditStatus",
      minWidth: 100,
      dataType: "tag",
      formatData: val => formatTag(val, {
        0: { label: "待审核" },
        1: { label: "审核通过" },
        2: { label: "审核不通过" },
      }),
      formatType: val => {
        const typeMap = {
          0: "warning",
          1: "success",
          2: "danger",
        };
        return typeMap[String(val)] || "info";
      },
    },
    {
      label: "报工类型",
      prop: "reportType",
      minWidth: 100,
      dataType: "tag",
      formatData: val => formatTag(val, {
        0: { label: "合格" },
        1: { label: "轻微返工" },
        2: { label: "严重返工" },
        3: { label: "报废" },
      }),
      formatType: val => {
        const typeMap = {
          0: "success",
          1: "warning",
          2: "danger",
          3: "info",
        };
        return typeMap[String(val)] || "info";
      },
    },
    {
      label: "销售合同号",
      prop: "salesContractNo",
      minWidth: 140,
    },
    {
      label: "产品大类",
      prop: "productName",
      minWidth: 100,
    },
    {
      label: "产品标准数量",
      prop: "productStandardQuantity",
      minWidth: 120,
    },
    {
      label: "规格型号",
      prop: "productModelName",
      minWidth: 100,
    },
    {
      label: "单位",
      prop: "unit",
      minWidth: 100,
    },
    {
      label: "工序",
      prop: "process",
      minWidth: 100,
    },
    {
      label: "标准数量",
      prop: "standardQuantity",
      minWidth: 100,
    },
    {
      label: "工单编号",
      prop: "workOrderNo",
      minWidth: 140,
    },
    {
      label: "补修理工时",
      prop: "repairWorkHour",
      minWidth: 120,
    },
    {
      label: "生产数量",
      prop: "quantity",
      minWidth: 100,
    },
    {
      label: "折算工时",
      prop: "convertedWorkHours",
      minWidth: 100,
    },
  ]);
 
  // 左侧汇总台账列(生产人、产量、工资、合格率)
  const leftTableColumn = ref([
    {
      label: "生产人",
      prop: "schedulingUserName",
      minWidth: 100,
    },
    {
      label: "产量",
      prop: "finishedNum",
      minWidth: 100,
    },
    {
      label: "折算工时合计",
      prop: "workHours",
      minWidth: 100,
    },
    {
      label: "合格率",
      prop: "outputRate",
      minWidth: 100,
      formatData: val => {
        if (val == null || val === "") return "-";
        return parseFloat(val).toFixed(2) + "%";
      },
    },
  ]);
 
  const tableData = ref([]);
  const tableLoading = ref(false);
  const tableLoading1 = ref(false);
  const leftTableData = ref([]);
  const selectedRows = ref([]);
  const adjustDialogVisible = ref(false);
  const adjustForm = reactive({
    id: null,
    reportNo: "",
    schedulingUserName: "",
    wages: 0,
    remark: "",
  });
  // 日 / 月 切换(默认按日)
  const page = reactive({
    current: 1,
    size: 100,
    total: 0,
  });
 
  const page1 = reactive({
    current: 1,
    size: 100,
    total: 0,
  });
 
  const data = reactive({
    searchForm: {
      schedulingUserName: "",
      workOrderNo: "",
      salesContractNo: "",
      dateType: "day",
      dateRange: dayjs().format("YYYY-MM-DD"),
      entryDate: dayjs().format("YYYY-MM-DD"),
      entryDateStart: undefined,
      entryDateEnd: undefined,
    },
  });
  const { searchForm } = toRefs(data);
 
  const pagination = obj => {
    page.current = obj.page;
    page.size = obj.limit;
    getList();
  };
 
  const pagination1 = obj => {
    page1.current = obj.page;
    page1.size = obj.limit;
    getList1();
  };
 
  const handleSelectionChange = selection => {
    selectedRows.value = selection || [];
  };
 
  const handleDateRangeChange = value => {
    if (value) {
      if (searchForm.value.dateType === "day") {
        searchForm.value.entryDate = value;
      } else {
        searchForm.value.entryDateStart = dayjs(value[0]).format("YYYY-MM-DD");
        searchForm.value.entryDateEnd = dayjs(value[1]).format("YYYY-MM-DD");
      }
    } else {
      searchForm.value.entryDate = undefined;
      searchForm.value.entryDateStart = undefined;
      searchForm.value.entryDateEnd = undefined;
    }
    reloadData();
  };
 
  const getList = () => {
    tableLoading.value = true;
    const params = { ...searchForm.value, ...page };
 
    salesLedgerProductionAccountingList(params)
      .then(res => {
        const records = res.data.records || [];
        leftTableData.value = records;
        page.total = res.data.total || 0;
      })
      .finally(() => {
        tableLoading.value = false;
      });
  };
 
  const getList1 = () => {
    tableLoading1.value = true;
    const params = { ...page1, ...searchForm.value };
    salesLedgerProductionAccountingListProductionDetails(params)
      .then(res => {
        tableData.value = res.data.records || [];
        page1.total = res.data.total || 0;
      })
      .finally(() => {
        tableLoading1.value = false;
      });
  };
 
  // 构建左侧汇总台账(按生产人汇总产量、工资等)
  const buildLeftTableData = records => {
    const map = {};
    records.forEach(item => {
      const key = item.schedulingUserName || "未知";
      if (!map[key]) {
        map[key] = {
          id: key,
          schedulingUserName: key,
          finishedNum: 0,
          wages: 0,
          qualifiedRate: item.qualifiedRate ?? null,
        };
      }
      map[key].finishedNum += Number(item.finishedNum || 0);
      map[key].wages += Number(item.wages || 0);
      if (item.qualifiedRate != null) {
        map[key].qualifiedRate = item.qualifiedRate;
      }
    });
    leftTableData.value = Object.values(map);
  };
 
  // 左侧日/月切换
  const handleDateTypeChange = value => {
    // 这里只作为筛选条件的一部分,直接重新查询列表
    if (value === "day") {
      searchForm.value.entryDate = dayjs().format("YYYY-MM-DD");
      searchForm.value.dateRange = searchForm.value.entryDate;
    } else {
      searchForm.value.entryDateStart = dayjs()
        .startOf("month")
        .format("YYYY-MM-DD");
      searchForm.value.entryDateEnd = dayjs().endOf("month").format("YYYY-MM-DD");
      searchForm.value.dateRange = [
        searchForm.value.entryDateStart,
        searchForm.value.entryDateEnd,
      ];
    }
 
    reloadData();
  };
 
  const reloadData = () => {
    page.current = 1;
    page1.current = 1;
    getList();
    tableData.value = [];
  };
 
  // 点击左侧行,刷右侧明细(按生产人过滤)
  const handleLeftRowClick = row => {
    searchForm.value.schedulingUserName = row.schedulingUserName || "";
    handleQuery();
  };
 
  // 查询列表
  /** 搜索按钮操作 */
  const handleQuery = () => {
    page1.current = 1;
    getList1();
  };
 
  // 导出
  const handleOut = () => {
    ElMessageBox.confirm("选中的内容将被导出,是否确认导出?", "导出", {
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      type: "warning",
    })
      .then(() => {
        proxy.download(
          "/productionAccount/exportSalarySlip",
          { ...searchForm.value },
          "生产工资条.xlsx"
        );
      })
      .catch(() => {
        proxy.$modal.msg("已取消");
      });
  };
 
  const handleBatchAccounting = () => {
    ElMessageBox.confirm("确定要按当前筛选条件执行批量核算吗?", "批量核算", {
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      type: "warning",
    })
      .then(() => {
        const { dateRange, ...batchPayload } = searchForm.value;
        return productionAccountingBatchAccounting(batchPayload);
      })
      .then(() => {
        proxy.$modal.msgSuccess("批量核算成功");
        reloadData();
      })
      .catch(() => {
        proxy.$modal.msg("已取消");
      });
  };
 
  const handleSingleAdjust = () => {
    if (!selectedRows.value.length) {
      proxy.$modal.msgWarning("请先勾选一条记录");
      return;
    }
    if (selectedRows.value.length > 1) {
      proxy.$modal.msgWarning("单个修正只能选择一条记录");
      return;
    }
    const row = selectedRows.value[0];
    adjustForm.id = row.id;
    adjustForm.reportNo = row.reportNo || "";
    adjustForm.schedulingUserName = row.schedulingUserName || "";
    adjustForm.wages = Number(row.wages || 0);
    adjustForm.remark = "";
    adjustDialogVisible.value = true;
  };
 
  const confirmAdjust = () => {
    const selectedRow = selectedRows.value[0];
    if (!selectedRow || !selectedRow.userId) {
      proxy.$modal.msgWarning("当前记录缺少报工人员信息,无法修正");
      return;
    }
    if (!adjustForm.wages && adjustForm.wages !== 0) {
      proxy.$modal.msgWarning("请输入修正金额");
      return;
    }
    productionAccountingSingleAdjust({
      productionProductMainId: adjustForm.id,
      schedulingUserId: selectedRow.userId,
      schedulingUserName: adjustForm.schedulingUserName,
      adjustAmount: adjustForm.wages,
      adjustRemark: adjustForm.remark,
      adjustUser: proxy.$store?.state?.user?.userId || undefined,
    }).then(() => {
      proxy.$modal.msgSuccess("修正成功");
      adjustDialogVisible.value = false;
      reloadData();
    }).catch(() => {});
  };
 
  const handleRowAdjust = row => {
    selectedRows.value = [row];
    handleSingleAdjust();
  };
 
  onMounted(() => {
    getList();
  });
</script>
 
<style scoped lang="scss">
  .content-row {
    width: 100%;
  }
 
  .content-row .left-col,
  .content-row .right-col {
    margin-bottom: 16px;
  }
 
  .left-panel,
  .right-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
  }
 
  .right-toolbar {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
  }
 
  .left-header {
    display: flex;
    align-items: center;
    gap: 12px;
  }
 
  .left-title {
    font-size: 16px;
    color: #ffffff;
  }
 
  .header-filters {
    display: flex;
    align-items: center;
    flex: 1;
    justify-content: flex-end;
    gap: 8px;
  }
 
  .search_title {
    color: #ffffff;
  }
 
  .ml10 {
    margin-left: 10px;
  }
</style>