wujianwei
2025-09-09 212f81d79dc966cdf5f73a658a070ca79d69e822
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
<template>
  <basicContainer>
    <avue-crud :option="option" :table-loading="pageF.loading" :data="tableData" :page="page"
      :permission="permissionList" :before-open="beforeOpen" v-model="form" ref="crudRef" @row-update="rowUpdate"
      @row-save="rowSave" @refresh-change="refreshChange" @row-del="rowDel" @search-change="searchChange"
      @search-reset="searchReset" @selection-change="selectionChange" @current-change="currentChange"
      @size-change="sizeChange" @on-load="onLoad">
      <template #menu-left>
        <!-- <el-button type="success" icon="Edit" :disabled="pageF.single"
          v-hasPermi="['cwgl:estimatedReceivableBill:edit']" @click="handleUpdate">修改
        </el-button> -->
        <!-- <el-button type="danger" icon="Delete" :disabled="pageF.multiple" @click="handleDelete"
          v-hasPermi="['cwgl:estimatedReceivableBill:remove']">删除
        </el-button>
        <el-button type="warning" plain icon="Download" @click="handleExport"
          v-hasPermi="['cwgl:estimatedReceivableBill:export']">导出
        </el-button> -->
      </template>
      <template #billSystemNo="{ size, row, index }">
 
        <el-link class="link-btn" type="primary" :underline="false" plain @click="handleBillSystemNo(row)">
          {{ row.billSystemNo }}
        </el-link>
      </template>
 
 
      <template #menu="{ size, row, index }">
 
        <el-link class="link-btn" type="primary" v-if="[0, 1].includes(row.status)" :underline="false" plain
          @click="handleclose(row)" v-hasPermi="['cwgl:estimatedReceivableBill:confirm']"> 结算
        </el-link>
        <el-link class="link-btn" type="primary" v-if="[0].includes(row.status)" :underline="false" plain
          @click="handleAmend(row)" v-hasPermi="['cwgl:estimatedReceivableBill:invalid']"> 修改
        </el-link>
        <el-link class="link-btn" type="primary" :underline="false" plain @click="handleFlow(row)"
          v-hasPermi="['cwgl:estimatedReceivableBill:flog']"> 日志
        </el-link>
      </template>
    </avue-crud>
  </basicContainer>
 
 
  <el-dialog v-model="dialog.visible" :title="dialog.title" width="1200px">
    <el-form ref="newFormRef" v-if="!dispIshow && noIshow" :model="newForm" :rules="rules" label-width="120px">
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="本次结算金额" prop="settlementAmount">
            <el-input v-model="newForm.settlementAmount" placeholder="请输入本次结算金额" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="备注" prop="remark">
            <el-input v-model="newForm.remark" :rows="2" type="textarea" placeholder="请输入备注" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="附件" prop="attachment">
            <FileUpload v-model="newForm.attachment" :isShowTip="false"
              :fileType="['pdf', 'bmp', 'gif', 'jpg', 'jpeg', 'png']"></FileUpload>
            &nbsp;支持文件类型: pdf,bmp,gif,jpg,jpeg,png'
          </el-form-item>
        </el-col>
 
      </el-row>
 
    </el-form>
 
    <div v-if="!dispIshow && noIshow" style="text-align: center;margin-top: 20px;">
      <el-button @click="cancel">取 消</el-button>
      <el-button type="primary" @click="submitForm">确 定</el-button>
    </div>
 
 
    <h2 style="margin: 15px;font-size: 15px;">
      账单基本信息
    </h2>
    <el-form ref="storagesTransferRef" :model="newObjForm" label-width="120px">
      <el-descriptions class="margin-top" title="" :column="3" border>
        <el-descriptions-item label="账单系统编号" align="center">
          {{ importForm.billSystemNo }}
        </el-descriptions-item>
        <el-descriptions-item label="账单名称" align="center">
          <el-input v-if="dispIshow" v-model="importForm.billName" placeholder="请输入账单名称" />
          <span v-if="!dispIshow"> {{ importForm.billName }}</span>
        </el-descriptions-item>
        <el-descriptions-item label="客户名称" align="center">
          {{ importForm.customerName }}
        </el-descriptions-item>
 
        <el-descriptions-item label="应结算金额" align="center">
          {{ importForm.totalAmount }}
        </el-descriptions-item>
 
        <el-descriptions-item v-if="!dispIshow" label="已结算金额" align="center">
          {{ importForm.settledAmount }}
        </el-descriptions-item>
 
        <el-descriptions-item v-if="!dispIshow" label="待结算金额" align="center">
          <span v-if="importForm.totalAmount == 0">0</span>
          <span v-else>{{ (importForm.totalAmount - importForm.settledAmount).toFixed(2) }}</span>
        </el-descriptions-item>
 
        <el-descriptions-item v-if="dispIshow" label="" align="center">
        </el-descriptions-item>
 
        <el-descriptions-item v-if="dispIshow" label="" align="center">
        </el-descriptions-item>
 
      </el-descriptions>
    </el-form>
 
    <div v-if="dispIshow" style="text-align: center;margin-top: 20px;">
      <el-button @click="cancel">取 消</el-button>
      <el-button type="primary" @click="submitFormTow">确 定</el-button>
    </div>
    <h2 style="margin: 15px;font-size: 15px;">
      关联明细
    </h2>
    <avue-crud :option="newOption" :data="newTableData" v-model:search="newFormData" :page="newPageF"
      :table-loading="itemTableLoading2" @search-change="newSearchChange" ref="newTableRef"
      @search-reset="newRsetChange" @current-change="handleAttachmentCurrentChange"
      @size-change="handleAttachmentSizeChange" @on-load="newOnLoad">
 
      <template #menu="{ size, row, index }">
        <el-link class="link-btn" type="primary" :underline="false" plain @click="handleRelevance(row)"
          v-hasPermi="['cwgl:estimatedReceivableBill:relevancy']"> 取消关联
        </el-link>
      </template>
 
    </avue-crud>
 
 
    <div v-if="!noIshow" style="text-align: right;margin-top: 20px;">
      <el-button @click="cancel">取 消</el-button>
    </div>
 
  </el-dialog>
 
  <flowLog ref="flowLogIshow" :fileNameIshow="true" :flowParams="flowParams"></flowLog>
 
 
