优化线下提号利润修改
This commit is contained in:
@@ -1,12 +1,23 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { EditPen } from '@element-plus/icons-vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { useRoute } from 'vue-router'
|
||||
|
||||
import { fetchAdminPickup, type AdminPickup } from '@/features/admin/api/adminPickup'
|
||||
import {
|
||||
fetchAdminPickup,
|
||||
updateAdminPickupProfit,
|
||||
type AdminPickup,
|
||||
} from '@/features/admin/api/adminPickup'
|
||||
import { quantity, readNumber, readUnitPrice } from '@/features/orders/composables/useOrderSnapshot'
|
||||
import { adminPath } from '@/shared/utils/adminPath'
|
||||
import { formatListingNo } from '@/shared/utils/listingDisplay'
|
||||
import { formatCentWithSymbol, formatMoneyWithSymbol } from '@/shared/utils/money'
|
||||
import {
|
||||
centToYuan,
|
||||
formatCentWithSymbol,
|
||||
formatMoneyWithSymbol,
|
||||
yuanToCent,
|
||||
} from '@/shared/utils/money'
|
||||
import { pickupStatusLabel } from '@/shared/utils/statusLabels'
|
||||
import { formatDateTime } from '@/shared/utils/time'
|
||||
|
||||
@@ -22,10 +33,14 @@ interface SnapshotResource {
|
||||
const route = useRoute()
|
||||
const loading = ref(false)
|
||||
const pickup = ref<AdminPickup | null>(null)
|
||||
const profitDialogVisible = ref(false)
|
||||
const profitSaving = ref(false)
|
||||
const profitForm = reactive({ profit_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 snapshot = computed(() => normalizeRecord(pickup.value?.account_snapshot))
|
||||
const assetSummary = computed(() => normalizeRecord(snapshot.value?.asset_summary))
|
||||
const priceBreakdown = computed(() => normalizeRecord(assetSummary.value?.price_breakdown))
|
||||
@@ -99,6 +114,34 @@ async function loadPickup() {
|
||||
}
|
||||
}
|
||||
|
||||
function openProfitDialog() {
|
||||
if (!pickup.value) return
|
||||
profitForm.profit_amount = centToYuan(pickup.value.profit_amount_cent)
|
||||
profitForm.reason = ''
|
||||
profitDialogVisible.value = true
|
||||
}
|
||||
|
||||
async function handleUpdateProfit() {
|
||||
if (!pickup.value) return
|
||||
if (profitForm.profit_amount < 0) {
|
||||
ElMessage.warning('线下利润不能为负数')
|
||||
return
|
||||
}
|
||||
profitSaving.value = true
|
||||
try {
|
||||
pickup.value = await updateAdminPickupProfit(pickup.value.id, {
|
||||
profit_amount_cent: yuanToCent(profitForm.profit_amount),
|
||||
reason: profitForm.reason,
|
||||
})
|
||||
ElMessage.success('线下利润已更新')
|
||||
profitDialogVisible.value = false
|
||||
} catch (e: unknown) {
|
||||
ElMessage.error(errorMessage(e) || '修改失败')
|
||||
} finally {
|
||||
profitSaving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function statusType(status: string) {
|
||||
if (status === 'picking_up') return 'warning'
|
||||
if (status === 'completed') return 'success'
|
||||
@@ -118,6 +161,13 @@ function displayValue(value: unknown) {
|
||||
return String(value)
|
||||
}
|
||||
|
||||
function errorMessage(e: unknown) {
|
||||
if (typeof e === 'object' && e !== null && 'message' in e) {
|
||||
return String((e as { message?: unknown }).message)
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
function readBreakdownCent(key: string) {
|
||||
const value = readNumber(priceBreakdown.value?.[key])
|
||||
return value > 0 ? Math.round(value * 100) : null
|
||||
@@ -183,6 +233,15 @@ function readSnapshotResources(summary: Record<string, unknown> | null): Snapsho
|
||||
</p>
|
||||
</div>
|
||||
<div class="toolbar-actions">
|
||||
<el-button
|
||||
v-if="canEditProfit"
|
||||
type="primary"
|
||||
plain
|
||||
:icon="EditPen"
|
||||
@click="openProfitDialog"
|
||||
>
|
||||
修改利润
|
||||
</el-button>
|
||||
<RouterLink :to="adminPath('pickup')">
|
||||
<el-button>返回列表</el-button>
|
||||
</RouterLink>
|
||||
@@ -259,7 +318,7 @@ function readSnapshotResources(summary: Record<string, unknown> | null): Snapsho
|
||||
<section class="dashboard-panel detail-panel">
|
||||
<div class="panel-heading">
|
||||
<h2>资金拆分</h2>
|
||||
<span class="panel-subtitle">提号创建时固化</span>
|
||||
<span class="panel-subtitle">价格快照来自创建时</span>
|
||||
</div>
|
||||
<div class="money-list">
|
||||
<div
|
||||
@@ -333,6 +392,37 @@ function readSnapshotResources(summary: Record<string, unknown> | null): Snapsho
|
||||
<pre class="snapshot-json">{{ snapshotText }}</pre>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<el-dialog v-model="profitDialogVisible" title="修改线下利润" width="460px">
|
||||
<el-form label-width="110px">
|
||||
<el-form-item label="线下利润(元)" required>
|
||||
<el-input-number
|
||||
v-model="profitForm.profit_amount"
|
||||
:min="0"
|
||||
:step="1"
|
||||
:precision="2"
|
||||
controls-position="right"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="修改原因">
|
||||
<el-input
|
||||
v-model="profitForm.reason"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
maxlength="255"
|
||||
show-word-limit
|
||||
placeholder="可选"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="profitDialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="profitSaving" @click="handleUpdateProfit">
|
||||
保存
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user