160 lines
6.1 KiB
Vue
160 lines
6.1 KiB
Vue
<template>
|
||
<el-dialog
|
||
v-model="visible"
|
||
:title="dialogTitle"
|
||
width="min(1500px, 96vw)"
|
||
append-to-body
|
||
destroy-on-close
|
||
>
|
||
<basic-table
|
||
:columns="columns"
|
||
:search-columns="searchColumns"
|
||
:query="queryBills"
|
||
:extra-params="fixedParams"
|
||
:selection="false"
|
||
:show-toolbar="false"
|
||
:border="true"
|
||
:max-height="560"
|
||
:page-size="10"
|
||
ref="tableRef"
|
||
row-key="arBillId"
|
||
>
|
||
<template #search-extra>
|
||
<el-button
|
||
type="warning"
|
||
icon="Download"
|
||
@click="handleExport"
|
||
v-hasPermi="['customersupplier:customerinfo:export']"
|
||
>导出</el-button>
|
||
</template>
|
||
<template #pagination-extra>
|
||
<div class="bill-summary">
|
||
<span>应收总额:<b class="amount">{{ money(billSummary.totalAmount) }}</b></span>
|
||
<span>已核销:<b class="written">{{ money(billSummary.writtenOffAmount) }}</b></span>
|
||
<span>未核销:<b class="unwritten">{{ money(billSummary.unwrittenAmount) }}</b></span>
|
||
</div>
|
||
</template>
|
||
<template #col-status="{ row }">
|
||
<el-tag :type="statusType(row.status)">{{ statusText(row.status) }}</el-tag>
|
||
</template>
|
||
<template #col-totalAmount="{ row }">
|
||
<span class="amount">{{ money(row.totalAmount) }}</span>
|
||
</template>
|
||
<template #col-writtenOffAmount="{ row }">
|
||
<span class="written">{{ money(row.writtenOffAmount) }}</span>
|
||
</template>
|
||
<template #col-unwrittenAmount="{ row }">
|
||
<span class="unwritten">{{ money(row.unwrittenAmount) }}</span>
|
||
</template>
|
||
</basic-table>
|
||
<template #footer>
|
||
<el-button @click="visible = false">关闭</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { computed, getCurrentInstance, ref } from 'vue'
|
||
import { listCustomerBills } from '@/api/customersuppliermanagement/customermoney/customerbill'
|
||
import { AR_BILL_STATUS_OPTIONS, AR_BILL_STATUS_TYPES } from '@/constants/ar/bill'
|
||
import { arEnumLabel } from '@/constants/ar/enums'
|
||
|
||
const props = defineProps({
|
||
modelValue: { type: Boolean, default: false },
|
||
customerId: { type: [String, Number], required: true },
|
||
customerName: { type: String, default: '' }
|
||
})
|
||
const { proxy } = getCurrentInstance()
|
||
const emit = defineEmits(['update:modelValue'])
|
||
|
||
const visible = computed({
|
||
get: () => props.modelValue,
|
||
set: value => emit('update:modelValue', value)
|
||
})
|
||
const dialogTitle = computed(() => props.customerName ? `客户账单 - ${props.customerName}` : '客户账单')
|
||
|
||
// BasicTable merges these fixed parameters after search and pagination state.
|
||
const fixedParams = computed(() => ({ customerId: Number(props.customerId) }))
|
||
const tableRef = ref()
|
||
const billSummary = ref({ totalAmount: 0, writtenOffAmount: 0, unwrittenAmount: 0 })
|
||
let querySerial = 0
|
||
const statusOptions = AR_BILL_STATUS_OPTIONS
|
||
const columns = [
|
||
{ label: '账单号', prop: 'billNo', minWidth: 180, showOverflowTooltip: true },
|
||
{ label: '账单名称', prop: 'billName', minWidth: 180, showOverflowTooltip: true },
|
||
{ label: '客户名称', prop: 'customerName', minWidth: 130, showOverflowTooltip: true },
|
||
{ label: '客户编码', prop: 'customerCode', minWidth: 120, showOverflowTooltip: true },
|
||
{ label: '账单截止日', prop: 'billPeriodEnd', minWidth: 120, formatter: row => `截至 ${date(row.billPeriodEnd)}` },
|
||
{ label: '订单数', prop: 'orderCount', width: 80 },
|
||
{ label: '应收总额', prop: 'totalAmount', width: 120, align: 'right', slot: 'totalAmount' },
|
||
{ label: '已核销', prop: 'writtenOffAmount', width: 110, align: 'right', slot: 'writtenOffAmount' },
|
||
{ label: '未核销', prop: 'unwrittenAmount', width: 110, align: 'right', slot: 'unwrittenAmount' },
|
||
{ label: '状态', prop: 'status', width: 110, slot: 'status' },
|
||
{ label: '账单日期', prop: 'billDate', width: 120, formatter: row => date(row.billDate) }
|
||
]
|
||
const searchColumns = [
|
||
{ label: '账单号', prop: 'billNo', component: 'input', placeholder: '账单号', width: '180px' },
|
||
{ label: '账单名称', prop: 'billName', component: 'input', placeholder: '账单名称', width: '180px' },
|
||
{ label: '状态', prop: 'status', component: 'select', options: statusOptions, placeholder: '全部状态', width: '150px' },
|
||
{ label: '账单日期', prop: 'billDateRange', component: 'daterange', width: '300px' },
|
||
{ label: '账单截止日', prop: 'billPeriodEnd', component: 'date', width: '160px' }
|
||
]
|
||
|
||
function queryBills(params) {
|
||
const query = normalizeBillQuery(params)
|
||
const serial = ++querySerial
|
||
return listCustomerBills(props.customerId, query).then(response => {
|
||
if (serial === querySerial) {
|
||
billSummary.value = response.summary || { totalAmount: 0, writtenOffAmount: 0, unwrittenAmount: 0 }
|
||
}
|
||
return response
|
||
})
|
||
}
|
||
|
||
function handleExport() {
|
||
const query = normalizeBillQuery(tableRef.value?.getQueryParams() || {})
|
||
delete query.pageNum
|
||
delete query.pageSize
|
||
proxy.download(
|
||
`/customersupplier/customerbill/export/${props.customerId}`,
|
||
query,
|
||
`客户账单_${props.customerId}_${Date.now()}.xlsx`
|
||
)
|
||
}
|
||
|
||
function normalizeBillQuery(params) {
|
||
const query = { ...params }
|
||
const range = query.billDateRange
|
||
if (Array.isArray(range) && range.length === 2) {
|
||
query.billDateStart = range[0]
|
||
query.billDateEnd = range[1]
|
||
}
|
||
delete query.billDateRange
|
||
// The route parameter is authoritative; the customer ID cannot be changed by search/reset.
|
||
delete query.customerId
|
||
return query
|
||
}
|
||
|
||
function date(value) { return value ? String(value).slice(0, 10) : '-' }
|
||
function money(value) {
|
||
const amount = Number(value)
|
||
return Number.isNaN(amount) ? '-' : amount.toFixed(2)
|
||
}
|
||
function statusText(value) { return arEnumLabel(AR_BILL_STATUS_OPTIONS, value) }
|
||
function statusType(value) { return AR_BILL_STATUS_TYPES[value] || 'info' }
|
||
</script>
|
||
|
||
<style scoped>
|
||
.bill-summary {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 8px 20px;
|
||
color: var(--el-text-color-regular);
|
||
font-size: 13px;
|
||
}
|
||
.bill-summary b { font-weight: 600; }
|
||
.amount { color: #f56c6c; font-weight: 600; }
|
||
.written { color: var(--el-color-success); }
|
||
.unwritten { color: var(--el-color-warning); }
|
||
</style>
|