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
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
<template>
  <div class="app-container">
    <el-form :inline="true" :model="queryParams" class="search-form">
      <el-form-item label="登记日期">
        <el-date-picker
          v-model="queryParams.registrationDate"
          type="date"
          value-format="YYYY-MM-DD"
          format="YYYY-MM-DD"
          clearable
          style="width: 100%"
          placeholder="请选择日期"
        />
      </el-form-item>
      <el-form-item label="煤种">
        <el-input
          v-model="queryParams.coal"
          placeholder="请输入煤种"
          clearable
          :style="{ width: '100%' }"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleQuery">查询</el-button>
        <el-button @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-card>
      <!-- 标签页 -->
      <el-tabs
        v-model="activeTab"
        class="info-tabs"
        @tab-click="handleTabClick"
      >
        <el-tab-pane
          v-for="tab in tabs"
          :key="tab.name"
          :label="tab.label"
          :name="tab.name"
        />
      </el-tabs>
      <!-- 操作按钮区 -->
      <el-space>
        <!--        <el-button type="danger" :icon="Delete">删除</el-button>-->
        <!-- <el-button type="info" plain :icon="Download">导出</el-button>  -->
        <el-button
          type="success"
          plain
          :icon="Refresh"
          v-if="activeTab === 'officialInventory'"
          @click="mergeRows('merge')"
          >合并</el-button
        >
        <el-button
          type="info"
          plain
          :icon="Download"
          v-if="activeTab === 'officialInventory'"
          @click="handleExport"
          >导出</el-button
        >
      </el-space>
      <div>
        <el-table
          :data="tableData"
          border
          @selection-change="selectionChange"
          style="width: 100%; height: calc(100vh - 30em)"
          show-summary
          :summary-method="summarizeChildrenTable"
        >
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column
            label="序号"
            type="index"
            width="60"
            align="center"
          />
          <el-table-column
            prop="supplierName"
            label="供货商名称"
            width="180"
            sortable
          />
          <el-table-column prop="coal" label="煤种" sortable />
          <el-table-column prop="unit" label="单位" width="70" />
          <el-table-column
            prop="inventoryQuantity"
            label="库存数量"
            sortable
            min-width="110"
          />
          <el-table-column
            prop="priceIncludingTax"
            label="单价(含税)"
            sortable
            width="130"
          />
          <el-table-column
            prop="totalPriceIncludingTax"
            label="总价(含税)"
            width="130"
          />
          <el-table-column
            prop="priceExcludingTax"
            label="单价(不含税)"
            width="130"
          />
          <el-table-column
            prop="totalPriceExcludingTax"
            label="总价(不含税)"
            width="130"
          />
          <el-table-column
            prop="pendingReplenishment"
            label="待补库"
            width="130"
            v-if="activeTab === 'officialInventory'"
          />
          <el-table-column
            label="煤质"
            align="center"
            v-if="activeTab === 'officialInventory'"
            width="600"
          >
            <el-table-column
              v-for="col in columnTitle"
              :key="col.prop"
              :prop="col.prop"
              :label="col.label"
              align="center"
              sortable
              min-width="200"
            />
          </el-table-column>
          <el-table-column prop="registrant" label="登记人" width="180" />
          <el-table-column
            prop="registrationDate"
            label="登记日期"
            width="180"
          />
          <el-table-column
            fixed="right"
            label="操作"
            min-width="100"
            align="center"
          >
            <template #default="scope">
              <el-button
                link
                type="primary"
                size="small"
                @click="reviewDia(scope.row)"
                v-if="activeTab !== 'officialInventory'"
                >审核</el-button
              >
              <el-button
                link
                type="primary"
                size="small"
                @click="mergeRows('edit', scope.row)"
                v-if="activeTab === 'officialInventory'"
                >编辑</el-button
              >
              <el-button
                link
                type="primary"
                size="small"
                @click="mergeRows('view', scope.row)"
                v-if="activeTab === 'officialInventory'"
                >详情</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-if="total > 0"
          :page="pageNum"
          :limit="pageSize"
          :total="total"
          @pagination="handlePagination"
          :layout="'total, prev, pager, next, jumper'"
        />
      </div>
    </el-card>
    <!-- 审核待入库弹框 -->
    <el-dialog title="审核入库" v-model="reviewVisible" width="1000px">
      <el-form :model="form" :rules="rules" ref="formRef" label-width="180px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="供应商名称" prop="supplierId">
              <el-select v-model="form.supplierId" placeholder="请选择供应商">
                <el-option
                  :label="item.label"
                  v-for="item in supplyList"
                  :key="item.value"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="煤种" prop="coalId">
              <el-select v-model="form.coalId" placeholder="请选择煤种">
                <el-option
                  :label="item.label"
                  v-for="item in coalList"
                  :key="item.value"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="单位" prop="unit">
              <el-input
                v-model="form.unit"
                placeholder="请输入单位"
                maxlength="30"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="库存数量" prop="inventoryQuantity">
              <el-input
                v-model="form.inventoryQuantity"
                placeholder="请输入库存数量"
                :max="inventoryQuantity"
                type="number"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="单价(含税)" prop="priceIncludingTax">
              <el-input
                v-model="form.priceIncludingTax"
                placeholder="请输入单价(含税)"
                maxlength="30"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="总价(含税)" prop="totalPriceIncludingTax">
              <el-input
                v-model="form.totalPriceIncludingTax"
                placeholder="请输入总价(含税)"
                maxlength="30"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="单价(不含税)" prop="priceExcludingTax">
              <el-input
                v-model="form.priceExcludingTax"
                placeholder="请输入成本单价"
                maxlength="30"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="总价(不含税)" prop="totalPriceExcludingTax">
              <el-input
                v-model="form.totalPriceExcludingTax"
                placeholder="请输入成本单价"
                maxlength="30"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="煤质方案" prop="coalPlanId">
              <el-select
                v-model="form.coalPlanId"
                placeholder="请选择"
                @change="coalPlanByIdList"
                clearable
              >
                <el-option
                  v-for="dict in qualityPlanOption"
                  :key="dict.id"
                  :label="dict.plan"
                  :value="dict.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider></el-divider>
        <el-row>
          <el-col :span="12" v-for="item in filteredList" :key="item.id">
            <el-form-item :label="item.fieldName">
              <el-input v-model="form[item.fields]" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitReviewForm">确 定</el-button>
          <el-button @click="cancelReview">取 消</el-button>
        </div>
      </template>
    </el-dialog>
    <!-- 合并数据弹框 -->
    <el-dialog
      :title="operationType.value === 'edit' ? '编辑库存' : '合并库存'"
      v-model="mergeVisible"
      width="800px"
    >
      <el-form
        :model="mergeForm"
        :rules="mergeRules"
        ref="mergeRef"
        label-width="100px"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="供应商名称" prop="supplierId">
              <el-select
                v-model="mergeForm.supplierId"
                placeholder="请选择供应商"
                :disabled="operationType === 'view'"
              >
                <el-option
                  :label="item.label"
                  v-for="item in supplyList"
                  :key="item.value"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="煤种" prop="coalId">
              <el-select
                v-model="mergeForm.coalId"
                placeholder="请选择煤种"
                :disabled="operationType === 'view'"
              >
                <el-option
                  :label="item.label"
                  v-for="item in coalList"
                  :key="item.value"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="单位" prop="unit">
              <el-input
                v-model="mergeForm.unit"
                placeholder="请输入单位"
                maxlength="30"
                :disabled="operationType === 'view'"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="库存数量" prop="inventoryQuantity">
              <el-input
                v-model="mergeForm.inventoryQuantity"
                placeholder="请输入库存数量"
                :max="inventoryQuantity"
                type="number"
                :disabled="operationType === 'view'"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="单价(含税)" prop="priceIncludingTax">
              <el-input
                v-model="mergeForm.priceIncludingTax"
                placeholder="请输入单价(含税)"
                maxlength="30"
                :disabled="operationType === 'view'"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="总价(含税)" prop="totalPriceIncludingTax">
              <el-input
                v-model="mergeForm.totalPriceIncludingTax"
                placeholder="请输入总价(含税)"
                maxlength="30"
                :disabled="operationType === 'view'"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="单价(不含税)" prop="priceExcludingTax">
              <el-input
                v-model="mergeForm.priceExcludingTax"
                placeholder="请输入单价(不含税)"
                maxlength="30"
                :disabled="operationType === 'view'"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="总价(不含税)" prop="totalPriceExcludingTax">
              <el-input
                v-model="mergeForm.totalPriceExcludingTax"
                placeholder="请输入总价(不含税)"
                maxlength="30"
                :disabled="operationType === 'view'"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="煤质方案" prop="coalPlanId">
              <el-select
                v-model="mergeForm.coalPlanId"
                placeholder="请选择"
                @change="coalPlanByIdList"
                clearable
                :disabled="operationType === 'view'"
              >
                <el-option
                  v-for="dict in qualityPlanOption"
                  :key="dict.id"
                  :label="dict.plan"
                  :value="dict.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider></el-divider>
        <el-row>
          <el-col :span="12" v-for="item in filteredList" :key="item.id">
            <el-form-item :label="item.fieldName">
              <el-input
                v-model="mergeForm[item.fields]"
                :disabled="operationType === 'view'"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
 