</template>
 
<script setup name="estimatedReceivableBill" lang="ts">
import {
  EstimatedReceivableBillI, addEstimatedReceivableBill, delEstimatedReceivableBill, exportEstimatedReceivableBill, getEstimatedReceivableBill, listEstimatedReceivableBill, updateEstimatedReceivableBill,
  estimatedReceivableBillSettlement, addEstimatedReceivableLog, cancelRelevancy, listEstimatedReceivableBillLog, updateEstimatedReceivableBillNmae
} from "@/api/cwgl/estimatedReceivableBill";
import useCurrentInstance from "@/utils/useCurrentInstance";
import { computed, reactive, ref, toRefs } from "vue";
import {
  getSelectCustomNam,
} from "@/api/cwgl/pendingSettlementBusiness";
import { PagesInterface, PageQueryInterface } from "@/utils/globalInterface";
import { usePagePlus } from "@/hooks/usePagePlus";
import { hasPermission } from "@/utils/permissionUtils";
import {
  getPendingSettlementBusiness, listPendingSettlementBusiness
} from "@/api/cwgl/pendingSettlementBusiness";
const { proxy } = useCurrentInstance();
const crudRef = ref();
 
const permissionList = computed(() => {
  return {
    addBtn: hasPermission(["cwgl:estimatedReceivableBill:add"]),
    delBtn: hasPermission(["cwgl:estimatedReceivableBill:remove"]),
    editBtn: hasPermission(["cwgl:estimatedReceivableBill:edit"]),
    viewBtn: hasPermission(["cwgl:estimatedReceivableBill:query"]),
  }
})
const dispIshow = ref(false)
const data = reactive({
  form: <EstimatedReceivableBillI>{},
  queryParams: <EstimatedReceivableBillI & PageQueryInterface>{},
  page: <PagesInterface>{
    pageSize: 10,
    total: 0,
    currentPage: 1,
  },
  selectionList: [],
  newForm: <EstimatedReceivableI>{
    pageNum: 1,
    pageSize: 10
  },
  importForm: {},
  newTableData: [],
  newFormData: {
    pageNum: 1,
    pageSize: 10
  },
  itemTableLoading2: false,
  rules: {
    settlementAmount: [
      { required: true, message: '请输入本次结算金额', trigger: 'blur' }
    ],
 
  },
})
const { queryParams, form, page, selectionList, newForm, importForm, newTableData, itemTableLoading2, newFormData, rules } = toRefs(data);
const option = ref({
  pageKey: 'EstimatedReceivableBill',
  rowKey: 'id',
 
  searchSpan: 5,
  editDisplay: false,
 
  addBtn: false,
  editBtn: false,
  delBtn: false,
  viewBtn: false,
 
  searchLabelWidth: 100,
  labelWidth: 120,
 
  column: {
    // id: {
    //   label: 'ID',
    // },
    billSystemNo: {
      label: '账单系统编号',
       showOverflowTooltip: true,
      search: true,
      rules: [
        {
          required: true,
          message: "账单系统编号不能为空", trigger: "blur"
        }
      ],
    },
    billName: {
      label: '账单名称',
       minWidth: 200,
      showOverflowTooltip: true,
      rules: [
        {
          required: true,
          message: "账单名称不能为空", trigger: "blur"
        }
      ],
    },
 
    customerName: {
      label: '客户名称',
      search: true,
      minWidth: 220,
      search: true,
      showOverflowTooltip: true,
      type: 'select',           // 设置为下拉框类型
      dicData: [], // 使用 selectCustomName 作为数据源
      disabled: false  // 根据需要设置是否禁用
    },
 
    dispatchCount: {
      label: '调度单数量',
    },
    totalAmount: {
      label: '应结算金额',
    },
    settledAmount: {
      label: '已结算金额',
    },
    invoiceStatus: {
      label: '开票状态',
      search: true,
      dataType: 'string',
      type: 'select',
      dicUrl: '/system/dict/data/type/sys_ticket_status',
    },
    // attachment: {
    //   label: '附件地址',
    //   type: 'textarea', minRows: 3, maxRows: 5,
    // },
    status: {
      label: '状态',
      search: true,
      dataType: 'string',
      type: 'select',
      dicUrl: '/system/dict/data/type/sys_final_statement_status',
    },
    // remark: {
    //   label: '备注',
    //   type: 'textarea', minRows: 3, maxRows: 5,
    // },
    // createBy: {
    //   label: '创建人',
    // },
    // confirmTime: {
    //   label: '确认时间',
    // },
    // createTime: {
    //   label: '创建时间',
    // },
    // updateTime: {
    //   label: '更新时间',
    // },
    // deleted: {
    //   label: '删除标记(0:正常;1:删除)',
    // },
  }
})
 
