liding
6 天以前 6ff8faad4a183eaa35fac526e4e29a1c6176ff15
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
<template>
  <div class="reconciliation-workspace">
    <div class="workspace-heading">
      <h2>财务对账</h2>
      <p>比对收支、资金流水与外部凭证,记录差异处理方案并归档。</p>
    </div>
    <el-form inline :model="query">
      <el-form-item label="对账类型"
        ><el-select v-model="query.reconType" clearable style="width: 150px"
          ><el-option
            v-for="(label, key) in reconTypeText"
            :key="key"
            :label="label"
            :value="key" /></el-select
      ></el-form-item>
      <el-form-item label="状态"
        ><el-select v-model="query.status" clearable style="width: 130px"
          ><el-option
            v-for="(label, key) in statusText"
            :key="key"
            :label="label"
            :value="key" /></el-select
      ></el-form-item>
      <el-form-item label="对象"
        ><el-input v-model="query.target" clearable
      /></el-form-item>
      <el-form-item
        ><el-button type="primary" @click="loadTasks">查询</el-button
        ><el-button @click="openCreate">发起对账</el-button></el-form-item
      >
    </el-form>
 
    <el-alert
      v-if="loadError"
      :title="loadError"
      type="error"
      show-icon
      :closable="false"
      class="load-error"
    />
    <el-table
      :data="tasks"
      border
      v-loading="loading"
      empty-text="暂无对账任务,可点击“发起对账”创建"
    >
      <el-table-column prop="id" label="任务号" width="80" />
      <el-table-column label="类型"
        ><template #default="{ row }">{{
          reconTypeText[row.reconType]
        }}</template></el-table-column
      >
      <el-table-column label="期间" min-width="190"
        ><template #default="{ row }"
          >{{ row.periodStart }} 至 {{ row.periodEnd }}</template
        ></el-table-column
      >
      <el-table-column prop="target" label="对账对象" />
      <el-table-column prop="systemAmount" label="系统金额" />
      <el-table-column prop="externalAmount" label="对方金额" />
      <el-table-column prop="diffAmount" label="差额" />
      <el-table-column label="结果"
        ><template #default="{ row }"
          ><el-tag :type="row.result === '0' ? 'success' : 'danger'">{{
            row.result === "0" ? "一致" : "有差异"
          }}</el-tag></template
        ></el-table-column
      >
      <el-table-column label="状态"
        ><template #default="{ row }">{{
          statusText[row.status]
        }}</template></el-table-column
      >
      <el-table-column label="操作" width="260" fixed="right"
        ><template #default="{ row }">
          <el-button link type="primary" @click="showDiff(row)"
            >差异明细</el-button
          >
          <el-button
            link
            type="primary"
            :disabled="row.status === '2'"
            @click="openHandle(row)"
            >处理</el-button
          >
          <el-button
            link
            type="success"
            :disabled="row.status === '2'"
            @click="archive(row)"
            >归档</el-button
          >
          <el-button link @click="exportDiff(row)">导出</el-button>
        </template></el-table-column
      >
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page="query.current"
      :limit="query.size"
      @pagination="
        (p) => {
          query.current = p.page;
          query.size = p.limit;
          loadTasks();
        }
      "
    />
 
    <el-dialog v-model="createVisible" title="发起对账" width="760px">
      <el-form :model="createForm" label-width="100px">
        <el-form-item label="对账类型"
          ><el-select v-model="createForm.reconType"
            ><el-option
              v-for="(label, key) in reconTypeText"
              :key="key"
              :label="label"
              :value="key" /></el-select
        ></el-form-item>
        <el-form-item label="对账期间"
          ><el-date-picker
            v-model="period"
            type="daterange"
            value-format="YYYY-MM-DD"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
        /></el-form-item>
        <el-form-item label="资金账户"
          ><el-select v-model="createForm.accountId" clearable
            ><el-option
              v-for="a in accounts"
              :key="a.id"
              :label="a.accountName"
              :value="a.id" /></el-select
        ></el-form-item>
        <el-form-item label="对账对象"
          ><el-input
            v-model="createForm.target"
            placeholder="银行/供应商/客户名称"
        /></el-form-item>
      </el-form>
      <template v-if="createForm.reconType !== '0'">
        <el-divider content-position="left">外部流水(手工录入)</el-divider>
        <div class="external-actions">
          <el-button size="small" @click="addExternal">新增外部流水</el-button>
        </div>
        <el-table :data="createForm.externalList" border max-height="260">
          <el-table-column label="日期" width="145"
            ><template #default="{ row }"
              ><el-date-picker
                v-model="row.extDate"
                value-format="YYYY-MM-DD"
                style="width: 125px" /></template
          ></el-table-column>
          <el-table-column label="往来单位"
            ><template #default="{ row }"
              ><el-input v-model="row.extCounterparty" /></template
          ></el-table-column>
          <el-table-column label="方向" width="100"
            ><template #default="{ row }"
              ><el-select v-model="row.direction"
                ><el-option label="收入" :value="1" /><el-option
                  label="支出"
                  :value="-1" /></el-select></template
          ></el-table-column>
          <el-table-column label="金额" width="140"
            ><template #default="{ row }"
              ><el-input-number
                v-model="row.amount"
                :min="0.01"
                :precision="2"
                style="width: 120px" /></template
          ></el-table-column>
          <el-table-column label="凭证号"
            ><template #default="{ row }"
              ><el-input v-model="row.voucherNo" /></template
          ></el-table-column>
          <el-table-column width="60"
            ><template #default="{ $index }"
              ><el-button
                link
                type="danger"
                @click="createForm.externalList.splice($index, 1)"
                >删</el-button
              ></template
            ></el-table-column
          >
        </el-table>
      </template>
      <template #footer
        ><el-button @click="createVisible = false">取消</el-button
        ><el-button type="primary" @click="submitTask"
          >开始比对</el-button
        ></template
      >
    </el-dialog>
 
    <el-drawer v-model="diffVisible" title="对账差异明细" size="70%">
      <el-descriptions v-if="currentTask" :column="4" border class="summary">
        <el-descriptions-item label="任务号">{{
          currentTask.id
        }}</el-descriptions-item
        ><el-descriptions-item label="系统金额">{{
          currentTask.systemAmount
        }}</el-descriptions-item
        ><el-descriptions-item label="对方金额">{{
          currentTask.externalAmount
        }}</el-descriptions-item
        ><el-descriptions-item label="差额">{{
          currentTask.diffAmount
        }}</el-descriptions-item>
      </el-descriptions>
      <el-descriptions
        v-if="currentTask?.handleNote"
        :column="1"
        border
        class="summary"
      >
        <el-descriptions-item label="处理方案">{{
          currentTask.handleNote
        }}</el-descriptions-item>
      </el-descriptions>
      <el-table :data="diffs" border>
        <el-table-column label="差异类型"
          ><template #default="{ row }">{{
            diffTypeText[row.diffType]
          }}</template></el-table-column
        >
        <el-table-column prop="bizType" label="业务类型" /><el-table-column
          prop="bizId"
          label="业务ID"
        /><el-table-column prop="bizDate" label="日期" /><el-table-column
          prop="counterparty"
          label="往来单位"
        /><el-table-column
          prop="systemAmount"
          label="系统金额"
        /><el-table-column
          prop="externalAmount"
          label="对方金额"
        /><el-table-column prop="remark" label="说明" min-width="190" />
      </el-table>
      <el-divider content-position="left">外部凭证</el-divider>
      <el-table :data="externals" border
        ><el-table-column prop="extDate" label="日期" /><el-table-column
          prop="extCounterparty"
          label="往来单位" /><el-table-column
          prop="amount"
          label="金额" /><el-table-column prop="direction" label="方向"
          ><template #default="{ row }">{{
            row.direction === 1 ? "收入" : "支出"
          }}</template></el-table-column
        ><el-table-column prop="voucherNo" label="凭证号"
      /></el-table>
    </el-drawer>
 
    <el-dialog v-model="handleVisible" title="填写处理方案" width="520px">
      <el-input
        v-model="handleForm.handleNote"
        type="textarea"
        :rows="5"
        placeholder="请输入差异处理方案"
      />
      <template #footer
        ><el-button @click="handleVisible = false">取消</el-button
        ><el-button type="primary" @click="saveHandle"
          >保存并标记处理中</el-button
        ></template
      >
    </el-dialog>
  </div>