<script setup>
import { onMounted, ref } from "vue";
import { Delete, Download, Refresh } from "@element-plus/icons-vue";
import Pagination from "@/components/Pagination/index.vue";
import {
  addOrEditCoalValue,
  coalFieldList,
  coalPlanById,
  coalPlanList,
  officialInventoryList,
  pendingInventoryList,
} from "@/api/warehouseManagement/index.js";
import { editOfficial, merge } from "../../api/warehouseManagement/index.js";
import { getSupplyList } from "@/api/procureMent/index.js";
import { getCoalInfoList } from "@/api/production/index.js";
import { ElMessage } from "element-plus";
 
const { proxy } = getCurrentInstance();
 
const tableData = ref([]);
const selectedRows = ref([]);
const qualityPlanOption = ref([]);
const filteredList = ref([]);
const tableLoading = ref(false);
const total = ref(0);
const pageNum = ref(1);
const pageSize = ref(10);
const inventoryQuantity = ref(0);
const count = ref(0);
const mean = ref(0);
const totalPrice = ref(0);
// 审核弹框
const reviewVisible = ref(false);
// 合并弹框
const mergeVisible = ref(false);
const operationType = ref("");
const data = reactive({
  form: {
    supplierName: "",
    coal: "",
    unit: "",
    inventoryQuantity: "",
    priceIncludingTax: "",
    totalPriceIncludingTax: "",
    priceExcludingTax: "",
    totalPriceExcludingTax: "",
    coalPlanId: "",
    pId: "",
  },
  mergeForm: {
    supplierId: "",
    coalId: "",
    unit: "",
    inventoryQuantity: "",
    priceIncludingTax: "",
    totalPriceIncludingTax: "",
    priceExcludingTax: "",
    totalPriceExcludingTax: "",
    coalPlanId: "",
    pId: "",
  },
  rules: {
    supplierName: [
      { required: true, message: "请输入供应商名称", trigger: "blur" },
    ],
    coal: [{ required: true, message: "请输入煤种", trigger: "blur" }],
    unit: [{ required: true, message: "请输入单位", trigger: "blur" }],
    coalPlanId: [{ required: true, message: "请选择", trigger: "change" }],
    supplierId: [
      { required: true, message: "请选择供应商", trigger: "change" },
    ],
  },
  mergeRules: {
    supplierName: [
      { required: true, message: "请输入供应商名称", trigger: "blur" },
    ],
    coal: [{ required: true, message: "请输入煤种", trigger: "blur" }],
    unit: [{ required: true, message: "请输入单位", trigger: "blur" }],
    coalPlanId: [{ required: true, message: "请选择", trigger: "change" }],
    supplierId: [
      { required: true, message: "请选择供应商", trigger: "change" },
    ],
  },
});
 
