提交
This commit is contained in:
1 parent
cedb7ee681
commit
c90f72fd34
22 files changed
+5163
-3825
No files matched your search
@@ -48,7 +48,7 @@ export function mapContractProductToPlanRow(item: ContractProductForm, index: nu
|
||||
categoryName: item.categoryName,
|
||||
unit: item.unit || '吨',
|
||||
quantity: Number(item.quantity || 0),
|
||||
actualQty: Number(item.quantity || 0),
|
||||
actualQty: 0,
|
||||
packageSpec: item.packageSpec,
|
||||
deliveryMethod: item.deliveryMethod,
|
||||
taxRate: item.taxRate != null ? Number(item.taxRate) : undefined,
|
||||
|
||||
@@ -38,6 +38,7 @@ export function mapPlanProductToFormRow(item: PlanProduct, index: number): PlanF
|
||||
),
|
||||
packageSpec: item.packageSpec,
|
||||
deliveryMethod: item.deliveryMethod,
|
||||
taxRate: item.taxRate != null ? Number(item.taxRate) : undefined,
|
||||
taxPrice: item.taxPrice ?? item.inboundPrice ?? item.outboundPrice,
|
||||
taxSubtotal: item.taxSubtotal ?? item.inboundAmount ?? item.outboundAmount,
|
||||
taxAmount: item.taxAmount,
|
||||
@@ -72,16 +73,26 @@ export function buildContractSnapshotFromPlan(data: Plan, rows: PlanFormProductR
|
||||
unreceivedAmount: 0,
|
||||
invoiceAmount: 0,
|
||||
uninvoiceAmount: 0,
|
||||
partyA: data.partyA || '',
|
||||
partyA: data.partyA || data.supplierName || '',
|
||||
partyAAddress: '',
|
||||
partyAContact: '',
|
||||
partyAMobile: '',
|
||||
partyALegalPerson: '',
|
||||
partyAAgent: '',
|
||||
partyAPhoneFax: '',
|
||||
partyABank: '',
|
||||
partyAAccount: '',
|
||||
supplierName: data.supplierName,
|
||||
settlementMethod: data.settlementMethod,
|
||||
partyB: data.partyB || '',
|
||||
partyBAddress: data.destinationAddress || '',
|
||||
partyB: data.partyB || data.customerName || '',
|
||||
partyBAddress: '',
|
||||
partyBContact: data.contactName || '',
|
||||
partyBMobile: data.contactPhone || '',
|
||||
partyBLegalPerson: '',
|
||||
partyBAgent: '',
|
||||
partyBPhoneFax: '',
|
||||
partyBBank: '',
|
||||
partyBAccount: '',
|
||||
paymentTerms: '',
|
||||
deliveryTerms: '',
|
||||
contractTerms: '',
|
||||
@@ -93,6 +104,16 @@ export function buildContractSnapshotFromPlan(data: Plan, rows: PlanFormProductR
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeContractSnapshot(raw: unknown): ContractVO | null {
|
||||
if (!raw || typeof raw !== 'object') return null
|
||||
const payload = raw as Record<string, unknown>
|
||||
const nested = payload.data
|
||||
if (nested && typeof nested === 'object') {
|
||||
return nested as ContractVO
|
||||
}
|
||||
return raw as ContractVO
|
||||
}
|
||||
|
||||
export function usePlPlanViewDetail() {
|
||||
const loading = ref(false)
|
||||
const plan = ref<Plan | null>(null)
|
||||
@@ -155,7 +176,7 @@ export function usePlPlanViewDetail() {
|
||||
if (data?.contractId) {
|
||||
try {
|
||||
const contractRes = await getContract(data.contractId)
|
||||
contractSnapshot.value = (contractRes.data ?? contractRes) as ContractVO
|
||||
contractSnapshot.value = normalizeContractSnapshot(contractRes.data ?? contractRes)
|
||||
} catch {
|
||||
contractSnapshot.value = buildContractSnapshotFromPlan(data, rows)
|
||||
}
|
||||
|
||||
@@ -55,24 +55,29 @@ export async function enrichPlanProductsHazardFromCrm<T extends HazardFlagProduc
|
||||
...new Set(
|
||||
products
|
||||
.filter(product => {
|
||||
if (!product.productId) return false
|
||||
const flags = resolveProductHazardFlags(product)
|
||||
return !flags.isToxic && !flags.isExplosive && product.productId
|
||||
const needsHazard = !flags.isToxic && !flags.isExplosive
|
||||
const needsTaxRate = product.taxRate == null
|
||||
return needsHazard || needsTaxRate
|
||||
})
|
||||
.map(product => product.productId)
|
||||
)
|
||||
]
|
||||
if (!needLookupIds.length) return products
|
||||
|
||||
const hazardMap = new Map<string, { isToxic: number; isExplosive: number }>()
|
||||
const hazardMap = new Map<string, { isToxic: number; isExplosive: number; taxRate?: number }>()
|
||||
await Promise.all(
|
||||
needLookupIds.map(async productId => {
|
||||
try {
|
||||
const res = await fetchProductDetail({ id: productId })
|
||||
const data = (res as { data?: Record<string, unknown> }).data ?? res
|
||||
const row = data as Record<string, unknown>
|
||||
const rawTaxRate = row.taxRate ?? row.tax_rate
|
||||
hazardMap.set(productId, {
|
||||
isToxic: Number(row.isToxic ?? row.is_toxic ?? 0),
|
||||
isExplosive: Number(row.isExplosive ?? row.is_explosive ?? 0)
|
||||
isExplosive: Number(row.isExplosive ?? row.is_explosive ?? 0),
|
||||
taxRate: rawTaxRate != null && rawTaxRate !== '' ? Number(rawTaxRate) : undefined
|
||||
})
|
||||
} catch {
|
||||
// 单条产品查询失败时跳过
|
||||
@@ -82,13 +87,13 @@ export async function enrichPlanProductsHazardFromCrm<T extends HazardFlagProduc
|
||||
|
||||
return products.map(product => {
|
||||
const flags = resolveProductHazardFlags(product)
|
||||
if (flags.isToxic || flags.isExplosive) return product
|
||||
const fromCrm = hazardMap.get(product.productId)
|
||||
if (!fromCrm) return product
|
||||
return {
|
||||
...product,
|
||||
isToxic: fromCrm.isToxic,
|
||||
isExplosive: fromCrm.isExplosive
|
||||
isToxic: flags.isToxic ? product.isToxic : fromCrm.isToxic,
|
||||
isExplosive: flags.isExplosive ? product.isExplosive : fromCrm.isExplosive,
|
||||
taxRate: product.taxRate ?? fromCrm.taxRate
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user