const newOption = ref({
  pageKey: 'PendingSettlementBusiness',
  rowKey: 'id',
  searchSpan: 5,
  selectionType: 'single',
  selectType: 'radio',
  editDisplay: false,
  addBtn: false,
  editBtn: false,
  selection: false,
  delBtn: false,
  menu: false,
  viewBtn: false,
  header: false,
  // searchLabelWidth: 100,
  // labelWidth: 120,
  column: {
    projectName: {
      label: '项目名称',
    },
    dispatchNo: {
      label: '调度单号',
    },
    createdTime: {
      label: '下单时间',
    },
    estimatedTotalIncome: {
      label: '预估应收金额',
    },
    currency: {
      label: '币制',
    },
    // customerName: {
    //   label: '客户名称',
    //   search: true,
    // },
 
 
  }
})
const { tableData, pageF, rowSave, rowUpdate, rowDel, beforeOpen, searchChange,
  searchReset, selectionChange, onLoad, currentChange, sizeChange, handleDelete, handleExport, handleUpdate, refreshChange } = usePagePlus({
    form: form,
    option: option,
    queryParams: queryParams,
    idKey: 'id',
    page: page.value,
    getListApi: listEstimatedReceivableBill,
    getDetailApi: getEstimatedReceivableBill,
    exportApi: exportEstimatedReceivableBill,
    deleteApi: delEstimatedReceivableBill,
    addApi: addEstimatedReceivableBill,
    updateApi: updateEstimatedReceivableBill,
    handleUpdateFunc: () => {
      crudRef.value.rowEdit(selectionList.value[0]);
    },
    handleSelectionChangeFunc: (selection: any) => {
      selectionList.value = selection;
    },
 
 
  })
