支持提号完成后财务调整
This commit is contained in:
@@ -1,13 +1,17 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { EditPen } from '@element-plus/icons-vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { useRoute } from 'vue-router'
|
||||
|
||||
import {
|
||||
fetchAdminPickup,
|
||||
fetchAdminPickupFinancialAdjustments,
|
||||
createAdminPickupFinancialAdjustment,
|
||||
settleAdminPickupFinancialAdjustment,
|
||||
updateAdminPickupProfit,
|
||||
type AdminPickup,
|
||||
type AdminPickupFinancialAdjustment,
|
||||
} from '@/features/admin/api/adminPickup'
|
||||
import { quantity, readNumber, readUnitPrice } from '@/features/orders/composables/useOrderSnapshot'
|
||||
import { adminPath } from '@/shared/utils/adminPath'
|
||||
@@ -33,14 +37,19 @@ interface SnapshotResource {
|
||||
const route = useRoute()
|
||||
const loading = ref(false)
|
||||
const pickup = ref<AdminPickup | null>(null)
|
||||
const financialAdjustments = ref<AdminPickupFinancialAdjustment[]>([])
|
||||
const profitDialogVisible = ref(false)
|
||||
const financialAdjustmentDialogVisible = ref(false)
|
||||
const profitSaving = ref(false)
|
||||
const financialAdjustmentSaving = ref(false)
|
||||
const profitForm = reactive({ profit_amount: 0, reason: '' })
|
||||
const financialAdjustmentForm = reactive({ profit_amount: 0, settle_amount: 0, reason: '' })
|
||||
|
||||
const listingCode = computed(() =>
|
||||
pickup.value ? formatListingNo(pickup.value.listing_no, pickup.value.listing_id) : '-'
|
||||
)
|
||||
const canEditProfit = computed(() => pickup.value?.status === 'picking_up')
|
||||
const canCreateFinancialAdjustment = computed(() => pickup.value?.status === 'completed')
|
||||
const snapshot = computed(() => normalizeRecord(pickup.value?.account_snapshot))
|
||||
const assetSummary = computed(() => normalizeRecord(snapshot.value?.asset_summary))
|
||||
const priceBreakdown = computed(() => normalizeRecord(assetSummary.value?.price_breakdown))
|
||||
@@ -74,15 +83,15 @@ const moneySplitRows = computed(() => {
|
||||
const ownerLossPriceCent =
|
||||
readBreakdownCent('consumable_price') ?? fallbackOwnerLossCent(ownerCoinBasePriceCent)
|
||||
const offlineTotalCent =
|
||||
row.settle_amount_cent > 0 ? row.settle_amount_cent + row.profit_amount_cent : null
|
||||
effectiveSettleCent(row) > 0 ? effectiveSettleCent(row) + effectiveProfitCent(row) : null
|
||||
const rows = [
|
||||
{ label: '网站售价', amountCent: row.listing_price_cent, tone: '' },
|
||||
{ label: '号主纯币价格', amountCent: ownerCoinBasePriceCent, tone: '' },
|
||||
{ label: '号主损耗', amountCent: ownerLossPriceCent, tone: '' },
|
||||
{ label: '号主价合计', amountCent: row.owner_price_cent, tone: 'subtotal' },
|
||||
{ label: '网站加价', amountCent: row.website_profit_cent, tone: '' },
|
||||
{ label: '线下利润', amountCent: row.profit_amount_cent, tone: 'profit' },
|
||||
{ label: '结算给号主', amountCent: row.settle_amount_cent, tone: '' },
|
||||
{ label: '线下利润', amountCent: effectiveProfitCent(row), tone: 'profit' },
|
||||
{ label: '结算给号主', amountCent: effectiveSettleCent(row), tone: '' },
|
||||
]
|
||||
if (offlineTotalCent !== null) {
|
||||
rows.push({ label: '线下成交合计', amountCent: offlineTotalCent, tone: 'total' })
|
||||
@@ -108,12 +117,70 @@ onMounted(loadPickup)
|
||||
async function loadPickup() {
|
||||
loading.value = true
|
||||
try {
|
||||
pickup.value = await fetchAdminPickup(String(route.params.id))
|
||||
const [item, adjustments] = await Promise.all([
|
||||
fetchAdminPickup(String(route.params.id)),
|
||||
fetchAdminPickupFinancialAdjustments(String(route.params.id)),
|
||||
])
|
||||
pickup.value = item
|
||||
financialAdjustments.value = adjustments
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function openFinancialAdjustmentDialog() {
|
||||
if (!pickup.value) return
|
||||
financialAdjustmentForm.profit_amount = centToYuan(effectiveProfitCent(pickup.value))
|
||||
financialAdjustmentForm.settle_amount = centToYuan(effectiveSettleCent(pickup.value))
|
||||
financialAdjustmentForm.reason = ''
|
||||
financialAdjustmentDialogVisible.value = true
|
||||
}
|
||||
|
||||
async function handleFinancialAdjustment() {
|
||||
if (!pickup.value) return
|
||||
if (!financialAdjustmentForm.reason.trim()) {
|
||||
ElMessage.warning('请输入调整原因')
|
||||
return
|
||||
}
|
||||
if (financialAdjustmentForm.profit_amount < 0 || financialAdjustmentForm.settle_amount < 0) {
|
||||
ElMessage.warning('金额不能小于 0')
|
||||
return
|
||||
}
|
||||
financialAdjustmentSaving.value = true
|
||||
try {
|
||||
pickup.value = await createAdminPickupFinancialAdjustment(pickup.value.id, {
|
||||
profit_amount_cent: yuanToCent(financialAdjustmentForm.profit_amount),
|
||||
settle_amount_cent: yuanToCent(financialAdjustmentForm.settle_amount),
|
||||
reason: financialAdjustmentForm.reason.trim(),
|
||||
})
|
||||
financialAdjustments.value = await fetchAdminPickupFinancialAdjustments(pickup.value.id)
|
||||
financialAdjustmentDialogVisible.value = false
|
||||
ElMessage.success('财务调整已创建')
|
||||
} catch (e: unknown) {
|
||||
ElMessage.error(errorMessage(e) || '调整失败')
|
||||
} finally {
|
||||
financialAdjustmentSaving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSettleFinancialAdjustment(item: AdminPickupFinancialAdjustment) {
|
||||
const action = item.status === 'recovery_pending' ? '已追回' : '已线下打款'
|
||||
try {
|
||||
const { value } = await ElMessageBox.prompt(`确认该笔调整${action}?`, '确认调整处理', {
|
||||
confirmButtonText: '确认',
|
||||
cancelButtonText: '取消',
|
||||
inputType: 'textarea',
|
||||
inputPlaceholder: '处理备注(可选)',
|
||||
inputValidator: input => input.length <= 255 || '备注不能超过 255 个字符',
|
||||
})
|
||||
await settleAdminPickupFinancialAdjustment(item.id, { remark: value })
|
||||
financialAdjustments.value = await fetchAdminPickupFinancialAdjustments(item.pickup_id)
|
||||
ElMessage.success('调整已确认')
|
||||
} catch {
|
||||
// 用户取消确认。
|
||||
}
|
||||
}
|
||||
|
||||
function openProfitDialog() {
|
||||
if (!pickup.value) return
|
||||
profitForm.profit_amount = centToYuan(pickup.value.profit_amount_cent)
|
||||
@@ -168,6 +235,34 @@ function offlineSettlementLabel(row: AdminPickup) {
|
||||
return '待完成提号'
|
||||
}
|
||||
|
||||
function effectiveProfitCent(row: AdminPickup) {
|
||||
return Number.isFinite(row.effective_profit_amount_cent)
|
||||
? row.effective_profit_amount_cent
|
||||
: row.profit_amount_cent
|
||||
}
|
||||
|
||||
function effectiveSettleCent(row: AdminPickup) {
|
||||
return Number.isFinite(row.effective_settle_amount_cent)
|
||||
? row.effective_settle_amount_cent
|
||||
: row.settle_amount_cent
|
||||
}
|
||||
|
||||
function financialAdjustmentStatusLabel(status: AdminPickupFinancialAdjustment['status']) {
|
||||
if (status === 'pending') return '待线下处理'
|
||||
if (status === 'recovery_pending') return '待追回'
|
||||
return '已处理'
|
||||
}
|
||||
|
||||
function financialAdjustmentStatusType(status: AdminPickupFinancialAdjustment['status']) {
|
||||
if (status === 'pending' || status === 'recovery_pending') return 'warning'
|
||||
return 'success'
|
||||
}
|
||||
|
||||
function formatSignedCent(value: number) {
|
||||
const amount = formatCentWithSymbol(Math.abs(value))
|
||||
return value > 0 ? `+${amount}` : value < 0 ? `-${amount}` : amount
|
||||
}
|
||||
|
||||
function ratioText(value: number) {
|
||||
const ratio = Number(value || 0)
|
||||
if (ratio <= 0) return '-'
|
||||
@@ -261,6 +356,15 @@ function readSnapshotResources(summary: Record<string, unknown> | null): Snapsho
|
||||
>
|
||||
修改利润
|
||||
</el-button>
|
||||
<el-button
|
||||
v-if="canCreateFinancialAdjustment"
|
||||
type="primary"
|
||||
plain
|
||||
:icon="EditPen"
|
||||
@click="openFinancialAdjustmentDialog"
|
||||
>
|
||||
财务调整
|
||||
</el-button>
|
||||
<RouterLink :to="adminPath('pickup')">
|
||||
<el-button>返回列表</el-button>
|
||||
</RouterLink>
|
||||
@@ -275,12 +379,12 @@ function readSnapshotResources(summary: Record<string, unknown> | null): Snapsho
|
||||
</div>
|
||||
<div class="metric-card">
|
||||
<span>线下利润</span>
|
||||
<strong>{{ formatCentWithSymbol(pickup.profit_amount_cent) }}</strong>
|
||||
<strong>{{ formatCentWithSymbol(effectiveProfitCent(pickup)) }}</strong>
|
||||
<small>财务统计使用该金额</small>
|
||||
</div>
|
||||
<div class="metric-card">
|
||||
<span>结算金额</span>
|
||||
<strong>{{ formatCentWithSymbol(pickup.settle_amount_cent) }}</strong>
|
||||
<strong>{{ formatCentWithSymbol(effectiveSettleCent(pickup)) }}</strong>
|
||||
<small>{{ pickup.completed_at ? formatDateTime(pickup.completed_at) : '待结算' }}</small>
|
||||
</div>
|
||||
<div class="metric-card">
|
||||
@@ -363,6 +467,52 @@ function readSnapshotResources(summary: Record<string, unknown> | null): Snapsho
|
||||
</dl>
|
||||
</section>
|
||||
|
||||
<section
|
||||
v-if="financialAdjustments.length"
|
||||
class="dashboard-panel detail-panel pickup-wide-panel"
|
||||
>
|
||||
<div class="panel-heading">
|
||||
<h2>财务调整记录</h2>
|
||||
<span class="panel-subtitle">原始完成金额不变,调整按创建日计入财务</span>
|
||||
</div>
|
||||
<el-table :data="financialAdjustments" size="small" class="adjustment-table">
|
||||
<el-table-column label="利润调整" width="130">
|
||||
<template #default="{ row }">{{ formatSignedCent(row.profit_delta_cent) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="打款调整" width="130">
|
||||
<template #default="{ row }">{{ formatSignedCent(row.settle_delta_cent) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="处理状态" width="130">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="financialAdjustmentStatusType(row.status)" effect="light" size="small">
|
||||
{{ financialAdjustmentStatusLabel(row.status) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="reason" label="调整原因" min-width="180" />
|
||||
<el-table-column label="创建时间" width="170">
|
||||
<template #default="{ row }">{{ formatDateTime(row.created_at) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="120" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button
|
||||
v-if="
|
||||
row.status === 'recovery_pending' ||
|
||||
(row.status === 'pending' && pickup?.offline_settlement_status !== 'pending')
|
||||
"
|
||||
size="small"
|
||||
type="primary"
|
||||
plain
|
||||
@click="handleSettleFinancialAdjustment(row)"
|
||||
>
|
||||
{{ row.status === 'recovery_pending' ? '确认追回' : '确认打款' }}
|
||||
</el-button>
|
||||
<span v-else class="text-muted">{{ formatDateTime(row.settled_at, '-') }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</section>
|
||||
|
||||
<section class="dashboard-panel detail-panel">
|
||||
<div class="panel-heading">
|
||||
<h2>资金拆分</h2>
|
||||
@@ -475,6 +625,58 @@ function readSnapshotResources(summary: Record<string, unknown> | null): Snapsho
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog v-model="financialAdjustmentDialogVisible" title="完成后财务调整" width="500px">
|
||||
<el-form label-width="130px">
|
||||
<el-form-item label="目标利润(元)">
|
||||
<el-input-number
|
||||
v-model="financialAdjustmentForm.profit_amount"
|
||||
:min="0"
|
||||
:step="1"
|
||||
:precision="2"
|
||||
controls-position="right"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="目标打款金额(元)">
|
||||
<el-input-number
|
||||
v-model="financialAdjustmentForm.settle_amount"
|
||||
:min="0"
|
||||
:step="1"
|
||||
:precision="2"
|
||||
controls-position="right"
|
||||
style="width: 100%"
|
||||
/>
|
||||
<div class="form-hint">
|
||||
{{
|
||||
pickup?.settlement_mode === 'platform_managed'
|
||||
? '会生成待线下补款或待追回记录'
|
||||
: '增加金额立即补入钱包,减少金额生成待追回记录'
|
||||
}}
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="调整原因" required>
|
||||
<el-input
|
||||
v-model="financialAdjustmentForm.reason"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
maxlength="255"
|
||||
show-word-limit
|
||||
placeholder="请输入调整原因"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="financialAdjustmentDialogVisible = false">取消</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
:loading="financialAdjustmentSaving"
|
||||
@click="handleFinancialAdjustment"
|
||||
>
|
||||
确认调整
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
@@ -498,6 +700,17 @@ function readSnapshotResources(summary: Record<string, unknown> | null): Snapsho
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.form-hint {
|
||||
margin-top: 4px;
|
||||
color: #64748b;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.adjustment-table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.pickup-detail-grid {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1.1fr) minmax(360px, 0.9fr);
|
||||
|
||||
Reference in New Issue
Block a user