<template>
|
<div class="app-container">
|
<el-form :model="filters" :inline="true">
|
<el-form-item label="客户:">
|
<el-select v-model="filters.customerId" placeholder="请选择客户" clearable style="width: 200px;">
|
<el-option v-for="item in customerList" :key="item.id" :label="item.name" :value="item.id" />
|
</el-select>
|
</el-form-item>
|
<el-form-item label="对账期间:">
|
<el-date-picker v-model="filters.startMonth" type="month" placeholder="开始月份" value-format="YYYY-MM" style="width: 140px;" />
|
<span style="margin: 0 10px;">至</span>
|
<el-date-picker v-model="filters.endMonth" type="month" placeholder="结束月份" value-format="YYYY-MM" style="width: 140px;" />
|
</el-form-item>
|
<el-form-item>
|
<el-button type="primary" @click="getTableData">搜索</el-button>
|
<el-button @click="resetFilters">重置</el-button>
|
</el-form-item>
|
</el-form>
|
<div class="table_list">
|
<div class="actions">
|
<div>
|
<el-button type="primary" @click="generateStatement" icon="Document">生成对账单</el-button>
|
</div>
|
<div>
|
<el-button @click="handleOut" icon="Download">导出对账单</el-button>
|
</div>
|
</div>
|
<PIMTable
|
rowKey="id"
|
:column="columns"
|
:tableData="dataList"
|
:page="{
|
current: pagination.currentPage,
|
size: pagination.pageSize,
|
total: pagination.total,
|
}"
|
@pagination="changePage"
|
>
|
<template #beginBalance="{ row }">
|
<span :class="row.beginBalance >= 0 ? 'text-success' : 'text-danger'">¥{{ formatMoney(row.beginBalance) }}</span>
|
</template>
|
<template #currentReceivable="{ row }">
|
<span class="text-primary">¥{{ formatMoney(row.currentReceivable) }}</span>
|
</template>
|
<template #currentReceipt="{ row }">
|
<span class="text-success">¥{{ formatMoney(row.currentReceipt) }}</span>
|
</template>
|
<template #endBalance="{ row }">
|
<span :class="row.endBalance >= 0 ? 'text-success' : 'text-danger'">¥{{ formatMoney(row.endBalance) }}</span>
|
</template>
|
<template #operation="{ row }">
|
<el-button type="primary" link @click="viewDetail(row)">查看明细</el-button>
|
<el-button type="primary" link @click="printStatement(row)">打印</el-button>
|
</template>
|
</PIMTable>
|
</div>
|
|
<el-dialog title="对账明细" v-model="detailDialogVisible" width="900px" append-to-body>
|
<div class="statement-header">
|
<h3>{{ currentCustomer }} 应收对账单</h3>
|
<p>对账期间: {{ currentPeriod }}</p>
|
</div>
|
<el-table :data="detailData" border style="width: 100%">
|
<el-table-column prop="date" label="日期" width="120" />
|
<el-table-column prop="type" label="类型" width="100">
|
<template #default="{ row }">
|
<el-tag :type="row.type === '出库' ? 'success' : row.type === '退货' ? 'danger' : 'primary'">{{ row.type }}</el-tag>
|
</template>
|
</el-table-column>
|
<el-table-column prop="code" label="单据编号" width="150" />
|
<el-table-column prop="debit" label="借方(应收)" width="120">
|
<template #default="{ row }">
|
<span v-if="row.debit > 0" class="text-danger">¥{{ formatMoney(row.debit) }}</span>
|
<span v-else>-</span>
|
</template>
|
</el-table-column>
|
<el-table-column prop="credit" label="贷方(收款)" width="120">
|
<template #default="{ row }">
|
<span v-if="row.credit > 0" class="text-success">¥{{ formatMoney(row.credit) }}</span>
|
<span v-else>-</span>
|
</template>
|
</el-table-column>
|
<el-table-column prop="balance" label="余额" width="120">
|
<template #default="{ row }">
|
<span :class="row.balance >= 0 ? 'text-success' : 'text-danger'">¥{{ formatMoney(row.balance) }}</span>
|
</template>
|
</el-table-column>
|
<el-table-column prop="remark" label="备注" show-overflow-tooltip />
|
</el-table>
|
<template #footer>
|
<el-button @click="detailDialogVisible = false">关闭</el-button>
|
<el-button type="primary" @click="printDetail">打印</el-button>
|
</template>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script setup>
|
import { ref, reactive, onMounted } from "vue";
|
import { ElMessage } from "element-plus";
|
|
defineOptions({
|
name: "应收对账",
|
});
|
|
const filters = reactive({
|
customerId: "",
|
startMonth: "",
|
endMonth: "",
|
});
|
|
const pagination = reactive({
|
currentPage: 1,
|
pageSize: 10,
|
total: 0,
|
});
|
|
const columns = [
|
{ label: "对账单号", prop: "statementCode", width: "150" },
|
{ label: "客户名称", prop: "customerName", width: "180" },
|
{ label: "对账期间", prop: "period", width: "150" },
|
{ label: "期初余额", prop: "beginBalance", slot: "beginBalance" },
|
{ label: "本期应收", prop: "currentReceivable", slot: "currentReceivable" },
|
{ label: "本期收款", prop: "currentReceipt", slot: "currentReceipt" },
|
{ label: "期末余额", prop: "endBalance", slot: "endBalance" },
|
{ label: "操作", prop: "operation", slot: "operation", width: "150", fixed: "right" },
|
];
|
|
const dataList = ref([]);
|
const detailDialogVisible = ref(false);
|
const currentCustomer = ref("");
|
const currentPeriod = ref("");
|
const detailData = ref([]);
|
|
const customerList = [
|
{ id: 1, name: "北京科技有限公司" },
|
{ id: 2, name: "上海贸易公司" },
|
{ id: 3, name: "广州实业有限公司" },
|
{ id: 4, name: "深圳电子公司" },
|
];
|
|
const mockData = [
|
{ id: 1, statementCode: "DZ202401001", customerId: 1, customerName: "北京科技有限公司", period: "2024-01", beginBalance: 10000, currentReceivable: 15000, currentReceipt: 8000, endBalance: 17000 },
|
{ id: 2, statementCode: "DZ202401002", customerId: 2, customerName: "上海贸易公司", period: "2024-01", beginBalance: 5000, currentReceivable: 12000, currentReceipt: 10000, endBalance: 7000 },
|
{ id: 3, statementCode: "DZ202402001", customerId: 1, customerName: "北京科技有限公司", period: "2024-02", beginBalance: 17000, currentReceivable: 20000, currentReceipt: 15000, endBalance: 22000 },
|
];
|
|
const formatMoney = (value) => {
|
if (value === undefined || value === null) return "0.00";
|
return Number(value).toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
};
|
|
const getTableData = () => {
|
let result = [...mockData];
|
if (filters.customerId) {
|
result = result.filter(item => item.customerId === filters.customerId);
|
}
|
if (filters.startMonth && filters.endMonth) {
|
result = result.filter(item => item.period >= filters.startMonth && item.period <= filters.endMonth);
|
}
|
pagination.total = result.length;
|
dataList.value = result.slice((pagination.currentPage - 1) * pagination.pageSize, pagination.currentPage * pagination.pageSize);
|
};
|
|
const resetFilters = () => {
|
filters.customerId = "";
|
filters.startMonth = "";
|
filters.endMonth = "";
|
pagination.currentPage = 1;
|
getTableData();
|
};
|
|
const changePage = ({ current, size }) => {
|
pagination.currentPage = current;
|
pagination.pageSize = size;
|
getTableData();
|
};
|
|
const generateStatement = () => {
|
ElMessage.success("对账单生成成功");
|
const newId = mockData.length > 0 ? Math.max(...mockData.map(item => item.id)) + 1 : 1;
|
const customer = customerList[Math.floor(Math.random() * customerList.length)];
|
mockData.unshift({
|
id: newId,
|
statementCode: "DZ" + Date.now(),
|
customerId: customer.id,
|
customerName: customer.name,
|
period: "2024-03",
|
beginBalance: Math.floor(Math.random() * 10000),
|
currentReceivable: Math.floor(Math.random() * 20000),
|
currentReceipt: Math.floor(Math.random() * 15000),
|
endBalance: Math.floor(Math.random() * 20000),
|
});
|
getTableData();
|
};
|
|
const viewDetail = (row) => {
|
currentCustomer.value = row.customerName;
|
currentPeriod.value = row.period;
|
detailData.value = [
|
{ date: row.period + "-01", type: "期初", code: "-", debit: 0, credit: 0, balance: row.beginBalance, remark: "期初余额" },
|
{ date: row.period + "-05", type: "出库", code: "CK2024001", debit: 5000, credit: 0, balance: row.beginBalance + 5000, remark: "" },
|
{ date: row.period + "-10", type: "收款", code: "SK2024001", debit: 0, credit: 3000, balance: row.beginBalance + 2000, remark: "" },
|
{ date: row.period + "-15", type: "出库", code: "CK2024002", debit: 8000, credit: 0, balance: row.beginBalance + 10000, remark: "" },
|
{ date: row.period + "-20", type: "退货", code: "TH2024001", debit: 0, credit: 2000, balance: row.beginBalance + 8000, remark: "" },
|
{ date: row.period + "-25", type: "收款", code: "SK2024002", credit: row.currentReceipt - 3000, balance: row.endBalance, remark: "" },
|
];
|
detailDialogVisible.value = true;
|
};
|
|
const printStatement = (row) => {
|
ElMessage.info(`打印对账单: ${row.statementCode}`);
|
};
|
|
const printDetail = () => {
|
ElMessage.info("打印明细");
|
};
|
|
const handleOut = () => {
|
ElMessage.success("导出成功");
|
};
|
|
onMounted(() => {
|
getTableData();
|
});
|
</script>
|
|
<style lang="scss" scoped>
|
.actions {
|
display: flex;
|
justify-content: space-between;
|
margin-bottom: 15px;
|
}
|
|
.text-success {
|
color: #67c23a;
|
}
|
|
.text-danger {
|
color: #f56c6c;
|
}
|
|
.text-primary {
|
color: #409eff;
|
}
|
|
.statement-header {
|
text-align: center;
|
margin-bottom: 20px;
|
h3 {
|
margin: 0 0 10px 0;
|
}
|
p {
|
color: #909399;
|
margin: 0;
|
}
|
}
|
</style>
|