const dialog = reactive({
  visible: false,
  title: '',
})
const newTableRef = ref();
const handleclose = (row) => {
  newFormData.value.billId = row.id;
  dispIshow.value = false;
  newOption.value.menu = false;
  noIshow.value = true;
  listPendingSettlementBusiness({ billId: row.id }).then((res) => {
    if (res.code === 200) {
      newForm.value.id = row.id;
      importForm.value = row;
      dialog.visible = true;
      newPageF.value.total = res.total || 0;
      newTableData.value = res.rows || [];
      newTableData.value.map(item => {
        item.currency = '人民币';
      });
      newTableRef.value.refreshTable();
      dialog.title = '应收账单结算';
    }
  })
 
  // crudRef.value.close();
}
 
const handleAmend = (row) => {
  newFormData.value.billId = row.id;
  importForm.value.billId = row.id;
  dispIshow.value = true;
  newOption.value.menu = true;
  listPendingSettlementBusiness({ billId: row.id }).then((res) => {
    if (res.code === 200) {
      newForm.value.id = row.id;
      importForm.value = row;
      dialog.visible = true;
      newPageF.value.total = res.total || 0;
      newTableData.value = res.rows || [];
      newTableData.value.map(item => {
        item.currency = '人民币';
      });
      newTableRef.value.refreshTable();
      dialog.title = '应收账单修改';
    }
  })
}
const noIshow = ref(false)
const handleBillSystemNo = (row) => {
  newFormData.value.billId = row.id;
  dispIshow.value = false;
  noIshow.value = false;
  newOption.value.menu = false;
  listPendingSettlementBusiness({ billId: row.id }).then((res) => {
    if (res.code === 200) {
      importForm.value = row;
      dialog.visible = true;
      dialog.title = '账单详情';
      newPageF.value.total = res.total || 0;
      newTableData.value = res.rows || [];
      newTableData.value.map(item => {
        item.currency = '人民币';
      });
      newTableRef.value.refreshTable();
    }
  })
}
const newFormRef = ref();
const submitForm = () => {
  if (newTableData.value.length == 0) {
    proxy.$message.error('无关联明细,无法结算');
    return; // 添加 return 中断执行
  } else {
    newFormRef.value!.validate(valid => {
      if (valid) {
        // 添加校验逻辑:本次结算金额不能大于应结算金额
        const settlementAmount = parseFloat(newForm.value.settlementAmount);
        const totalAmount = parseFloat(importForm.value.totalAmount);
 
        // 检查输入是否为有效数字
        if (isNaN(settlementAmount) || isNaN(totalAmount)) {
          proxy.$message.error('金额格式不正确');
          return;
        }
 
        if (settlementAmount > totalAmount) {
          proxy.$message.error('本次结算金额不能大于应结算金额');
          return; // 关键:在这里添加 return 中断后续执行
        }
 
        let data = {
          billId: newForm.value.id,
          fileName: newForm.value.attachment
        }
       if (newForm.value.attachment == null || newForm.value.attachment === '' || newForm.value.attachment === undefined) {
             estimatedReceivableBillSettlement(newForm.value).then((res) => {
              if (res.code === 200) {
                onLoad(page.value);
                proxy.$message.success('操作成功');
                dialog.visible = false;
                newForm.value = {};
              }
            })
        }else{ 
               addEstimatedReceivableLog(data).then((res1) => {
          if (res1.code === 200) {
            estimatedReceivableBillSettlement(newForm.value).then((res) => {
              if (res.code === 200) {
                onLoad(page.value);
                proxy.$message.success('操作成功');
                dialog.visible = false;
                newForm.value = {};
              }
            })
          }
        })
        }
 
   
      } else {
        // 表单验证失败
        return false;
      }
    });
  }
}
const submitFormTow = () => {
  proxy.$modal.confirm(`是否确认修改账单名称?`).then(function () {
    return updateEstimatedReceivableBillNmae(importForm.value);
  }).then((res) => {
    onLoad(page.value);
    proxy.$modal.msgSuccess(res.msg);
  })
 
}
const storagesTransferRef = ref();
const cancel = () => {
  newForm.value = {};
  dialog.visible = false;
  proxy.resetForm(storagesTransferRef.value)
}
 
 
const newPageF = ref<PagesInterface>({
  total: 0,
  pageSize: 10
})
 