</template>
 
<script setup>
import { ref, reactive, onMounted, nextTick } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { saveAs } from "file-saver";
import pagination from "@/components/PIMTable/Pagination.vue";
import { getFinanceAccountList } from "@/api/financialManagement/fundsManagement";
import {
  getReconciliationTaskPage,
  createReconciliationTask,
  getReconciliationDiff,
  getReconciliationExternal,
  handleReconciliationTask,
  archiveReconciliationTask,
  exportReconciliationDiff,
} from "@/api/financialManagement/financialReconciliation";
 
const reconTypeText = {
    0: "内部对账",
    1: "银行对账",
    2: "供应商对账",
    3: "客户对账",
  },
  statusText = { 0: "待处理", 1: "处理中", 2: "已归档" },
  diffTypeText = {
    0: "系统有外部无",
    1: "外部有系统无",
    2: "金额不符",
    3: "日期不符",
  };
const tasks = ref([]),
  total = ref(0),
  loading = ref(false),
  loadError = ref(""),
  accounts = ref([]),
  createVisible = ref(false),
  diffVisible = ref(false),
  handleVisible = ref(false),
  period = ref([]),
  diffs = ref([]),
  externals = ref([]),
  currentTask = ref(null);
const query = reactive({
    current: 1,
    size: 10,
    reconType: "",
    status: "",
    target: "",
  }),
  createForm = reactive({
    reconType: "0",
    accountId: null,
    target: "",
    externalList: [],
  }),
  handleForm = reactive({ id: null, handleNote: "" });
