Files
shanxia2.0/web-admin/src/composables/usePlContractToPlan.ts
T
2026-06-23 23:30:57 +08:00

113 lines
3.7 KiB
TypeScript

import type { ContractProductForm, ContractVO } from '@/api/crm/contract/types'
export interface PlanFormProductRow {
id?: string
productId: string
productNo: string
productName: string
model?: string
categoryName?: string
unit: string
quantity: number
actualQty?: number
packageSpec?: string
deliveryMethod?: string
taxRate?: number
taxPrice?: number
taxSubtotal?: number
taxAmount?: number
remark?: string
isExplosive?: number
isToxic?: number
purchaseCertUrl?: string
transportCertUrl?: string
}
export function resolveBelongsCompany(supplierName?: string) {
if (supplierName?.includes('安徽云栋')) return 'yundong'
return 'shanxia'
}
export function mapContractProductToPlanRow(item: ContractProductForm, index: number): PlanFormProductRow {
const productId = String(item.productId || item.id || index)
return {
productId,
productNo: productId,
productName: item.productName || '',
model: item.model || item.productModel,
categoryName: item.categoryName,
unit: item.unit || '吨',
quantity: Number(item.quantity || 0),
actualQty: 0,
packageSpec: item.packageSpec,
deliveryMethod: item.deliveryMethod,
taxRate: item.taxRate != null ? Number(item.taxRate) : undefined,
taxPrice: item.price != null ? Number(item.price) : undefined,
taxSubtotal: item.subtotal != null ? Number(item.subtotal) : undefined,
taxAmount: item.taxAmount != null ? Number(item.taxAmount) : undefined,
remark: item.remark,
isExplosive: Number(item.isExplosive ?? 0),
isToxic: Number(item.isToxic ?? 0)
}
}
export function mapContractProducts(products?: ContractProductForm[]) {
return (products || []).map(mapContractProductToPlanRow)
}
export function applyContractToPlanForm(contract: ContractVO) {
// 供方/需方以合同甲乙方可章名为准;supplierName/customerName 仅作冗余,供地磅按 planType 取用
const supplierName = contract.partyA || contract.supplierName || ''
const customerName = contract.partyB || contract.customerName || ''
const destinationName = customerName
return {
contractId: String(contract.id),
contractNo: contract.contractNo,
belongsCompany: resolveBelongsCompany(contract.supplierName || contract.partyA),
supplierId: contract.supplierId != null ? String(contract.supplierId) : '',
supplierName,
destinationId: contract.customerId != null ? String(contract.customerId) : '',
destinationName,
customerId: contract.customerId != null ? String(contract.customerId) : '',
customerName,
contactName: contract.contactName || contract.partyBContact || '',
contactPhone: contract.contactMobile || contract.partyBMobile || '',
partyA: contract.partyA || '',
partyB: contract.partyB || '',
contractStartDate: contract.startDate || '',
contractEndDate: contract.endDate || '',
settlementMethod: contract.settlementMethod || '',
hasFreight: contract.settlementMethod?.includes('含运') ? 1 : 0,
products: mapContractProducts(contract.products)
}
}
export function getPlanTypeLabel(planType: string) {
const map: Record<string, string> = {
direct: '直销单',
inbound: '入库单',
outbound: '出库单'
}
return map[planType] || planType
}
export function getPlanTypeTagType(planType: string) {
const map: Record<string, string> = {
direct: 'primary',
inbound: 'success',
outbound: 'warning'
}
return map[planType] || 'info'
}
export function getDeliveryMethodLabel(method?: string) {
const map: Record<string, string> = {
self_pick: '山峡自提',
one_ticket: '一票制',
customer_pick: '客户自提'
}
if (!method) return '—'
return map[method] || method
}