const newSearchChange = (params, done) => {
  // itemTableLoading2.value = true;
  // listPendingSettlementBusiness(newForm.value).then((res) => {
  //   if (res.code === 200) {
  //     done()
  //     newTableData.value = res.rows || [];
  //     newPageF.value.total = res.total || 0;
  //   }
  //   itemTableLoading2.value = false;
  // })
}
const newRsetChange = (done) => {
  getEstimatedReceivableCancel()
}
// 处理附件分页页码变化
const handleAttachmentCurrentChange = (currentPage: number) => {
  newFormData.value.pageNum = currentPage;
  getEstimatedReceivableCancel();
}
// 处理附件分页大小变化
const handleAttachmentSizeChange = (pageSize: number) => {
  newFormData.value.pageSize = pageSize;
  getEstimatedReceivableCancel();
}
const newOnLoad = (newPageF) => {
  getEstimatedReceivableCancel(newPageF);
}
const getEstimatedReceivableCancel = () => {
  itemTableLoading2.value = true;
  listPendingSettlementBusiness(newFormData.value).then((res) => {
    if (res.code === 200) {
      newTableData.value = res.rows || [];
      newTableData.value.map(item => {
        item.currency = '人民币';
      });
      newTableRef.value.refreshTable();
      newPageF.value.total = res.total || 0;
    }
    itemTableLoading2.value = false;
  })
}
 
const handleRelevance = (row) => {
  proxy.$modal.confirm(`是否取消关联成功该调度号 :${row.dispatchNo}?`).then(function () {
    return cancelRelevancy(row.id);
  }).then((res) => {
    newOnLoad(newPageF.value);
    proxy.$modal.msgSuccess(res.msg);
  })
 
}
 
const flowLogIshow = ref()
const flowParams = ref([])
const handleFlow = (row: string) => {
  let data = {
    billId: row.id,
  }
  listEstimatedReceivableBillLog(data).then((res) => {
    flowParams.value = res.rows
    flowLogIshow.value.openModel()
 
  })
}
 
const selectCustomName = ref([]);
const getSelectCustomName = () => {
  getSelectCustomNam().then((res) => {
    if (res.code === 200) {
      // selectCustomName.value = res.data;
      selectCustomName.value = res.data.map(item => ({
        dictLabel: item,
        dictValue: item
      }));
      option.value.column.customerName.dicData = selectCustomName.value || [];
    }
  })
}
getSelectCustomName()
</script>
<style scoped>
::v-deep .el-descriptions__body .el-descriptions__table.is-bordered .el-descriptions__cell {
  border: var(--el-descriptions-table-border);
  padding: 8px 11px;
  width: 200px;
}
:deep(.avue-crud__table) {
  overflow-y: auto;
}
 
:deep(.el-scrollbar__bar.is-horizontal) {
  pointer-events: auto;
}
</style>