const loadTasks = async () => {
  loading.value = true;
  loadError.value = "";
  try {
    const r = await getReconciliationTaskPage(query);
    tasks.value = r.data?.records || [];
    total.value = r.data?.total || 0;
  } catch (error) {
    tasks.value = [];
    total.value = 0;
    loadError.value =
      error?.message ||
      error?.msg ||
      "对账任务加载失败,请检查后端服务及数据库脚本";
  } finally {
    loading.value = false;
  }
};
const openCreate = () => {
  Object.assign(createForm, {
    reconType: "0",
    accountId: null,
    target: "",
    externalList: [],
  });
  period.value = [];
  createVisible.value = true;
};
const addExternal = () =>
  createForm.externalList.push({
    extDate: "",
    extCounterparty: "",
    amount: null,
    direction: 1,
    voucherNo: "",
    remark: "",
  });
const submitTask = async () => {
  if (period.value.length !== 2) {
    ElMessage.warning("请选择对账期间");
    return;
  }
  if (createForm.reconType !== "0" && !createForm.target.trim()) {
    ElMessage.warning("请输入银行、供应商或客户名称");
    return;
  }
  if (
    createForm.reconType !== "0" &&
    createForm.externalList.some(
      (row) => !row.extDate || !row.amount || row.amount <= 0
    )
  ) {
    ElMessage.warning("请填写外部凭证的日期和正数金额");
    return;
  }
  try {
    await createReconciliationTask({
      ...createForm,
      periodStart: period.value[0],
      periodEnd: period.value[1],
    });
    ElMessage.success("对账任务已生成");
    createVisible.value = false;
    await loadTasks();
  } catch (error) {
    ElMessage.error(error?.message || "对账任务生成失败");
  }
};
const showDiff = async (row) => {
  currentTask.value = row;
  const [d, e] = await Promise.all([
    getReconciliationDiff(row.id),
    getReconciliationExternal(row.id),
  ]);
  diffs.value = d.data || [];
  externals.value = e.data || [];
  diffVisible.value = true;
};
const openHandle = (row) => {
  handleForm.id = row.id;
  handleForm.handleNote = row.handleNote || "";
  handleVisible.value = true;
};
const saveHandle = async () => {
  await handleReconciliationTask(handleForm.id, {
    handleNote: handleForm.handleNote,
    status: "1",
  });
  ElMessage.success("处理方案已保存");
  handleVisible.value = false;
  loadTasks();
};
const archive = async (row) => {
  if (row.result === "1" && !row.handleNote?.trim()) {
    ElMessage.warning("请先填写差异处理方案");
    return;
  }
  try {
    await ElMessageBox.confirm(
      "归档后该任务将进入已归档状态,是否继续?",
      "归档"
    );
    await archiveReconciliationTask(row.id);
    ElMessage.success("已归档");
    await loadTasks();
  } catch (error) {
    if (error !== "cancel" && error !== "close") {
      ElMessage.error(error?.message || "归档失败");
    }
  }
};
const exportDiff = async (row) => {
  const blob = await exportReconciliationDiff(row.id);
  saveAs(blob, `对账差异-${row.id}.xlsx`);
};
onMounted(() => {
  nextTick(() => {
    loadTasks();
    getFinanceAccountList()
      .then((r) => {
        accounts.value = r.data || [];
      })
      .catch((error) => {
        accounts.value = [];
        console.error("资金账户加载失败:", error);
      });
  });
});
</script>
 
<style scoped>
.reconciliation-workspace {
  padding: 4px;
}
.workspace-heading {
  margin-bottom: 16px;
}
.workspace-heading h2 {
  margin: 0 0 6px;
  font-size: 20px;
}
.workspace-heading p {
  margin: 0;
  color: #606266;
}
.load-error {
  margin-bottom: 12px;
}
.external-actions {
  margin-bottom: 8px;
}
.summary {
  margin-bottom: 16px;
}
</style>