const { form, rules, mergeForm, mergeRules } = toRefs(data);
// 当前标签
const activeTab = ref("pendingInbound");
const tabName = ref("pendingInbound");
// 标签页数据
const tabs = reactive([
  { name: "pendingInbound", label: "待入库" },
  { name: "officialInventory", label: "正式库存" },
]);
// 查询参数
const queryParams = reactive({
  registrationDate: "",
  coal: "",
});
const columnTitle = ref([]);
const supplyList = ref([]);
const coalList = ref([]);
 
// 获取供应商下拉和煤种下拉
const getDropdownData = async () => {
  try {
    const [supplyRes, coalRes] = await Promise.all([
      getSupplyList(),
      getCoalInfoList(),
    ]);
    let supplyData = supplyRes.data;
    let coalData = coalRes.data;
    supplyList.value = supplyData.map((item) => ({
      value: item.id,
      label: item.supplierName,
    }));
    coalList.value = coalData.map((item) => ({
      value: item.id,
      label: item.coal,
    }));
  } catch (error) {
    ElMessage.error("获取下拉数据失败,请稍后重试");
  }
};
defineExpose({
  getDropdownData,
});
onMounted(() => {
  handleTabClick({ props: { name: "pendingInbound" } });
});
// 标签页点击
const handleTabClick = (tab) => {
  tabName.value = tab.props.name;
  tableData.value = [];
  getList();
};
const summarizeChildrenTable = (param) => {
  return proxy.summarizeTable(param, [
    "inventoryQuantity",
    "priceIncludingTax",
    "totalPriceIncludingTax",
    "priceExcludingTax",
    "totalPriceExcludingTax",
  ]);
};
// 点击查询
const handleQuery = () => {
  pageNum.value = 1;
  pageSize.value = 10;
  getList();
};
// 分页处理
const handlePagination = (val) => {
  pageNum.value = val.page;
  pageSize.value = val.limit;
  getList();
};
const getList = () => {
  tableLoading.value = true;
  // 赋值煤质表头展示字段
  if (tabName.value === "pendingInbound") {
    pendingInventoryList({
      ...queryParams,
      current: pageNum.value,
      size: pageSize.value,
    }).then((res) => {
      tableLoading.value = false;
      tableData.value = res.data.records;
      total.value = res.data.total;
    });
  } else {
    officialInventoryList({
      ...queryParams,
      current: pageNum.value,
      size: pageSize.value,
    }).then((res) => {
      tableLoading.value = false;
      const result = flattenFields(res.data.records);
      tableData.value = result;
      total.value = res.data.total;
      coalFieldListOption();
    });
  }
};
// 扁平化处理函数
const flattenFields = (data) => {
  return data.map((item) => {
    const mergedFields = item.fields.reduce((acc, obj) => {
      const key = Object.keys(obj)[0];
      acc[key] = obj[key];
      return acc;
    }, {});
 
    // 合并主对象与提取出的 fields 字段
    return {
      ...item,
      ...mergedFields,
    };
  });
};
// 重置查询
const resetQuery = () => {
  Object.keys(queryParams).forEach((key) => {
    if (key !== "pageNum" && key !== "pageSize") {
      queryParams[key] = "";
    }
  });
  handleQuery();
};
// 表格选择数据
const selectionChange = (rows) => {
  selectedRows.value = rows;
};
// 打开审核弹框
const reviewDia = (row) => {
  reviewVisible.value = true;
  filteredList.value = [];
  form.value = { ...row };
  form.value.pId = row.id;
  inventoryQuantity.value = row.inventoryQuantity;
  getDropdownData();
  coalPlanListOptions();
};
// 查询煤质方案下拉框
const coalPlanListOptions = () => {
  coalPlanList().then((res) => {
    qualityPlanOption.value = res.data;
  });
};
// 查询煤质方案字段
const coalPlanByIdList = (id) => {
  coalPlanById({ id: id }).then((res) => {
    filteredList.value = res.data;
    if (!id) {
      filteredList.value = [];
    }
  });
};
// 查询煤质字段
const coalFieldListOption = () => {
  coalFieldList().then((res) => {
    filteredList.value = res.data;
    columnTitle.value = res.data.map((item) => {
      return {
        prop: item.fields,
        label: item.fieldName, // 使用 fieldName 作为 label
      };
    });
  });
};
const handleExport = () => {
  const config = { api: "/officialInventory/export", name: "正式库" };
  proxy.$modal
    .confirm(
      "是否要导出" +
        (selectedRows.value.length > 0
          ? `选中的${selectedRows.value.length}条`
          : "全部") +
        "数据?"
    )
    .then((res) => {
      if (res) {
        ElMessage.success("正在导出数据,请稍候...");
        exportData(config.api, config.name);
      }
    })
    .catch(() => {});
};
const exportData = (api, name) => {
  proxy.download(
    api,
    { exportIds: selectedRows.value.map((row) => row.id) },
    `${new Date().getTime()}${name}${new Date().toLocaleDateString("en-CA")}.xlsx`
  );
};
// 合并库存数据方法
const mergeRows = (type, row) => {
  getDropdownData();
  coalPlanListOptions();
  if (type === "edit") {
    mergeVisible.value = true;
  }
  operationType.value = type;
  if (type !== "merge") {
    mergeForm.value = { ...row };
  } else {
    if (selectedRows.value.length < 2) {
      proxy.$modal.msgWarning("请至少选择两条数据");
      return;
    }
    mergeVisible.value = true;
    filteredList.value.forEach((item) => {
      mergeForm.value[item.fields] = "";
    });
    const data = selectedRows.value;
    const selectedIds = selectedRows.value.map((row) => row.id);
    // 初始化合计和均值变量
    let totalInventory = 0;
    let totalPriceIncludingTax = 0;
    let totalPriceExcludingTax = 0;
    let priceIncludingTaxSum = 0;
    let priceExcludingTaxSum = 0;
    // 遍历所有选中数据,累加计算
    data.forEach((row) => {
      totalInventory += parseFloat(row.inventoryQuantity) || 0;
      priceIncludingTaxSum += parseFloat(row.priceIncludingTax) || 0;
      totalPriceIncludingTax += parseFloat(row.totalPriceIncludingTax) || 0;
      priceExcludingTaxSum += parseFloat(row.priceExcludingTax) || 0;
      totalPriceExcludingTax += parseFloat(row.totalPriceExcludingTax) || 0;
    });
    // 计算平均值并保留两位小数
    const avgPriceIncludingTax = Number(
      (priceIncludingTaxSum / data.length).toFixed(2)
    );
    const avgTotalPriceIncludingTax = Number(
      (totalPriceIncludingTax / data.length).toFixed(2)
    );
    const avgPriceExcludingTax = Number(
      (priceExcludingTaxSum / data.length).toFixed(2)
    );
    const avgTotalPriceExcludingTax = Number(
      (totalPriceExcludingTax / data.length).toFixed(2)
    );
    // 设置表单显示
    mergeForm.value.inventoryQuantity = totalInventory;
    mergeForm.value.priceIncludingTax = avgPriceIncludingTax;
    mergeForm.value.totalPriceIncludingTax = avgTotalPriceIncludingTax;
    mergeForm.value.priceExcludingTax = avgPriceExcludingTax;
    mergeForm.value.totalPriceExcludingTax = avgTotalPriceExcludingTax;
    mergeForm.value.ids = selectedIds;
  }
};
// 提交合并表单
const submitForm = () => {
  proxy.$refs.mergeRef.validate((valid) => {
    if (valid) {
      delete mergeForm.value.createTime;
      delete mergeForm.value.updateTime;
      if (operationType.value === "edit") {
        mergeForm.value.fields = filteredList.value.reduce((acc, item) => {
          const key = item.fields;
          const value = mergeForm.value[key];
          // 判断是否有值(你可以根据需要修改判断条件)
          if (value !== null && value !== undefined && value !== "") {
            acc.push({ [key]: value });
          }
          return acc;
        }, []);
        editOfficial(mergeForm.value).then(() => {
          cancel();
          proxy.$modal.msgSuccess("修改成功");
          handleQuery();
        });
      } else {
        mergeForm.value.fields = filteredList.value.reduce((acc, item) => {
          const key = item.fields;
          const value = mergeForm.value[key];
          // 判断是否有值(你可以根据需要修改判断条件)
          if (value !== null && value !== undefined && value !== "") {
            acc.push({ [key]: value });
          }
          return acc;
        }, []);
        mergeForm.value.type = 2;
        merge(mergeForm.value).then(() => {
          cancel();
          proxy.$modal.msgSuccess("合并成功");
          handleQuery();
        });
      }
    }
  });
};
// 关闭合并表单
const cancel = () => {
  proxy.$refs.mergeRef.resetFields();
  mergeVisible.value = false;
};
// 提交审核表单
const submitReviewForm = () => {
  proxy.$refs.formRef.validate((valid) => {
    if (valid) {
      delete form.value.registrationTime;
      delete form.value.createTime;
      delete form.value.updateTime;
      form.value.type = 1;
      form.value.fieldValue = filteredList.value.map((item) => ({
        [item.fields]: form.value[item.fields],
      }));
      addOrEditCoalValue(form.value).then(() => {
        cancelReview();
        proxy.$modal.msgSuccess("提交成功");
        handleQuery();
      });
    }
  });
};
// 关闭审核弹框
const cancelReview = () => {
  proxy.$refs.formRef.resetFields();
  reviewVisible.value = false;
};
</script>
 
<style scoped>
:deep(.el-table) {
  margin: 20px 0;
}
</style>