feat(stocking): 取消预估退税自动计算,改为纯手动输入
移除 watch 中的 (官方价-优惠)*11.5% 自动写入与手动编辑跟踪 (manualTaxRefundRows/prevTaxRefundValues/calcTaxRefund), 保留手动输入后利润联动重算;placeholder 改为请输入。 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -158,7 +158,6 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) {
|
|||||||
// 回显填充抑制标记:为 true 时不触发自动计算覆盖接口值
|
// 回显填充抑制标记:为 true 时不触发自动计算覆盖接口值
|
||||||
const isPopulating = ref(false)
|
const isPopulating = ref(false)
|
||||||
const userEditing = ref<Set<number>>(new Set()) // 跟踪用户正在编辑的行
|
const userEditing = ref<Set<number>>(new Set()) // 跟踪用户正在编辑的行
|
||||||
const manualTaxRefundRows = ref<Set<number>>(new Set()) // 跟踪用户手动编辑过预估退税额的行
|
|
||||||
|
|
||||||
// 选项数据
|
// 选项数据
|
||||||
const channelOptions = ref<any>()
|
const channelOptions = ref<any>()
|
||||||
@@ -622,26 +621,6 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) {
|
|||||||
return unit - retention
|
return unit - retention
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算预估退税额 = (官方价 - 折扣价) * 11.5% (固定人民币)
|
|
||||||
const calcTaxRefund = (it: any): number => {
|
|
||||||
const mileageVal = Number(it.mileage ?? 0)
|
|
||||||
if (mileageVal > 0) return 0
|
|
||||||
const targetCurrency = 'CNY' // 固定使用人民币
|
|
||||||
const official = convertCurrency(
|
|
||||||
it.official_price ?? (it as any).guide_price,
|
|
||||||
(it as any).guide_price_currency,
|
|
||||||
targetCurrency
|
|
||||||
)
|
|
||||||
const discount = convertCurrency(
|
|
||||||
it.discount_price ?? (it as any).discount,
|
|
||||||
(it as any).discount_currency,
|
|
||||||
targetCurrency
|
|
||||||
)
|
|
||||||
const base = official - discount
|
|
||||||
const refund = base * 0.115
|
|
||||||
return refund < 0 ? 0 : Number(refund.toFixed(2))
|
|
||||||
}
|
|
||||||
|
|
||||||
// 计算车价:车价 = 报关价 - FOB运费 - 港杂费 - 海运费
|
// 计算车价:车价 = 报关价 - FOB运费 - 港杂费 - 海运费
|
||||||
const calcCarPrice = (it: any): number => {
|
const calcCarPrice = (it: any): number => {
|
||||||
const targetCurrency = it.car_price_currency || baseForm.settlement_currency || 'CNY'
|
const targetCurrency = it.car_price_currency || baseForm.settlement_currency || 'CNY'
|
||||||
@@ -811,49 +790,14 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) {
|
|||||||
const copyRow = (idx: number) => {
|
const copyRow = (idx: number) => {
|
||||||
const copied = JSON.parse(JSON.stringify(items.value[idx])) as ItemRow
|
const copied = JSON.parse(JSON.stringify(items.value[idx])) as ItemRow
|
||||||
items.value.splice(idx + 1, 0, copied)
|
items.value.splice(idx + 1, 0, copied)
|
||||||
// 如果原行是手动编辑的,复制的行也标记为手动编辑
|
|
||||||
if (manualTaxRefundRows.value.has(idx)) {
|
|
||||||
// 需要调整后续行的索引
|
|
||||||
const newManualRows = new Set<number>()
|
|
||||||
manualTaxRefundRows.value.forEach((rowIdx) => {
|
|
||||||
if (rowIdx <= idx) {
|
|
||||||
newManualRows.add(rowIdx)
|
|
||||||
} else {
|
|
||||||
newManualRows.add(rowIdx + 1)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
newManualRows.add(idx + 1) // 新复制的行
|
|
||||||
manualTaxRefundRows.value = newManualRows
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const addRowAfter = (idx: number) => {
|
const addRowAfter = (idx: number) => {
|
||||||
items.value.splice(idx + 1, 0, newItem())
|
items.value.splice(idx + 1, 0, newItem())
|
||||||
// 调整后续行的手动编辑标记索引
|
|
||||||
const newManualRows = new Set<number>()
|
|
||||||
manualTaxRefundRows.value.forEach((rowIdx) => {
|
|
||||||
if (rowIdx <= idx) {
|
|
||||||
newManualRows.add(rowIdx)
|
|
||||||
} else {
|
|
||||||
newManualRows.add(rowIdx + 1)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
manualTaxRefundRows.value = newManualRows
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const removeRow = (idx: number) => {
|
const removeRow = (idx: number) => {
|
||||||
items.value.splice(idx, 1)
|
items.value.splice(idx, 1)
|
||||||
// 移除该行的手动编辑标记,并调整后续行的索引
|
|
||||||
const newManualRows = new Set<number>()
|
|
||||||
manualTaxRefundRows.value.forEach((rowIdx) => {
|
|
||||||
if (rowIdx < idx) {
|
|
||||||
newManualRows.add(rowIdx)
|
|
||||||
} else if (rowIdx > idx) {
|
|
||||||
newManualRows.add(rowIdx - 1)
|
|
||||||
}
|
|
||||||
// rowIdx === idx 的行被删除,不添加到新集合中
|
|
||||||
})
|
|
||||||
manualTaxRefundRows.value = newManualRows
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 收款项操作方法
|
// 收款项操作方法
|
||||||
@@ -1197,16 +1141,6 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) {
|
|||||||
}
|
}
|
||||||
// 等待本轮变更完成后,再恢复自动计算
|
// 等待本轮变更完成后,再恢复自动计算
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
// 检查哪些行的预估退税额与自动计算值不同,标记为手动编辑
|
|
||||||
items.value.forEach((it: any, index: number) => {
|
|
||||||
const currentValue = String(it.tax_refund || '')
|
|
||||||
const autoCalculatedValue = String(calcTaxRefund(it) || '0')
|
|
||||||
if (currentValue !== autoCalculatedValue && currentValue !== '' && currentValue !== '0') {
|
|
||||||
manualTaxRefundRows.value.add(index)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
// 初始化 prevTaxRefundValues
|
|
||||||
prevTaxRefundValues.value = items.value.map((item: any) => String(item.tax_refund || ''))
|
|
||||||
isPopulating.value = false
|
isPopulating.value = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -1442,15 +1376,6 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 自动计算预估退税额(跳过用户手动编辑过的行)
|
|
||||||
if (!manualTaxRefundRows.value.has(index)) {
|
|
||||||
const refund = calcTaxRefund(it)
|
|
||||||
if (items.value[index]) {
|
|
||||||
items.value[index].tax_refund = isNaN(refund) ? '0' : String(Number(refund.toFixed(2)))
|
|
||||||
;(items.value[index] as any).tax_refund_currency = 'CNY'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 自动计算车价
|
// 自动计算车价
|
||||||
const carPrice = calcCarPrice(it)
|
const carPrice = calcCarPrice(it)
|
||||||
if (items.value[index]) {
|
if (items.value[index]) {
|
||||||
@@ -1500,40 +1425,15 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) {
|
|||||||
{ deep: true }
|
{ deep: true }
|
||||||
)
|
)
|
||||||
|
|
||||||
// 存储上一次的 tax_refund 值,用于检测用户手动输入
|
// 预估退税额为手动输入,输入变化时重新计算利润
|
||||||
const prevTaxRefundValues = ref<string[]>([])
|
|
||||||
|
|
||||||
// 当用户手动输入预估退税额时,重新计算利润
|
|
||||||
watch(
|
watch(
|
||||||
() => items.value.map((item: any) => item.tax_refund),
|
() => items.value.map((item: any) => item.tax_refund),
|
||||||
(newValues) => {
|
() => {
|
||||||
if (isPopulating.value) return
|
if (isPopulating.value) return
|
||||||
|
|
||||||
// 初始化 prevTaxRefundValues
|
|
||||||
if (prevTaxRefundValues.value.length === 0) {
|
|
||||||
prevTaxRefundValues.value = newValues.map((v: any) => String(v || ''))
|
|
||||||
}
|
|
||||||
|
|
||||||
items.value.forEach((it: any, index: number) => {
|
items.value.forEach((it: any, index: number) => {
|
||||||
if (!items.value[index]) return
|
if (!items.value[index]) return
|
||||||
|
|
||||||
const currentValue = String(it.tax_refund || '')
|
|
||||||
const prevValue = prevTaxRefundValues.value[index] || ''
|
|
||||||
const autoCalculatedValue = String(calcTaxRefund(it) || '0')
|
|
||||||
|
|
||||||
// 如果当前值与自动计算值不同,且与上一次值不同,说明是用户手动输入的
|
|
||||||
if (
|
|
||||||
currentValue !== autoCalculatedValue &&
|
|
||||||
currentValue !== prevValue &&
|
|
||||||
currentValue !== ''
|
|
||||||
) {
|
|
||||||
// 标记该行已被用户手动编辑
|
|
||||||
manualTaxRefundRows.value.add(index)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新上一次的值
|
|
||||||
prevTaxRefundValues.value[index] = currentValue
|
|
||||||
|
|
||||||
// 重新计算利润
|
// 重新计算利润
|
||||||
const profit = calcProfit(it)
|
const profit = calcProfit(it)
|
||||||
items.value[index].profit = isNaN(profit) ? 0 : Number(profit.toFixed(2))
|
items.value[index].profit = isNaN(profit) ? 0 : Number(profit.toFixed(2))
|
||||||
@@ -1621,7 +1521,6 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) {
|
|||||||
wrapMoney,
|
wrapMoney,
|
||||||
calcProfit,
|
calcProfit,
|
||||||
calcClearanceFee,
|
calcClearanceFee,
|
||||||
calcTaxRefund,
|
|
||||||
handleUserEdit,
|
handleUserEdit,
|
||||||
|
|
||||||
// 合同文件方法
|
// 合同文件方法
|
||||||
|
|||||||
@@ -457,7 +457,7 @@
|
|||||||
<ElFormItem label="预估退税额" label-width="85px">
|
<ElFormItem label="预估退税额" label-width="85px">
|
||||||
<ElInput
|
<ElInput
|
||||||
v-model="item.tax_refund"
|
v-model="item.tax_refund"
|
||||||
placeholder="正在计算预估退税额"
|
placeholder="请输入预估退税额"
|
||||||
@input="handleUserEdit(idx)"
|
@input="handleUserEdit(idx)"
|
||||||
>
|
>
|
||||||
<template #suffix>
|
<template #suffix>
|
||||||
|
|||||||
@@ -480,7 +480,7 @@
|
|||||||
<ElFormItem label="预估退税额" label-width="85px">
|
<ElFormItem label="预估退税额" label-width="85px">
|
||||||
<ElInput
|
<ElInput
|
||||||
v-model="item.tax_refund"
|
v-model="item.tax_refund"
|
||||||
placeholder="正在计算预估退税额"
|
placeholder="请输入预估退税额"
|
||||||
@input="handleUserEdit(idx)"
|
@input="handleUserEdit(idx)"
|
||||||
>
|
>
|
||||||
<template #suffix>
|
<template #suffix>
|
||||||
|
|||||||
@@ -479,7 +479,7 @@
|
|||||||
<ElFormItem label="预估退税额" label-width="85px">
|
<ElFormItem label="预估退税额" label-width="85px">
|
||||||
<ElInput
|
<ElInput
|
||||||
v-model="item.tax_refund"
|
v-model="item.tax_refund"
|
||||||
placeholder="正在计算预估退税额"
|
placeholder="请输入预估退税额"
|
||||||
@input="handleUserEdit(idx)"
|
@input="handleUserEdit(idx)"
|
||||||
>
|
>
|
||||||
<template #suffix>
|
<template #suffix>
|
||||||
|
|||||||
Reference in New Issue
Block a user