判断是否有签名换到长链接推送 然后添加 报关价 预估退税计算

This commit is contained in:
浅念
2025-10-14 14:43:09 +08:00
parent 153bb37d10
commit 16abb6364c
10 changed files with 829 additions and 236 deletions
+86 -23
View File
@@ -1,4 +1,4 @@
import { ref, reactive, watch, onMounted } from 'vue'
import { ref, reactive, watch, onMounted, nextTick } from 'vue'
import { componentSizeMap, ElMessage } from 'element-plus'
import { CrmService } from '@/api/crmApi'
import { commonService } from '@/api/commonApi'
@@ -75,6 +75,9 @@ export interface ItemRow {
tax_refund: string
tax_refund_currency: string
tax_refund_currency_snapshot: string
clearance_price: number | undefined
clearance_price_currency: string
clearance_price_currency_snapshot: string
retrofit_fee: string
total_price: number | undefined
official_price: number | undefined
@@ -133,6 +136,8 @@ export interface DialogState {
export function useStockingForm(isFinal = false, stockingId?: string | number) {
const { uploadHeaders } = useUploadHeaders()
const actionImageUplode = `${import.meta.env.VITE_API_URL}/ticket/upload?scene=stock_orders`
// 回显填充抑制标记:为 true 时不触发自动计算覆盖接口值
const isPopulating = ref(false)
// 选项数据
const channelOptions = ref<any>()
@@ -218,6 +223,9 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) {
tax_refund: '',
tax_refund_currency: 'CNY',
tax_refund_currency_snapshot: '人民币',
clearance_price: undefined,
clearance_price_currency: 'CNY',
clearance_price_currency_snapshot: '人民币',
retrofit_fee: '',
total_price: undefined,
official_price: undefined,
@@ -484,16 +492,9 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) {
)
return (
unit -
(retrofit +
fob +
listing +
reduction +
handling +
port +
ocean +
commission +
purchaseTax) +
taxRefund
(retrofit + fob + listing + handling + port + ocean + commission + purchaseTax) +
taxRefund +
reduction
)
}
@@ -510,11 +511,42 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) {
)
return (
unit -
(retrofit + fob + guide + discount + handling + port + ocean + commission + purchaseTax) +
taxRefund
(retrofit + fob + guide + handling + port + ocean + commission + purchaseTax) +
taxRefund +
discount
)
}
const calcClearanceFee = (it: any): number => {
const targetCurrency = baseForm.settlement_currency || 'USD'
const unit = convertCurrency(it.unit_price, it.unit_price_currency, targetCurrency)
const commission = convertCurrency(
it.commission ?? (it as any).commission,
(it as any).commission_currency,
targetCurrency
)
return unit - commission
}
const calcTaxRefund = (it: any): number => {
const mileageVal = Number(it.mileage ?? 0)
if (mileageVal > 0) return 0
const targetCurrency = baseForm.settlement_currency || 'USD'
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 : refund
}
// 合同文件相关方法
const isImageFile = (file: { name: string; url: string; file_name: string }) => {
return /\.(jpg|jpeg|png|gif)$/i.test(file.name) || file.file_name.startsWith('image/')
@@ -675,6 +707,7 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) {
// 数据回显方法
const populateFromDetail = (res: any) => {
if (!res) return
isPopulating.value = true
// 基础信息
baseForm.pick_up_date = res.pick_up_date || ''
baseForm.collect_all_date = res.collect_all_date || ''
@@ -703,7 +736,7 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) {
baseForm.remark = res.remark || ''
baseForm.settlement_currency = res.settlement_currency || 'CNY'
// 合计与汇率
baseForm.total_cif = res.cif_total_amount ? Number(res.cif_total_amount) : undefined
baseForm.total_cif = res.cif_total_amount.amount ? Number(res.cif_total_amount.amount) : undefined
baseForm.total_cif_currency = res.settlement_currency || baseForm.total_cif_currency
baseForm.contract_exchange_rate =
res.contract_exchange_rate || getCurrencyRate(baseForm.total_cif_currency)
@@ -739,9 +772,6 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) {
purchase_tax: it.purchase_tax?.amount ?? '',
purchase_tax_currency: it.purchase_tax?.currency || 'CNY',
purchase_tax_currency_snapshot: '',
tax_refund: it.tax_refund?.amount ?? '',
tax_refund_currency: it.tax_refund?.currency || 'CNY',
tax_refund_currency_snapshot: '',
retrofit_fee: it.retrofit_fee?.amount ?? '',
total_price: it.total_price?.amount ? Number(it.total_price.amount) : undefined,
official_price: it.official_price?.amount ? Number(it.official_price.amount) : undefined,
@@ -768,14 +798,20 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) {
discount_currency: it.discount_price?.currency || 'CNY',
discount_currency_snapshot: '',
contract_rate: baseForm.contract_exchange_rate ? Number(baseForm.contract_exchange_rate) : undefined,
profit: undefined,
profit: it.profit?.amount ? Number(it.profit.amount) : undefined,
profit_type_snapshot: '',
clearance_price: it.clearance_price?.amount ? Number(it.clearance_price.amount) : undefined,
clearance_price_currency: it.clearance_price?.currency || 'CNY',
clearance_price_currency_snapshot: '',
modify_ids: Array.isArray(it.modify_list) ? it.modify_list.map((m: any) => Number(m.option_id)) : [],
modify_list: Array.isArray(it.modify_list)
? it.modify_list.map((m: any) => ({ option_id: String(m.option_id), option_name_snapshot: m.option_name_snapshot }))
: [],
modify_fee_currency: it.retrofit_fee?.currency || 'CNY',
modify_fee_currency_snapshot: ''
modify_fee_currency_snapshot: '',
tax_refund: it.tax_refund?.amount ?? '',
tax_refund_currency: it.tax_refund?.currency || 'CNY',
tax_refund_currency_snapshot: ''
}))
// 计划收款
const pays = Array.isArray(res.account_list) ? res.account_list : []
@@ -798,6 +834,8 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) {
file_name: res.contract
}
}
// 等待本轮变更完成后,再恢复自动计算
nextTick(() => { isPopulating.value = false })
}
// 提交方法
@@ -836,7 +874,8 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) {
ocean_freight: wrapMoney(it.ocean_freight, (it as any).ocean_freight_currency, '海运费'),
commission: wrapMoney(it.commission, (it as any).commission_currency, '佣金'),
purchase_tax: wrapMoney(it.purchase_tax, (it as any).purchase_tax_currency, '购置税'),
tax_refund: wrapMoney(it.tax_refund, (it as any).tax_refund_currency, '退税'),
// tax_refund: wrapMoney(it.tax_refund, (it as any).tax_refund_currency, '退税'),
tax_refund: wrapMoney(it.tax_refund, baseForm.settlement_currency, '退税'),
retrofit_fee: wrapMoney((it as any).retrofit_fee, (it as any).modify_fee_currency, '改装费'),
modify_list: it.modify_list,
// total_price: wrapMoney(it.total_price, (it as any).total_price_currency, '总价'),
@@ -851,8 +890,14 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) {
(it as any).discount_currency,
'优惠额'
),
profit: wrapMoney(it.profit, baseForm.settlement_currency, '利润'),
listing_price: wrapMoney(it.listing_price, (it as any).listing_price_currency, '挂牌价'),
reduction_price: wrapMoney(it.reduction_price, (it as any).reduction_price_currency, '二手减价')
reduction_price: wrapMoney(
it.reduction_price,
(it as any).reduction_price_currency,
'二手减价'
),
clearance_price: wrapMoney(it.clearance_price, baseForm.settlement_currency, '报关价')
}))
// 从提交参数中移除 settlement_currency
@@ -867,6 +912,7 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) {
account_list: paymentItems.value,
approval_status: type
}
console.log(payload)
try {
if (edit) {
@@ -887,7 +933,7 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) {
}
}, 1000)
} catch (e) {
ElMessage.error('保存失败')
// ElMessage.error('保存失败')
}
}
@@ -895,6 +941,7 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) {
watch(
() => baseForm.settlement_currency,
(newCurrency) => {
if (isPopulating.value) return
if (newCurrency) {
baseForm.contract_exchange_rate = getCurrencyRate(newCurrency)
if (typeof validateContractRate === 'function') {
@@ -904,6 +951,13 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) {
(items.value || []).forEach((it: any, index: number) => {
const profit = calcProfit(it)
if (items.value[index]) items.value[index].profit = isNaN(profit) ? 0 : Number(profit.toFixed(2))
const clearance = calcClearanceFee(it)
if (items.value[index]) items.value[index].clearance_price = isNaN(clearance) ? 0 : Number(clearance.toFixed(2))
const refund = calcTaxRefund(it)
if (items.value[index]) {
items.value[index].tax_refund = isNaN(refund) ? 0 : Number(refund.toFixed(2)) as any
;(items.value[index] as any).tax_refund_currency = baseForm.settlement_currency || 'USD'
}
})
}
}
@@ -923,11 +977,18 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) {
watch(
items,
(val) => {
if (isPopulating.value) return
val.forEach((it: any, index: number) => {
const profit = calcProfit(it)
if (items.value[index]) items.value[index].profit = isNaN(profit) ? 0 : Number(profit.toFixed(2))
const clearance = calcClearanceFee(it)
if (items.value[index]) items.value[index].clearance_price = isNaN(clearance) ? 0 : Number(clearance.toFixed(2))
const refund = calcTaxRefund(it)
if (items.value[index]) {
items.value[index].tax_refund = isNaN(refund) ? 0 : Number(refund.toFixed(2)) as any
;(items.value[index] as any).tax_refund_currency = baseForm.settlement_currency || 'USD'
}
})
// 合计到岸价 = 所有单价相加
const sum = (val || []).reduce((acc: number, cur: any) => {
const n = cur?.unit_price === undefined || cur?.unit_price === null || cur?.unit_price === '' ? 0 : Number(cur.unit_price)
@@ -1004,6 +1065,8 @@ export function useStockingForm(isFinal = false, stockingId?: string | number) {
validateContractRate,
wrapMoney,
calcProfit,
calcClearanceFee,
calcTaxRefund,
// 合同文件方法
isImageFile,