Files
tms-erp-web/src/views/payment/receipt-flow.vue
T
2026-09-02 03:22:51 +08:00

466 lines
16 KiB
Vue

<template>
<basic-container class="receipt-flow-page">
<section class="receipt-flow-page__search">
<el-form :model="query" label-position="right" label-width="88px" @submit.prevent>
<div class="receipt-flow-page__search-grid">
<el-form-item label="认领通知单">
<el-input v-model="query.receiptNoticeNo" clearable placeholder="请输入" />
</el-form-item>
<el-form-item label="对方户名">
<el-input v-model="query.counterpartyName" clearable placeholder="请输入" />
</el-form-item>
<el-form-item label="对方开户行">
<el-input v-model="query.counterpartyBank" clearable placeholder="请输入" />
</el-form-item>
<el-form-item label="对方账号">
<el-input v-model="query.counterpartyAccount" clearable placeholder="请输入" />
</el-form-item>
<el-form-item v-show="searchExpanded" label="摘要">
<el-input v-model="query.summary" clearable placeholder="请输入" />
</el-form-item>
<el-form-item v-show="searchExpanded" label="认领状态">
<el-select v-model="query.claimStatus" clearable placeholder="请选择">
<el-option
v-for="item in claimStatusOptions"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
<el-form-item v-show="searchExpanded" label="交易时间">
<el-date-picker
v-model="query.transactionTimeRange"
type="datetimerange"
value-format="YYYY-MM-DD HH:mm:ss"
range-separator="~"
start-placeholder="开始时间"
end-placeholder="结束时间"
clearable
/>
</el-form-item>
</div>
<div class="receipt-flow-page__search-actions">
<el-button @click="searchExpanded = !searchExpanded">
{{ searchExpanded ? '折叠' : '展开' }}
</el-button>
<el-button type="primary" @click="handleSearch">查询</el-button>
<el-button @click="resetSearch">重置</el-button>
</div>
</el-form>
</section>
<section class="receipt-flow-page__table-panel">
<div class="receipt-flow-page__toolbar">
<el-button
v-if="hasPermission('receipt_flow_sync')"
type="primary"
:loading="syncing"
@click="handleSync"
>
手动同步流水
</el-button>
<el-button
v-if="hasPermission('receipt_flow_claim')"
type="primary"
:disabled="!selectedRows.length"
@click="openBatchClaim"
>
批量认领
</el-button>
</div>
<el-table
v-loading="loading"
:data="rows"
border
@selection-change="selectedRows = $event"
>
<el-table-column type="selection" width="52" align="center" />
<el-table-column type="index" label="序号" width="64" align="center" />
<el-table-column
v-for="column in columns"
:key="column.prop"
v-bind="column"
align="center"
show-overflow-tooltip
>
<template #default="{ row }">
<el-link v-if="column.link" type="primary" @click="openDetail(row)">
{{ displayValue(row[column.prop]) }}
</el-link>
<el-tag
v-else-if="column.status"
:type="statusType(row.claimStatus)"
class="status-text"
>
{{ displayValue(row[column.prop]) }}
</el-tag>
<span v-else-if="column.money">{{ formatMoney(row[column.prop]) }}</span>
<span v-else>{{ displayValue(row[column.prop]) }}</span>
</template>
</el-table-column>
<el-table-column label="操作" width="120" fixed="right" align="center">
<template #default="{ row }">
<el-link v-if="canClaim(row)" type="primary" @click="openClaim(row)">认领</el-link>
<span v-else>-</span>
</template>
</el-table-column>
</el-table>
<div class="receipt-flow-page__pagination">
<el-pagination
v-model:current-page="page.current"
v-model:page-size="page.size"
:total="page.total"
:page-sizes="[10, 20, 50, 100]"
layout="total, sizes, prev, pager, next, jumper"
@current-change="loadTable"
@size-change="handleSizeChange"
/>
</div>
</section>
<el-dialog
v-model="detailDialog.visible"
title="收款流水详情"
width="960px"
append-to-body
destroy-on-close
>
<div v-loading="detailDialog.loading">
<el-descriptions :column="3" border>
<el-descriptions-item label="认领通知单">
{{ displayValue(detailDialog.data.receiptNoticeNo) }}
</el-descriptions-item>
<el-descriptions-item label="付款人">
{{ displayValue(detailDialog.data.payerName) }}
</el-descriptions-item>
<el-descriptions-item label="付款金额">
{{ formatMoney(detailDialog.data.receiptAmount) }}
</el-descriptions-item>
<el-descriptions-item label="交易时间">
{{ displayValue(detailDialog.data.transactionTime) }}
</el-descriptions-item>
<el-descriptions-item label="对方户名">
{{ displayValue(detailDialog.data.counterpartyName) }}
</el-descriptions-item>
<el-descriptions-item label="对方开户行">
{{ displayValue(detailDialog.data.counterpartyBank) }}
</el-descriptions-item>
<el-descriptions-item label="对方账号">
{{ displayValue(detailDialog.data.counterpartyAccount) }}
</el-descriptions-item>
<el-descriptions-item label="明细流水号">
{{ displayValue(detailDialog.data.detailSerialNo) }}
</el-descriptions-item>
<el-descriptions-item label="认领状态">
<el-tag :type="statusType(detailDialog.data.claimStatus)">
{{ displayValue(detailDialog.data.claimStatusName) }}
</el-tag>
</el-descriptions-item>
<el-descriptions-item label="已认领金额">
{{ formatMoney(detailDialog.data.claimedAmount) }}
</el-descriptions-item>
<el-descriptions-item label="剩余可认领金额">
{{ formatMoney(detailDialog.data.remainingAmount) }}
</el-descriptions-item>
<el-descriptions-item label="摘要">
{{ displayValue(detailDialog.data.summary) }}
</el-descriptions-item>
</el-descriptions>
<div class="dialog-section-title receipt-flow-page__detail-title">认领记录</div>
<el-table :data="detailDialog.claimRecords" border empty-text="暂无认领记录">
<el-table-column type="index" label="序号" width="64" align="center" />
<el-table-column prop="createTime" label="认领时间" min-width="170" align="center" />
<el-table-column label="认领金额" min-width="130" align="right">
<template #default="{ row }">{{ formatMoney(row.operationAmount) }}</template>
</el-table-column>
<el-table-column prop="operatorName" label="认领人" min-width="120" align="center" />
<el-table-column label="状态变化" min-width="170" align="center">
<template #default="{ row }">{{ claimStatusChange(row) }}</template>
</el-table-column>
<el-table-column prop="content" label="认领说明" min-width="220" />
</el-table>
</div>
<template #footer>
<el-button @click="detailDialog.visible = false">关闭</el-button>
</template>
</el-dialog>
</basic-container>
</template>
<script>
import { mapGetters } from 'vuex';
import * as api from '@/api/payment/receiptFlow';
import { receiptFlowTableColumns } from '@/option/payment/receiptFlow';
const receiptFlowMockTemplates = [
{
receiptNoticeNo: 'SKTZ20260827001',
payerName: '华东供应链管理有限公司',
receiptAmount: 48000,
counterpartyName: '上海安捷运输有限公司',
counterpartyAccount: '310000000000001001',
counterpartyBank: '中国工商银行上海分行',
summary: '运输服务款',
transactionTime: '2026-08-27 09:30:00',
detailSerialNo: 'MOCK-RF-20260827-001',
sourceUpdatedTime: '2026-08-27 09:30:00',
},
{
receiptNoticeNo: 'SKTZ20260827002',
payerName: '华东供应链管理有限公司',
receiptAmount: 26500,
counterpartyName: '江苏联运物流有限公司',
counterpartyAccount: '320100000000002002',
counterpartyBank: '中国建设银行南京分行',
summary: '物流服务款',
transactionTime: '2026-08-27 13:45:00',
detailSerialNo: 'MOCK-RF-20260827-002',
sourceUpdatedTime: '2026-08-27 13:45:00',
},
];
const randomDigits = length =>
Array.from({ length }, () => Math.floor(Math.random() * 10)).join('');
const formatMockDateTime = date => {
const pad = value => String(value).padStart(2, '0');
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(
date.getHours()
)}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
};
const createReceiptFlowMockRows = () => {
const count = 20 + Math.floor(Math.random() * 31);
return Array.from({ length: count }, (_, index) => {
const template = receiptFlowMockTemplates[index % receiptFlowMockTemplates.length];
const transactionDate = new Date();
transactionDate.setDate(transactionDate.getDate() - Math.floor(Math.random() * 7));
transactionDate.setHours(8 + Math.floor(Math.random() * 10), Math.floor(Math.random() * 60), 0);
const transactionTime = formatMockDateTime(transactionDate);
const dateCode = transactionTime.slice(0, 10).replaceAll('-', '');
return {
...template,
receiptNoticeNo: `SKTZ${dateCode}${randomDigits(5)}`,
receiptAmount: Math.floor(10000 + Math.random() * 90000),
counterpartyAccount: `${template.counterpartyAccount.slice(0, -6)}${randomDigits(6)}`,
transactionTime,
detailSerialNo: `MOCK-RF-${dateCode}-${index + 1}${randomDigits(4)}`,
sourceUpdatedTime: transactionTime,
};
});
};
const emptyQuery = () => ({
receiptNoticeNo: '',
counterpartyName: '',
counterpartyBank: '',
counterpartyAccount: '',
summary: '',
claimStatus: '',
transactionTimeRange: [],
});
export default {
name: 'ReceiptFlow',
data() {
return {
query: emptyQuery(),
claimStatusOptions: api.claimStatusOptions,
columns: receiptFlowTableColumns,
rows: [],
selectedRows: [],
loading: false,
syncing: false,
searchExpanded: false,
page: { current: 1, size: 10, total: 0 },
detailDialog: { visible: false, loading: false, data: {}, claimRecords: [] },
};
},
computed: {
...mapGetters(['permission', 'userInfo']),
isAdmin() {
const authority = this.userInfo?.authority;
return Array.isArray(authority)
? authority.includes('admin')
: String(authority || '').includes('admin');
},
},
mounted() {
this.loadTable();
},
methods: {
unwrapData(response) {
const body = response?.data || response || {};
return body?.data || body;
},
async loadTable() {
this.loading = true;
try {
const range = this.query.transactionTimeRange || [];
const data = this.unwrapData(
await api.getList(this.page.current, this.page.size, {
...this.query,
transactionTimeRange: undefined,
transactionStartTime: range[0],
transactionEndTime: range[1],
})
);
this.rows = data.records || [];
this.selectedRows = [];
this.page.total = Number(data.total || 0);
} finally {
this.loading = false;
}
},
handleSearch() {
this.page.current = 1;
this.loadTable();
},
resetSearch() {
this.query = emptyQuery();
this.handleSearch();
},
handleSizeChange() {
this.page.current = 1;
this.loadTable();
},
async handleSync() {
this.syncing = true;
try {
const mockRows = createReceiptFlowMockRows();
const syncedCount = Number(this.unwrapData(await api.sync({ flows: mockRows })) || 0);
this.$message.success(`流水同步完成,共同步${syncedCount}条`);
await this.loadTable();
} finally {
this.syncing = false;
}
},
async openDetail(row) {
this.detailDialog = {
visible: true,
loading: true,
data: { ...row },
claimRecords: [],
};
try {
const data = this.unwrapData(await api.getDetail(row.id));
this.detailDialog.data = data || {};
this.detailDialog.claimRecords = data?.claimRecords || [];
} finally {
this.detailDialog.loading = false;
}
},
openClaim(row) {
this.$router.push({
path: '/payment/receipt-flow/form',
query: { mode: 'add', id: row.id },
});
},
openBatchClaim() {
if (!this.selectedRows.length) {
this.$message.warning('请先勾选收款流水');
return;
}
const first = this.selectedRows[0];
const payerName = String(first.payerName || '').trim();
const counterpartyAccount = String(first.counterpartyAccount || '').trim();
const sameParty = this.selectedRows.every(
row =>
String(row.payerName || '').trim() === payerName &&
String(row.counterpartyAccount || '').trim() === counterpartyAccount
);
if (!sameParty) {
this.$message.warning('批量认领所选流水的付款人、对方账号必须一致');
return;
}
this.$router.push({
path: '/payment/receipt-flow/form',
query: {
mode: 'add',
batch: '1',
ids: this.selectedRows.map(row => row.id).join(','),
},
});
},
hasPermission(code) {
return this.isAdmin || this.validData(this.permission?.[code], false);
},
canClaim(row) {
return this.hasPermission('receipt_flow_claim') && Number(row.remainingAmount || 0) > 0;
},
statusType(status) {
return { claimed: 'success', partial: 'warning', unclaimed: 'info' }[status] || '';
},
claimStatusChange(row) {
const label = status =>
({ claimed: '认领完成', partial: '部分认领', unclaimed: '未认领' }[status] || '-');
return `${label(row.fromStatus)}${label(row.toStatus)}`;
},
displayValue(value) {
return value === null || value === undefined || value === '' ? '-' : value;
},
formatMoney(value) {
return Number(value || 0).toFixed(2);
},
},
};
</script>
<style scoped lang="scss">
.receipt-flow-page__search {
padding: 12px 12px 4px;
background: #fff;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}
.receipt-flow-page__search-grid {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 8px 24px;
}
.receipt-flow-page__search :deep(.el-form-item) {
margin-bottom: 8px;
}
.receipt-flow-page__search :deep(.el-input),
.receipt-flow-page__search :deep(.el-select),
.receipt-flow-page__search :deep(.el-date-editor) {
width: 100%;
}
.receipt-flow-page__search-actions {
display: flex;
justify-content: flex-end;
gap: 8px;
margin-bottom: 8px;
}
.receipt-flow-page__table-panel {
margin-top: 8px;
}
.receipt-flow-page__toolbar {
display: flex;
justify-content: flex-start;
align-items: center;
gap: 8px;
padding: 12px 0;
}
.receipt-flow-page__pagination {
display: flex;
justify-content: flex-end;
padding: 16px 0;
}
.receipt-flow-page__detail-title {
margin: 20px 0 12px;
}
.receipt-flow-page :deep(.el-table) {
--el-table-border-color: #eff1f7;
}
.receipt-flow-page :deep(.el-table__row:nth-child(even) > td.el-table__cell) {
background: #fafafa;
}
@media (max-width: 1200px) {
.receipt-flow-page__search-grid {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
}
</style>