✨ 限制应收账单毛利查询日期并调整筛选布局
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
function formatLocalDate(date) {
|
||||
const year = date.getFullYear()
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
return `${year}-${month}-${day}`
|
||||
}
|
||||
|
||||
// 次月没有对应日期时取月末,再减一天;起止日期均包含当天。
|
||||
export function maxEndDate(start) {
|
||||
const [year, month, day] = start.split('-').map(Number)
|
||||
const lastDayOfNextMonth = new Date(year, month + 1, 0).getDate()
|
||||
const limit = new Date(year, month, Math.min(day, lastDayOfNextMonth))
|
||||
limit.setDate(limit.getDate() - 1)
|
||||
return formatLocalDate(limit)
|
||||
}
|
||||
|
||||
export function defaultDateRange() {
|
||||
const end = new Date()
|
||||
const start = new Date(end.getFullYear(), end.getMonth(), end.getDate())
|
||||
const endText = formatLocalDate(end)
|
||||
start.setDate(start.getDate() - 31)
|
||||
while (maxEndDate(formatLocalDate(start)) < endText) start.setDate(start.getDate() + 1)
|
||||
return [formatLocalDate(start), endText]
|
||||
}
|
||||
@@ -1,17 +1,23 @@
|
||||
<template>
|
||||
<div class="app-container ar-profit-report">
|
||||
<el-card shadow="never">
|
||||
<el-form :model="query" inline @submit.prevent>
|
||||
<el-form-item label="账单日期">
|
||||
<el-date-picker v-model="dateRange" type="daterange" value-format="YYYY-MM-DD" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" />
|
||||
<el-card shadow="never" class="search-card">
|
||||
<el-form :model="query" label-width="88px" @submit.prevent>
|
||||
<el-row :gutter="16">
|
||||
<el-col :xs="24" :sm="12" :lg="8">
|
||||
<el-form-item label="账单日期" class="filter-item" :error="dateRangeError" required>
|
||||
<el-date-picker v-model="dateRange" type="daterange" value-format="YYYY-MM-DD" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" class="filter-control" />
|
||||
</el-form-item>
|
||||
<el-form-item label="客户">
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="12" :lg="8">
|
||||
<el-form-item label="客户" class="filter-item">
|
||||
<customer-select v-model="query.customerId" :fetch-options="listArBillCustomerOptions"
|
||||
placeholder="请输入客户名称或代码搜索" :remote-search="true" :page-size="20" />
|
||||
placeholder="请输入客户名称或代码搜索" :remote-search="true" :page-size="20" class="filter-control" />
|
||||
</el-form-item>
|
||||
<el-form-item label="销售员">
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="12" :lg="8">
|
||||
<el-form-item label="销售员" class="filter-item">
|
||||
<el-select v-model="query.salesUserId" placeholder="姓名或工号搜索" clearable filterable remote
|
||||
:remote-method="searchSales" :loading="salesLoading" style="width: 180px"
|
||||
:remote-method="searchSales" :loading="salesLoading" class="filter-control"
|
||||
@input="handleSalesInput">
|
||||
<el-option v-for="person in salesOptions" :key="person.userId" :label="person.name || person.code || String(person.userId)" :value="person.userId">
|
||||
<span>{{ person.name || person.code || person.userId }}</span>
|
||||
@@ -19,13 +25,21 @@
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="账单号"><el-input v-model="query.billNo" clearable @keyup.enter="search" /></el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="query.status" placeholder="全部状态" clearable style="width: 140px">
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="12" :lg="8">
|
||||
<el-form-item label="账单号" class="filter-item"><el-input v-model="query.billNo" clearable class="filter-control" @keyup.enter="search" /></el-form-item>
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="12" :lg="8">
|
||||
<el-form-item label="状态" class="filter-item">
|
||||
<el-select v-model="query.status" placeholder="全部状态" clearable class="filter-control">
|
||||
<el-option label="已确认" value="CONFIRMED" /><el-option label="部分核销" value="PARTIAL_WRITTEN_OFF" /><el-option label="已核销" value="WRITTEN_OFF" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item><el-button type="primary" icon="Search" @click="search">搜索</el-button><el-button icon="Refresh" @click="reset">重置</el-button></el-form-item>
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="12" :lg="8">
|
||||
<div class="filter-item filter-actions"><el-button type="primary" icon="Search" @click="search">搜索</el-button><el-button icon="Refresh" @click="reset">重置</el-button></div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form>
|
||||
</el-card>
|
||||
|
||||
@@ -179,6 +193,7 @@
|
||||
import { listArBillCustomerOptions } from '@/api/ar/bill'
|
||||
import { addArProfitRate, confirmArProfitMissingRate, listArProfitAreaRules, listArProfitBillDetails, listArProfitBills, listArProfitCommissions, listArProfitCommissionSummary, listArProfitFees, listArProfitMissingRates, listArProfitRates, listArProfitSalesOptions, listArProfitSummary, listArProfitWriteoffRates } from '@/api/report/arProfit'
|
||||
import { parseTime } from '@/utils/bms'
|
||||
import { defaultDateRange, maxEndDate } from '@/utils/reportDateRange'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
const { proxy } = getCurrentInstance()
|
||||
@@ -187,7 +202,11 @@ const salesOptions = ref([])
|
||||
const salesLoading = ref(false)
|
||||
let salesSearchVersion = 0
|
||||
const areaRules = ref({})
|
||||
const dateRange = ref(defaultBillDateRange())
|
||||
const dateRange = ref(defaultDateRange())
|
||||
const dateRangeError = computed(() => {
|
||||
if (!dateRange.value?.[0] || !dateRange.value?.[1]) return ''
|
||||
return dateRange.value[1] > maxEndDate(dateRange.value[0]) ? '账单日期最多查询一个月' : ''
|
||||
})
|
||||
const pageNum = ref(1), pageSize = ref(10), total = ref(0), rows = ref([]), loading = ref(false)
|
||||
const summaries = ref([]), summaryLoaded = ref(false)
|
||||
const detailsVisible = ref(false), detailsLoading = ref(false), details = ref([]), detailsTotal = ref(0)
|
||||
@@ -211,18 +230,20 @@ const missingRates = ref([]), missingTotal = ref(0), missingPage = ref(1), missi
|
||||
const confirmVisible = ref(false), confirmForm = reactive({ writeoffId: null, billNo: '', rate: null, remark: '' })
|
||||
const writeoffRatesVisible = ref(false), writeoffRatesLoading = ref(false), writeoffRates = ref([])
|
||||
|
||||
function formatLocalDate(offset) {
|
||||
const date = new Date()
|
||||
date.setDate(date.getDate() + offset)
|
||||
const year = date.getFullYear()
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
return `${year}-${month}-${day}`
|
||||
function validateDateRange(showMessage = true) {
|
||||
if (!dateRange.value?.[0] || !dateRange.value?.[1]) {
|
||||
if (showMessage) ElMessage.warning('请选择完整的账单日期')
|
||||
return false
|
||||
}
|
||||
if (dateRangeError.value) {
|
||||
if (showMessage) ElMessage.warning(dateRangeError.value)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
function defaultBillDateRange() { return [formatLocalDate(-30), formatLocalDate(0)] }
|
||||
function params() { return { ...query, beginBillDate: dateRange.value?.[0], endBillDate: dateRange.value?.[1] } }
|
||||
function search() { pageNum.value = 1; loadRows(); loadSummary() }
|
||||
function reset() { Object.assign(query, { customerId: null, salesUserId: null, billNo: '', status: '' }); dateRange.value = defaultBillDateRange(); search() }
|
||||
function search() { if (!validateDateRange()) return; pageNum.value = 1; loadRows(); loadSummary() }
|
||||
function reset() { Object.assign(query, { customerId: null, salesUserId: null, billNo: '', status: '' }); dateRange.value = defaultDateRange(); search() }
|
||||
function handleSalesInput() {
|
||||
salesSearchVersion++
|
||||
salesOptions.value = []
|
||||
@@ -241,6 +262,7 @@ async function searchSales(keyword) {
|
||||
}
|
||||
}
|
||||
function loadRows() {
|
||||
if (!validateDateRange()) return
|
||||
const version = ++requestVersion
|
||||
loading.value = true
|
||||
rows.value = []
|
||||
@@ -250,6 +272,7 @@ function loadRows() {
|
||||
}
|
||||
let summaryVersion = 0
|
||||
function loadSummary() {
|
||||
if (!validateDateRange(false)) return
|
||||
const version = ++summaryVersion
|
||||
summaryLoaded.value = false
|
||||
listArProfitSummary(params()).then(res => { if (version === summaryVersion) { summaries.value = res.data || []; summaryLoaded.value = true } })
|
||||
@@ -263,7 +286,7 @@ async function loadBillDetails() {
|
||||
finally { if (version === detailsVersion) detailsLoading.value = false }
|
||||
}
|
||||
async function openFees(row) { feeVisible.value = true; feeLoading.value = true; fees.value = []; try { fees.value = (await listArProfitFees(row.detailId)).data || [] } finally { feeLoading.value = false } }
|
||||
function exportRows() { proxy.download('/report/ar-profit/export', params(), `应收账单毛利分析_${Date.now()}.xlsx`) }
|
||||
function exportRows() { if (validateDateRange()) proxy.download('/report/ar-profit/export', params(), `应收账单毛利分析_${Date.now()}.xlsx`) }
|
||||
function exportCommissions() { proxy.download('/report/ar-profit/commissions/export', {}, `应收账单提成明细_${Date.now()}.xlsx`) }
|
||||
function money(v) { return v === null || v === undefined || v === '' || !Number.isFinite(Number(v)) ? '-' : Number(v).toFixed(2) }
|
||||
function rate(v) { return v === null || v === undefined || v === '' || !Number.isFinite(Number(v)) ? '-' : Number(v).toFixed(2) + '%' }
|
||||
@@ -318,11 +341,26 @@ async function confirmRate() {
|
||||
if (confirmForm.rate === null || !confirmForm.remark.trim()) return ElMessage.warning('请填写比例及核对说明')
|
||||
await confirmArProfitMissingRate(confirmForm); confirmVisible.value = false; ElMessage.success('已确认提成比例'); loadCommissionTab()
|
||||
}
|
||||
watch(dateRange, () => {
|
||||
requestVersion++
|
||||
summaryVersion++
|
||||
rows.value = []
|
||||
total.value = 0
|
||||
loading.value = false
|
||||
summaries.value = []
|
||||
summaryLoaded.value = false
|
||||
}, { flush: 'sync' })
|
||||
listArProfitAreaRules().then(res => { areaRules.value = res.data || {} })
|
||||
search()
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.search-card :deep(.el-card__body) { padding: 18px 20px 8px; }
|
||||
.filter-item { width: 100%; margin-bottom: 14px; }
|
||||
.filter-item :deep(.el-form-item__content) { min-width: 0; }
|
||||
.filter-item :deep(.el-date-editor.el-input__wrapper) { width: 100%; }
|
||||
.filter-control { width: 100%; }
|
||||
.filter-actions { display: flex; align-items: center; }
|
||||
.summary-card, .data-card { margin-top: 14px; }
|
||||
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); gap: 14px; }
|
||||
.metrics > div { min-width: 0; padding: 10px; background: var(--el-fill-color-lighter); color: var(--el-text-color-secondary); }
|
||||
|
||||
@@ -264,6 +264,7 @@
|
||||
import { listProfitAreaRules, listProfitCustomerOptions, listProfitOrders, listProfitSummary } from '@/api/report/profit'
|
||||
// 提成功能暂停使用:import { deleteProfitCommissionRate, listProfitCommissionRates, saveProfitCommissionRate } from '@/api/report/profit'
|
||||
import { parseTime } from '@/utils/bms'
|
||||
import { defaultDateRange, maxEndDate } from '@/utils/reportDateRange'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { exportAsync } from '@/utils/excelExport'
|
||||
// 提成功能暂停使用:import { ElMessageBox } from 'element-plus'
|
||||
@@ -347,31 +348,6 @@ function createRateForm(row = {}) {
|
||||
}
|
||||
*/
|
||||
|
||||
function formatLocalDate(date) {
|
||||
const year = date.getFullYear()
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
return `${year}-${month}-${day}`
|
||||
}
|
||||
|
||||
// 次月没有对应日期时取月末,再减一天;起止日期均包含当天。
|
||||
function maxEndDate(start) {
|
||||
const [year, month, day] = start.split('-').map(Number)
|
||||
const lastDayOfNextMonth = new Date(year, month + 1, 0).getDate()
|
||||
const limit = new Date(year, month, Math.min(day, lastDayOfNextMonth))
|
||||
limit.setDate(limit.getDate() - 1)
|
||||
return formatLocalDate(limit)
|
||||
}
|
||||
|
||||
function defaultDateRange() {
|
||||
const end = new Date()
|
||||
const start = new Date(end.getFullYear(), end.getMonth(), end.getDate())
|
||||
const endText = formatLocalDate(end)
|
||||
start.setDate(start.getDate() - 31)
|
||||
while (maxEndDate(formatLocalDate(start)) < endText) start.setDate(start.getDate() + 1)
|
||||
return [formatLocalDate(start), endText]
|
||||
}
|
||||
|
||||
function buildQuery(paged = true) {
|
||||
const params = { ...query }
|
||||
if (arBillStatus.value) params.arBillStatus = arBillStatus.value
|
||||
|
||||
Reference in New Issue
Block a user