diff --git a/src/composables/useStockingForm.ts b/src/composables/useStockingForm.ts index 886005b..b765aa4 100644 --- a/src/composables/useStockingForm.ts +++ b/src/composables/useStockingForm.ts @@ -158,7 +158,6 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) { // 回显填充抑制标记:为 true 时不触发自动计算覆盖接口值 const isPopulating = ref(false) const userEditing = ref>(new Set()) // 跟踪用户正在编辑的行 - const manualTaxRefundRows = ref>(new Set()) // 跟踪用户手动编辑过预估退税额的行 // 选项数据 const channelOptions = ref() @@ -622,26 +621,6 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) { 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运费 - 港杂费 - 海运费 const calcCarPrice = (it: any): number => { 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 copied = JSON.parse(JSON.stringify(items.value[idx])) as ItemRow items.value.splice(idx + 1, 0, copied) - // 如果原行是手动编辑的,复制的行也标记为手动编辑 - if (manualTaxRefundRows.value.has(idx)) { - // 需要调整后续行的索引 - const newManualRows = new Set() - 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) => { items.value.splice(idx + 1, 0, newItem()) - // 调整后续行的手动编辑标记索引 - const newManualRows = new Set() - manualTaxRefundRows.value.forEach((rowIdx) => { - if (rowIdx <= idx) { - newManualRows.add(rowIdx) - } else { - newManualRows.add(rowIdx + 1) - } - }) - manualTaxRefundRows.value = newManualRows } const removeRow = (idx: number) => { items.value.splice(idx, 1) - // 移除该行的手动编辑标记,并调整后续行的索引 - const newManualRows = new Set() - 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(() => { - // 检查哪些行的预估退税额与自动计算值不同,标记为手动编辑 - 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 }) } @@ -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) if (items.value[index]) { @@ -1500,40 +1425,15 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) { { deep: true } ) - // 存储上一次的 tax_refund 值,用于检测用户手动输入 - const prevTaxRefundValues = ref([]) - - // 当用户手动输入预估退税额时,重新计算利润 + // 预估退税额为手动输入,输入变化时重新计算利润 watch( () => items.value.map((item: any) => item.tax_refund), - (newValues) => { + () => { 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) => { 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) items.value[index].profit = isNaN(profit) ? 0 : Number(profit.toFixed(2)) @@ -1621,7 +1521,6 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) { wrapMoney, calcProfit, calcClearanceFee, - calcTaxRefund, handleUserEdit, // 合同文件方法 diff --git a/src/views/crmpc/stocking/Add.vue b/src/views/crmpc/stocking/Add.vue index 963144d..05c168c 100644 --- a/src/views/crmpc/stocking/Add.vue +++ b/src/views/crmpc/stocking/Add.vue @@ -457,7 +457,7 @@