780 lines
32 KiB
Vue
780 lines
32 KiB
Vue
<template>
|
||
<div class="app-container profit-report">
|
||
<Teleport to="body">
|
||
<div v-if="exportFloatVisible" class="export-status-float">
|
||
<el-tooltip :content="exportMessage || '点击查看详情'" placement="bottom">
|
||
<el-button class="export-status-button" type="warning" plain size="small" @click="exportProgressVisible = true">
|
||
<span class="export-progress-ring" :style="{ '--export-progress': exportDegree + 'deg' }" aria-hidden="true">
|
||
<span class="export-progress-value">{{ exportPercent }}%</span>
|
||
</span>
|
||
<span class="export-status-text">
|
||
<strong>{{ exportFloatTitle }}</strong>
|
||
<small>{{ exportFloatSummary }}</small>
|
||
</span>
|
||
</el-button>
|
||
</el-tooltip>
|
||
</div>
|
||
</Teleport>
|
||
<el-card shadow="never" class="search-card">
|
||
<el-form :model="query" label-width="120px" @submit.prevent>
|
||
<el-row :gutter="16">
|
||
<el-col :xs="24" :sm="12" :lg="8">
|
||
<el-form-item label="客户区域" class="filter-item">
|
||
<el-select v-model="query.customerArea" placeholder="请选择客户区域" class="filter-control">
|
||
<el-option v-for="area in customer_area" :key="area.value" :label="area.label" :value="area.value" />
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col>
|
||
<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-col>
|
||
<el-col :xs="24" :sm="12" :lg="8">
|
||
<el-form-item label="客户名称" class="filter-item">
|
||
<customer-select
|
||
v-model="query.customerCode"
|
||
:fetch-options="listProfitCustomerOptions"
|
||
value-key="customerCode"
|
||
remote-search
|
||
:page-size="20"
|
||
placeholder="请输入客户名称或代码搜索"
|
||
class="filter-control"
|
||
/>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :xs="24" :sm="12" :lg="8">
|
||
<el-form-item label="业务员编码/姓名" class="filter-item">
|
||
<el-input v-model="query.belongSalerCode" clearable placeholder="输入业务员编码或姓名" class="filter-control" @keyup.enter="handleSearch" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :xs="24" :sm="12" :lg="8">
|
||
<el-form-item label="产品代码/名称" class="filter-item">
|
||
<el-input v-model="query.productKeyword" clearable placeholder="输入产品代码或名称" class="filter-control" @keyup.enter="handleSearch" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :xs="24" :sm="12" :lg="8">
|
||
<el-form-item label="国家/地区" class="filter-item">
|
||
<el-input v-model="query.countryName" clearable placeholder="输入国家/地区名称" class="filter-control" @keyup.enter="handleSearch" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :xs="24" :sm="12" :lg="8">
|
||
<el-form-item label="国家代码" class="filter-item">
|
||
<el-input v-model="query.countryCode" clearable placeholder="输入国家代码" class="filter-control" @keyup.enter="handleSearch" />
|
||
</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.currency" clearable filterable allow-create default-first-option placeholder="选择或输入币种" class="filter-control">
|
||
<el-option v-for="item in bms_currency" :key="item.value" :label="item.label || item.value" :value="item.value" />
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :xs="24" :sm="12" :lg="8">
|
||
<el-form-item label="订单号" class="filter-item">
|
||
<el-input
|
||
v-model="query.orderNo"
|
||
type="textarea"
|
||
:rows="1"
|
||
resize="none"
|
||
clearable
|
||
placeholder="输入订单号,多个值请换行"
|
||
class="filter-control multi-line-filter"
|
||
/>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :xs="24" :sm="12" :lg="8">
|
||
<el-form-item label="应收状态" class="filter-item">
|
||
<el-select v-model="arBillStatus" clearable placeholder="全部状态" class="filter-control" @change="clearReportResults">
|
||
<el-option label="未出账" value="UNBILLED" />
|
||
<el-option label="部分出账" value="PARTIAL" />
|
||
<el-option label="已出账" value="BILLED" />
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :xs="24" :sm="12" :lg="8" class="filter-actions-col">
|
||
<div class="filter-item filter-actions">
|
||
<el-button type="primary" icon="Search" :disabled="!hasProfitRule()" @click="handleSearch">搜索</el-button>
|
||
<el-button icon="Refresh" @click="handleReset">重置</el-button>
|
||
</div>
|
||
</el-col>
|
||
</el-row>
|
||
</el-form>
|
||
</el-card>
|
||
|
||
<el-alert v-if="areaRulesFailed" title="毛利规则加载失败,请刷新页面重试" type="error" :closable="false" show-icon class="rule-alert" />
|
||
<el-alert v-else-if="areaRules && hasCustomerArea() && !currentRule" title="该客户区域未配置毛利规则" type="warning" :closable="false" show-icon class="rule-alert" />
|
||
|
||
<div v-if="summaryLoaded && hasProfitRule()" class="summary-list">
|
||
<el-card v-for="summary in summaryCards" :key="summary.currency || 'empty'" shadow="never" class="summary-card">
|
||
<template #header>
|
||
<span>{{ summary.empty ? '汇总' : `${summary.currency || '未标币种'} 汇总` }}</span>
|
||
<span class="summary-subtitle">订单 {{ summary.orderCount ?? '-' }} 条</span>
|
||
</template>
|
||
<el-row :gutter="12" class="summary-grid">
|
||
<el-col :xs="12" :sm="8" :md="6">
|
||
<div class="metric-item"><div class="metric-label">红线价</div><div class="metric-value">{{ money(summary.redlineAmount) }}</div></div>
|
||
</el-col>
|
||
<el-col v-if="!isGuangzhou" :xs="12" :sm="8" :md="6">
|
||
<div class="metric-item"><div class="metric-label">产品价</div><div class="metric-value">{{ money(summary.costAmount) }}</div></div>
|
||
</el-col>
|
||
<el-col :xs="12" :sm="8" :md="6">
|
||
<div class="metric-item"><div class="metric-label">销售价</div><div class="metric-value">{{ money(summary.salesAmount) }}</div></div>
|
||
</el-col>
|
||
<el-col v-if="!isGuangzhou" :xs="12" :sm="8" :md="6">
|
||
<div class="metric-item"><div class="metric-label">红线毛利</div><div class="metric-value">{{ money(summary.redlineGrossProfit) }} <small>{{ rate(summary.redlineGrossMarginRate) }}</small></div></div>
|
||
</el-col>
|
||
<el-col :xs="12" :sm="8" :md="6">
|
||
<div class="metric-item"><div class="metric-label">销售毛利</div><div class="metric-value profit-value">{{ money(summary.salesGrossProfit) }} <small>{{ rate(summary.salesGrossMarginRate) }}</small></div></div>
|
||
</el-col>
|
||
<!-- 提成功能暂停使用,保留代码便于恢复。
|
||
<el-col :xs="12" :sm="8" :md="6">
|
||
<div class="metric-item"><div class="metric-label">提成金额</div><div class="metric-value">{{ money(summary.commissionAmount) }}</div></div>
|
||
</el-col>
|
||
-->
|
||
<!-- 提成功能暂停使用。
|
||
<el-col :xs="12" :sm="8" :md="6">
|
||
<div class="metric-item"><div class="metric-label">提成未计算订单</div><div class="metric-value">{{ summary.commissionMissingOrderCount || 0 }}</div></div>
|
||
</el-col>
|
||
-->
|
||
</el-row>
|
||
</el-card>
|
||
</div>
|
||
|
||
<el-card shadow="never" class="table-card">
|
||
<div class="table-heading">
|
||
<span class="table-title">订单列表</span>
|
||
<div class="table-toolbar">
|
||
<!-- 提成功能暂停使用。
|
||
<el-button
|
||
icon="Setting"
|
||
v-hasPermi="['report:profit:commission:list']"
|
||
@click="openCommissionRates"
|
||
>提成比例设置</el-button>
|
||
-->
|
||
<el-button
|
||
type="primary"
|
||
plain
|
||
icon="Download"
|
||
v-hasPermi="['report:profit:export']"
|
||
:loading="exporting"
|
||
:disabled="!hasProfitRule() || !hasSearched || loading"
|
||
@click="handleExport"
|
||
>导出订单</el-button>
|
||
</div>
|
||
</div>
|
||
|
||
<div v-text-drag-copy="true" class="report-table-copy-area">
|
||
<el-table :key="currentRule" v-loading="loading" :data="rows" border stripe row-key="orderNo">
|
||
<el-table-column prop="bizDate" label="计费时间" width="170" align="center"><template #default="{ row }">{{ parseTime(row.bizDate) }}</template></el-table-column>
|
||
<el-table-column prop="orderNo" label="订单号" min-width="160" show-overflow-tooltip />
|
||
<el-table-column prop="customerCode" label="客户代码" width="120" />
|
||
<el-table-column prop="customerName" label="客户名称" min-width="160" show-overflow-tooltip />
|
||
<el-table-column prop="belongSalerCode" label="业务员编码" min-width="150" show-overflow-tooltip />
|
||
<el-table-column prop="belongSaler" label="业务员" min-width="110" show-overflow-tooltip />
|
||
<el-table-column prop="productCode" label="产品代码" width="120" />
|
||
<el-table-column prop="productName" label="产品名称" min-width="160" show-overflow-tooltip />
|
||
<el-table-column prop="countryName" label="国家/地区" min-width="110" show-overflow-tooltip />
|
||
<el-table-column prop="countryCode" label="国家代码" width="100" align="center" />
|
||
<el-table-column prop="currency" label="币种" width="80" align="center" />
|
||
<el-table-column v-if="!isGuangzhou" prop="costAmount" label="产品价" min-width="130" align="right"><template #default="{ row }">{{ money(row.costAmount) }}</template></el-table-column>
|
||
<el-table-column prop="redlineAmount" label="红线价" min-width="130" align="right"><template #default="{ row }">{{ money(row.redlineAmount) }}</template></el-table-column>
|
||
<el-table-column v-if="!isGuangzhou" prop="redlineGrossProfit" label="红线毛利" min-width="130" align="right"><template #default="{ row }">{{ money(row.redlineGrossProfit) }}</template></el-table-column>
|
||
<el-table-column v-if="!isGuangzhou" prop="redlineGrossMarginRate" label="红线毛利率" min-width="120" align="right"><template #default="{ row }">{{ rate(row.redlineGrossMarginRate) }}</template></el-table-column>
|
||
<el-table-column prop="salesAmount" label="销售价" min-width="130" align="right"><template #default="{ row }">{{ money(row.salesAmount) }}</template></el-table-column>
|
||
<el-table-column prop="salesGrossProfit" label="销售毛利" min-width="130" align="right"><template #default="{ row }">{{ money(row.salesGrossProfit) }}</template></el-table-column>
|
||
<el-table-column prop="salesGrossMarginRate" label="销售毛利率" min-width="120" align="right"><template #default="{ row }">{{ rate(row.salesGrossMarginRate) }}</template></el-table-column>
|
||
<!-- 提成功能暂停使用。
|
||
<el-table-column prop="commissionRate" label="提成比例" width="110" align="right"><template #default="{ row }">{{ commissionRateFormat(row.commissionRate) }}</template></el-table-column>
|
||
<el-table-column prop="commissionAmount" label="提成金额" min-width="120" align="right"><template #default="{ row }">{{ money(row.commissionAmount) }}</template></el-table-column>
|
||
-->
|
||
<el-table-column prop="arBillStatus" label="应收状态" width="110" align="center">
|
||
<template #default="{ row }">{{ arBillStatusLabel(row.arBillStatus) }}</template>
|
||
</el-table-column>
|
||
<template #empty><el-empty :description="hasSearched ? '暂无符合条件的数据' : '请选择计费日期后点击搜索'" /></template>
|
||
</el-table>
|
||
</div>
|
||
|
||
<pagination
|
||
v-show="total > 0"
|
||
v-model:page="pageNum"
|
||
v-model:limit="pageSize"
|
||
:total="total"
|
||
@pagination="loadRows"
|
||
/>
|
||
</el-card>
|
||
|
||
<el-dialog v-model="exportProgressVisible" :title="exportDialogTitle" width="480px" append-to-body :close-on-click-modal="false">
|
||
<el-progress :percentage="exportPercent" :status="exportStatus" :stroke-width="14" striped :striped-flow="exporting" />
|
||
<div class="export-progress__msg">{{ exportMessage }}</div>
|
||
<div class="export-progress__text">导出行数 {{ exportRowCount }}</div>
|
||
<p v-if="exporting" class="export-progress__hint">导出在后台进行,可收起弹窗继续操作;请勿关闭或刷新本页</p>
|
||
<template #footer>
|
||
<el-button v-if="exporting" @click="exportProgressVisible = false">收起</el-button>
|
||
<el-button v-else type="primary" @click="exportProgressVisible = false">关闭</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 提成设置与编辑弹窗暂停使用。
|
||
<el-dialog v-model="commissionDialogVisible" title="业务员固定提成比例" width="760px" append-to-body>
|
||
<div class="commission-toolbar">
|
||
<span class="commission-tip">按业务员编码配置,比例输入百分数,例如 5 表示 5%。</span>
|
||
<el-button type="primary" plain icon="Plus" v-hasPermi="['report:profit:commission:save']" @click="openRateForm()">新增比例</el-button>
|
||
</div>
|
||
<el-table v-loading="commissionLoading" :data="commissionRates" border stripe>
|
||
<el-table-column prop="belongSalerCode" label="业务员编码" min-width="150" />
|
||
<el-table-column prop="commissionRate" label="提成比例" width="130" align="right"><template #default="{ row }">{{ commissionRateFormat(row.commissionRate) }}</template></el-table-column>
|
||
<el-table-column prop="status" label="状态" width="90" align="center"><template #default="{ row }">{{ row.status === '0' ? '正常' : '停用' }}</template></el-table-column>
|
||
<el-table-column label="操作" width="130" fixed="right" align="center">
|
||
<template #default="{ row }">
|
||
<el-button link type="primary" v-hasPermi="['report:profit:commission:save']" @click="openRateForm(row)">编辑</el-button>
|
||
<el-button link type="danger" v-hasPermi="['report:profit:commission:remove']" @click="handleDeleteRate(row)">删除</el-button>
|
||
</template>
|
||
</el-table-column>
|
||
<template #empty><el-empty description="尚未配置业务员提成比例" /></template>
|
||
</el-table>
|
||
<template #footer><el-button @click="commissionDialogVisible = false">关闭</el-button></template>
|
||
</el-dialog>
|
||
|
||
<el-dialog v-model="rateFormVisible" :title="rateForm.rateId ? '编辑提成比例' : '新增提成比例'" width="520px" append-to-body>
|
||
<el-form ref="rateFormRef" :model="rateForm" :rules="rateRules" label-width="110px">
|
||
<el-form-item label="业务员编码" prop="belongSalerCode"><el-input v-model="rateForm.belongSalerCode" maxlength="64" :disabled="!!rateForm.rateId" /></el-form-item>
|
||
<el-form-item label="提成比例(%)" prop="commissionRate"><el-input-number v-model="rateForm.commissionRate" :min="0" :max="100" :precision="4" :step="0.01" controls-position="right" style="width: 100%" /></el-form-item>
|
||
<el-form-item label="状态" prop="status"><el-radio-group v-model="rateForm.status"><el-radio value="0">正常</el-radio><el-radio value="1">停用</el-radio></el-radio-group></el-form-item>
|
||
<el-form-item label="备注" prop="remark"><el-input v-model="rateForm.remark" type="textarea" :rows="2" maxlength="500" /></el-form-item>
|
||
</el-form>
|
||
<template #footer>
|
||
<el-button type="primary" :loading="rateSaving" @click="submitRateForm">保存</el-button>
|
||
<el-button @click="rateFormVisible = false">取消</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
-->
|
||
</div>
|
||
</template>
|
||
|
||
<script setup name="ProfitReport">
|
||
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'
|
||
|
||
const { customer_area, bms_currency } = useDict('customer_area', 'bms_currency')
|
||
const multiValueFilterLimit = 2000
|
||
const dateRange = ref(defaultDateRange())
|
||
const dateRangeError = computed(() => {
|
||
if (!hasCompleteDateRange()) return ''
|
||
const [start, end] = dateRange.value
|
||
return end > maxEndDate(start) ? '计费日期最多查询一个月' : ''
|
||
})
|
||
const arBillStatus = ref('')
|
||
const query = reactive({
|
||
customerArea: '',
|
||
orderNo: '',
|
||
customerCode: '',
|
||
belongSalerCode: '',
|
||
productKeyword: '',
|
||
countryName: '',
|
||
countryCode: '',
|
||
currency: ''
|
||
})
|
||
const areaRules = ref(null)
|
||
const areaRulesFailed = ref(false)
|
||
const currentRule = computed(() => areaRules.value?.[String(query.customerArea)] || '')
|
||
const isGuangzhou = computed(() => currentRule.value === 'GUANGZHOU')
|
||
const summaryList = ref([])
|
||
const summaryLoaded = ref(false)
|
||
const summaryCards = computed(() => summaryList.value.length ? summaryList.value : [{ empty: true }])
|
||
let summaryRequestVersion = 0
|
||
const rows = ref([])
|
||
let rowsRequestVersion = 0
|
||
const loading = ref(false)
|
||
const hasSearched = ref(false)
|
||
const exporting = ref(false)
|
||
const exportFinished = ref(false)
|
||
const exportProgressVisible = ref(false)
|
||
const exportPercent = ref(0)
|
||
const exportStatus = ref(undefined)
|
||
const exportMessage = ref('')
|
||
const exportRowCount = ref(0)
|
||
let exportHideTimer = null
|
||
const exportFloatVisible = computed(() => exporting.value || exportFinished.value)
|
||
const exportDegree = computed(() => Math.round(exportPercent.value / 100 * 360))
|
||
const exportFloatTitle = computed(() => exporting.value ? '导出中' : (exportStatus.value === 'exception' ? '导出失败' : '导出完成'))
|
||
const exportFloatSummary = computed(() => exportRowCount.value > 0
|
||
? `${exportPercent.value}% / ${exportRowCount.value} 行`
|
||
: `${exportPercent.value}%`)
|
||
const exportDialogTitle = computed(() => exporting.value ? '异步导出进行中' : (exportStatus.value === 'exception' ? '异步导出失败' : '异步导出完成'))
|
||
onBeforeUnmount(() => {
|
||
clearTimeout(exportHideTimer)
|
||
})
|
||
const pageNum = ref(1)
|
||
const pageSize = ref(10)
|
||
// 汇总按币种分组,分页总数复用各币种订单数之和。
|
||
const total = computed(() => summaryList.value.reduce((count, summary) => count + Number(summary.orderCount || 0), 0))
|
||
/* 提成表单状态与初始化暂停使用,保留代码便于恢复。
|
||
const commissionDialogVisible = ref(false)
|
||
const commissionLoading = ref(false)
|
||
const commissionRates = ref([])
|
||
const rateFormVisible = ref(false)
|
||
const rateSaving = ref(false)
|
||
const rateFormRef = ref()
|
||
const rateForm = reactive(createRateForm())
|
||
const rateRules = {
|
||
belongSalerCode: [{ required: true, message: '请输入业务员编码', trigger: 'blur' }],
|
||
commissionRate: [{ required: true, message: '请输入提成比例', trigger: 'change' }],
|
||
status: [{ required: true, message: '请选择状态', trigger: 'change' }]
|
||
}
|
||
|
||
function createRateForm(row = {}) {
|
||
return {
|
||
rateId: row.rateId || undefined,
|
||
belongSalerCode: row.belongSalerCode || '',
|
||
belongSaler: row.belongSaler || '',
|
||
commissionRate: row.commissionRate === 0 ? 0 : (row.commissionRate || undefined),
|
||
status: row.status || '0',
|
||
remark: row.remark || ''
|
||
}
|
||
}
|
||
*/
|
||
|
||
function buildQuery(paged = true) {
|
||
const params = { ...query }
|
||
if (arBillStatus.value) params.arBillStatus = arBillStatus.value
|
||
if (dateRange.value?.[0]) params.beginBizDate = dateRange.value[0] + ' 00:00:00'
|
||
if (dateRange.value?.[1]) params.endBizDate = dateRange.value[1] + ' 23:59:59'
|
||
if (paged) {
|
||
params.pageNum = pageNum.value
|
||
params.pageSize = pageSize.value
|
||
}
|
||
return params
|
||
}
|
||
|
||
function validateMultiValueFilters(showMessage = true) {
|
||
const filters = [
|
||
['orderNo', '订单号']
|
||
]
|
||
for (const [key, label] of filters) {
|
||
const values = new Set(String(query[key] || '').split(/[\s,,;;]+/).map(value => value.trim()).filter(Boolean))
|
||
if (values.size > multiValueFilterLimit) {
|
||
if (showMessage) ElMessage.warning(`${label}最多输入 ${multiValueFilterLimit} 个不重复值`)
|
||
return false
|
||
}
|
||
}
|
||
return true
|
||
}
|
||
|
||
function hasCustomerArea() {
|
||
return query.customerArea !== '' && query.customerArea !== null && query.customerArea !== undefined
|
||
}
|
||
|
||
function hasProfitRule() {
|
||
return hasCustomerArea() && !!currentRule.value
|
||
}
|
||
|
||
function hasCompleteDateRange() {
|
||
return Array.isArray(dateRange.value) && !!dateRange.value[0] && !!dateRange.value[1]
|
||
}
|
||
|
||
function validateRequiredFilters(showMessage = true) {
|
||
if (!hasCompleteDateRange()) {
|
||
if (showMessage) ElMessage.warning('请选择完整的计费日期')
|
||
return false
|
||
}
|
||
if (dateRangeError.value) {
|
||
if (showMessage) ElMessage.warning(dateRangeError.value)
|
||
return false
|
||
}
|
||
return true
|
||
}
|
||
|
||
function loadSummary() {
|
||
if (!hasSearched.value || !validateRequiredFilters(false) || !hasProfitRule() || !validateMultiValueFilters(false)) return Promise.resolve()
|
||
const requestVersion = ++summaryRequestVersion
|
||
summaryLoaded.value = false
|
||
return listProfitSummary(buildQuery(false)).then(res => {
|
||
if (requestVersion !== summaryRequestVersion) return
|
||
summaryList.value = res.data || []
|
||
summaryLoaded.value = true
|
||
})
|
||
}
|
||
|
||
function loadRows() {
|
||
if (!hasSearched.value || !validateRequiredFilters(false) || !hasProfitRule() || !validateMultiValueFilters()) return Promise.resolve()
|
||
const requestVersion = ++rowsRequestVersion
|
||
loading.value = true
|
||
return listProfitOrders(buildQuery()).then(res => {
|
||
if (requestVersion !== rowsRequestVersion) return
|
||
rows.value = res.rows || []
|
||
}).finally(() => {
|
||
if (requestVersion === rowsRequestVersion) loading.value = false
|
||
})
|
||
}
|
||
|
||
function clearReportResults() {
|
||
hasSearched.value = false
|
||
summaryRequestVersion++
|
||
rowsRequestVersion++
|
||
summaryList.value = []
|
||
summaryLoaded.value = false
|
||
rows.value = []
|
||
loading.value = false
|
||
}
|
||
|
||
function handleSearch() {
|
||
clearReportResults()
|
||
if (!validateRequiredFilters()) return
|
||
if (!hasProfitRule() || !validateMultiValueFilters()) return
|
||
hasSearched.value = true
|
||
pageNum.value = 1
|
||
Promise.all([loadSummary(), loadRows()])
|
||
}
|
||
|
||
function handleReset() {
|
||
Object.keys(query).forEach(key => { query[key] = '' })
|
||
query.customerArea = customer_area.value[0]?.value ?? ''
|
||
arBillStatus.value = ''
|
||
dateRange.value = defaultDateRange()
|
||
hasSearched.value = false
|
||
clearReportResults()
|
||
}
|
||
|
||
function money(value) {
|
||
if (value === null || value === undefined || value === '') return '-'
|
||
const number = Number(value)
|
||
return Number.isFinite(number) ? number.toFixed(2) : '-'
|
||
}
|
||
|
||
function rate(value) {
|
||
if (value === null || value === undefined || value === '') return '-'
|
||
const number = Number(value)
|
||
return Number.isFinite(number) ? number.toFixed(2) + '%' : '-'
|
||
}
|
||
|
||
/* 提成比例格式化暂停使用。
|
||
function commissionRateFormat(value) {
|
||
if (value === null || value === undefined || value === '') return '-'
|
||
const number = Number(value)
|
||
return Number.isFinite(number) ? number.toFixed(4) + '%' : '-'
|
||
}
|
||
*/
|
||
|
||
function arBillStatusLabel(value) {
|
||
const labels = {
|
||
UNBILLED: '未出账',
|
||
PARTIAL: '部分出账',
|
||
BILLED: '已出账'
|
||
}
|
||
return labels[value] || value || '-'
|
||
}
|
||
|
||
async function handleExport() {
|
||
if (exporting.value || !hasSearched.value || !validateRequiredFilters()) return
|
||
if (!hasProfitRule() || !validateMultiValueFilters()) return
|
||
clearTimeout(exportHideTimer)
|
||
exporting.value = true
|
||
exportFinished.value = false
|
||
exportProgressVisible.value = false
|
||
exportPercent.value = 0
|
||
exportStatus.value = undefined
|
||
exportMessage.value = '正在提交导出任务'
|
||
exportRowCount.value = 0
|
||
try {
|
||
const result = await exportAsync({
|
||
baseUrl: '/report/profit/orders/export',
|
||
query: buildQuery(false),
|
||
filePrefix: '订单维度毛利分析',
|
||
showLoading: false,
|
||
onProgress: task => {
|
||
exportPercent.value = Math.max(0, Math.min(100, Number(task.percent) || 0))
|
||
exportRowCount.value = Number(task.rowCount) || 0
|
||
exportMessage.value = task.error || task.message || '导出中'
|
||
if (task.status === 'FAIL' || task.status === 'FAILED') exportStatus.value = 'exception'
|
||
}
|
||
})
|
||
if (result) {
|
||
exportPercent.value = 100
|
||
exportStatus.value = 'success'
|
||
exportMessage.value = '导出完成'
|
||
} else {
|
||
if (exportStatus.value !== 'exception') exportMessage.value = '导出失败,请查看提示后重试'
|
||
exportStatus.value = 'exception'
|
||
}
|
||
} catch (error) {
|
||
exportStatus.value = 'exception'
|
||
exportMessage.value = error?.message || '导出失败,请稍后重试'
|
||
} finally {
|
||
exporting.value = false
|
||
exportFinished.value = true
|
||
exportHideTimer = window.setTimeout(() => {
|
||
exportFinished.value = false
|
||
exportHideTimer = null
|
||
}, 1000)
|
||
}
|
||
}
|
||
|
||
/* 提成配置交互暂停使用。
|
||
function openCommissionRates() {
|
||
commissionDialogVisible.value = true
|
||
commissionLoading.value = true
|
||
listProfitCommissionRates().then(res => {
|
||
commissionRates.value = res.data || []
|
||
}).finally(() => {
|
||
commissionLoading.value = false
|
||
})
|
||
}
|
||
|
||
function openRateForm(row) {
|
||
Object.assign(rateForm, createRateForm(row))
|
||
rateFormVisible.value = true
|
||
nextTick(() => rateFormRef.value?.clearValidate())
|
||
}
|
||
|
||
function submitRateForm() {
|
||
rateFormRef.value.validate(valid => {
|
||
if (!valid) return
|
||
rateSaving.value = true
|
||
saveProfitCommissionRate({ ...rateForm }).then(() => {
|
||
ElMessage.success('提成比例已保存')
|
||
rateFormVisible.value = false
|
||
openCommissionRates()
|
||
Promise.all([loadSummary(), loadRows()])
|
||
}).finally(() => {
|
||
rateSaving.value = false
|
||
})
|
||
})
|
||
}
|
||
|
||
function handleDeleteRate(row) {
|
||
ElMessageBox.confirm(`确定删除业务员 ${row.belongSalerCode} 的提成比例吗?`, '提示', { type: 'warning' }).then(() => {
|
||
return deleteProfitCommissionRate(row.rateId)
|
||
}).then(() => {
|
||
ElMessage.success('提成比例已删除')
|
||
openCommissionRates()
|
||
Promise.all([loadSummary(), loadRows()])
|
||
}).catch(error => {
|
||
if (error !== 'cancel' && error !== 'close' && error?.action !== 'cancel' && error?.action !== 'close') {
|
||
ElMessage.error(error?.message || '删除提成比例失败')
|
||
}
|
||
})
|
||
}
|
||
*/
|
||
|
||
listProfitAreaRules().then(res => {
|
||
areaRules.value = res.data || {}
|
||
}).catch(() => {
|
||
areaRules.value = {}
|
||
areaRulesFailed.value = true
|
||
clearReportResults()
|
||
})
|
||
|
||
watch(customer_area, options => {
|
||
if (!options?.length) {
|
||
query.customerArea = ''
|
||
clearReportResults()
|
||
return
|
||
}
|
||
if (!options.some(area => area.value === query.customerArea)) {
|
||
query.customerArea = options[0].value
|
||
}
|
||
}, { immediate: true })
|
||
|
||
watch(() => [
|
||
query.customerArea,
|
||
query.orderNo,
|
||
query.customerCode,
|
||
query.belongSalerCode,
|
||
query.productKeyword,
|
||
query.countryName,
|
||
query.countryCode,
|
||
query.currency,
|
||
dateRange.value?.[0],
|
||
dateRange.value?.[1]
|
||
], () => {
|
||
if (hasSearched.value) clearReportResults()
|
||
})
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
.export-status-float { position: fixed; top: 92px; right: 24px; z-index: 3001; }
|
||
.export-status-button { display: inline-flex; align-items: center; gap: 10px; min-width: 200px; min-height: 68px; padding: 6px 16px 6px 7px; border-radius: 36px; }
|
||
.export-progress-ring { position: relative; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 54px; width: 54px; height: 54px; border-radius: 50%; background: conic-gradient(var(--el-color-warning) 0deg var(--export-progress, 0deg), var(--el-color-warning-light-8) var(--export-progress, 0deg) 360deg); }
|
||
.export-progress-ring::after { position: absolute; inset: 5px; content: ''; border-radius: 50%; background: var(--el-bg-color); }
|
||
.export-progress-value { position: relative; z-index: 1; color: var(--el-color-warning); font-size: 12px; font-weight: 600; line-height: 1; }
|
||
.export-status-text { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; line-height: 1.2; white-space: nowrap; }
|
||
.export-status-text strong { font-size: 14px; font-weight: 600; }
|
||
.export-status-text small { color: var(--el-text-color-secondary); font-size: 11px; }
|
||
.export-progress__msg { margin-top: 12px; color: var(--el-text-color-regular); }
|
||
.export-progress__text { margin-top: 8px; color: var(--el-text-color-secondary); font-size: 13px; }
|
||
.export-progress__hint { margin-top: 12px; color: var(--el-color-warning); font-size: 12px; }
|
||
|
||
.search-card,
|
||
.table-card {
|
||
margin-bottom: 14px;
|
||
}
|
||
|
||
.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-control {
|
||
width: 100%;
|
||
}
|
||
|
||
.filter-actions-col {
|
||
display: flex;
|
||
align-items: flex-end;
|
||
}
|
||
|
||
.filter-actions {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: flex-start;
|
||
gap: 8px;
|
||
}
|
||
|
||
.rule-alert {
|
||
margin-bottom: 14px;
|
||
}
|
||
|
||
.summary-list {
|
||
display: grid;
|
||
grid-template-columns: repeat(auto-fit, minmax(560px, 1fr));
|
||
gap: 12px;
|
||
margin-bottom: 14px;
|
||
}
|
||
|
||
.summary-card :deep(.el-card__header) {
|
||
padding: 12px 16px;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.summary-card :deep(.el-card__body) {
|
||
padding: 14px 16px 16px;
|
||
}
|
||
|
||
.summary-grid {
|
||
margin-bottom: -12px;
|
||
}
|
||
|
||
.summary-grid :deep(.el-col) {
|
||
margin-bottom: 12px;
|
||
}
|
||
|
||
.summary-subtitle {
|
||
float: right;
|
||
color: var(--el-text-color-secondary);
|
||
font-size: 13px;
|
||
font-weight: 400;
|
||
}
|
||
|
||
.metric-label {
|
||
margin-bottom: 5px;
|
||
color: var(--el-text-color-secondary);
|
||
font-size: 13px;
|
||
}
|
||
|
||
.metric-item {
|
||
min-height: 68px;
|
||
padding: 10px 12px;
|
||
border-radius: 4px;
|
||
background: var(--el-fill-color-lighter);
|
||
}
|
||
|
||
.metric-value {
|
||
color: var(--el-text-color-primary);
|
||
font-size: 18px;
|
||
font-weight: 600;
|
||
overflow-wrap: anywhere;
|
||
line-height: 1.4;
|
||
}
|
||
|
||
.metric-value small {
|
||
color: var(--el-text-color-secondary);
|
||
font-size: 12px;
|
||
font-weight: 400;
|
||
}
|
||
|
||
.profit-value {
|
||
color: var(--el-color-primary);
|
||
}
|
||
|
||
.table-heading {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 12px;
|
||
margin-bottom: 12px;
|
||
border-bottom: 1px solid var(--el-border-color-light);
|
||
}
|
||
|
||
.table-title {
|
||
font-weight: 600;
|
||
padding-bottom: 8px;
|
||
}
|
||
|
||
.table-toolbar {
|
||
display: flex;
|
||
flex-shrink: 0;
|
||
gap: 8px;
|
||
padding-bottom: 8px;
|
||
}
|
||
|
||
/* 提成设置弹窗样式暂停使用。
|
||
.commission-toolbar {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 12px;
|
||
margin-bottom: 12px;
|
||
}
|
||
|
||
.commission-tip {
|
||
color: var(--el-text-color-secondary);
|
||
font-size: 13px;
|
||
}
|
||
*/
|
||
|
||
@media (max-width: 768px) {
|
||
.summary-list {
|
||
grid-template-columns: 1fr;
|
||
}
|
||
|
||
.search-card :deep(.el-card__body),
|
||
.summary-card :deep(.el-card__body) {
|
||
padding-right: 12px;
|
||
padding-left: 12px;
|
||
}
|
||
|
||
.table-heading {
|
||
align-items: stretch;
|
||
flex-direction: column;
|
||
gap: 8px;
|
||
}
|
||
|
||
.table-toolbar {
|
||
justify-content: flex-end;
|
||
padding-bottom: 10px;
|
||
}
|
||
}
|
||
</style>
|