提交
This commit is contained in:
1 parent
c3be9d1dce
commit
299609706c
328 files changed
+144899
-13873
No files matched your search
@@ -0,0 +1,122 @@
|
||||
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 determinePlPlanType(supplierName?: string, destinationName?: string) {
|
||||
if (destinationName && (destinationName.includes('安庆山峡') || destinationName.includes('安徽云栋'))) {
|
||||
return 'inbound'
|
||||
}
|
||||
if (supplierName && (supplierName.includes('安庆山峡') || supplierName.includes('安徽云栋'))) {
|
||||
return 'outbound'
|
||||
}
|
||||
return 'direct'
|
||||
}
|
||||
|
||||
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: Number(item.quantity || 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) {
|
||||
const supplierName = contract.supplierName || contract.partyA
|
||||
const destinationName = contract.customerName || contract.partyB
|
||||
const planType = determinePlPlanType(supplierName, destinationName)
|
||||
|
||||
return {
|
||||
contractId: String(contract.id),
|
||||
contractNo: contract.contractNo,
|
||||
belongsCompany: resolveBelongsCompany(supplierName),
|
||||
planType,
|
||||
supplierId: contract.supplierId != null ? String(contract.supplierId) : '',
|
||||
supplierName: supplierName || '',
|
||||
destinationId: contract.customerId != null ? String(contract.customerId) : '',
|
||||
destinationName: destinationName || '',
|
||||
customerId: contract.customerId != null ? String(contract.customerId) : '',
|
||||
customerName: contract.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
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
import { computed, ref, watch, type Ref } from 'vue'
|
||||
|
||||
export interface FreightCalcProductRow {
|
||||
quantity?: number | null
|
||||
actualQty?: number | null
|
||||
unit?: string | null
|
||||
}
|
||||
|
||||
export function sumProductActualQuantities(products: FreightCalcProductRow[]) {
|
||||
return products.reduce((sum, row) => {
|
||||
const actual = row.actualQty
|
||||
if (actual != null && !Number.isNaN(Number(actual))) {
|
||||
return sum + Number(actual)
|
||||
}
|
||||
return sum + Number(row.quantity || 0)
|
||||
}, 0)
|
||||
}
|
||||
|
||||
/** @deprecated 使用 sumProductActualQuantities */
|
||||
export function sumProductQuantities(products: FreightCalcProductRow[]) {
|
||||
return sumProductActualQuantities(products)
|
||||
}
|
||||
|
||||
export function resolveFreightUnitLabel(products: FreightCalcProductRow[]) {
|
||||
const units = products.map(row => row.unit).filter(Boolean) as string[]
|
||||
if (!units.length) return '吨'
|
||||
const first = units[0]
|
||||
return first
|
||||
}
|
||||
|
||||
export function usePlFreightCalc(options: {
|
||||
products: Ref<FreightCalcProductRow[]>
|
||||
hasFreight: Ref<number>
|
||||
freightType: Ref<string>
|
||||
}) {
|
||||
const transportQty = ref<number | null>(null)
|
||||
const transportQtyTouched = ref(false)
|
||||
const freightAmount = ref<number | null>(null)
|
||||
const freightAmountTouched = ref(false)
|
||||
const freightPrice = ref<number | null>(null)
|
||||
|
||||
const defaultTransportQty = computed(() => sumProductActualQuantities(options.products.value))
|
||||
|
||||
watch(
|
||||
() => options.products.value,
|
||||
() => {
|
||||
if (!transportQtyTouched.value) {
|
||||
transportQty.value = defaultTransportQty.value || null
|
||||
}
|
||||
},
|
||||
{ deep: true, immediate: true }
|
||||
)
|
||||
|
||||
const calculatedFreight = computed(() => {
|
||||
if (!options.hasFreight.value) return 0
|
||||
if (options.freightType.value === 'by_trip') {
|
||||
return Number(freightAmount.value || 0)
|
||||
}
|
||||
const qty = Number(transportQty.value || 0)
|
||||
const price = Number(freightPrice.value || 0)
|
||||
return qty * price
|
||||
})
|
||||
|
||||
watch(calculatedFreight, val => {
|
||||
if (options.freightType.value === 'by_weight' && !freightAmountTouched.value) {
|
||||
freightAmount.value = val > 0 ? val : null
|
||||
}
|
||||
})
|
||||
|
||||
watch([transportQty, freightPrice], () => {
|
||||
if (options.freightType.value === 'by_weight' && options.hasFreight.value) {
|
||||
freightAmountTouched.value = false
|
||||
}
|
||||
})
|
||||
|
||||
watch(
|
||||
() => options.freightType.value,
|
||||
type => {
|
||||
freightAmountTouched.value = false
|
||||
if (type === 'by_trip') {
|
||||
freightPrice.value = null
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
function resetFreightCalc() {
|
||||
transportQty.value = null
|
||||
transportQtyTouched.value = false
|
||||
freightAmount.value = null
|
||||
freightAmountTouched.value = false
|
||||
freightPrice.value = null
|
||||
}
|
||||
|
||||
function markTransportQtyTouched() {
|
||||
transportQtyTouched.value = true
|
||||
}
|
||||
|
||||
function markFreightAmountTouched() {
|
||||
freightAmountTouched.value = true
|
||||
}
|
||||
|
||||
return {
|
||||
transportQty,
|
||||
transportQtyTouched,
|
||||
freightPrice,
|
||||
freightAmount,
|
||||
freightAmountTouched,
|
||||
defaultTransportQty,
|
||||
calculatedFreight,
|
||||
resetFreightCalc,
|
||||
markTransportQtyTouched,
|
||||
markFreightAmountTouched
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
import type { Plan, PlanProduct, TransportArrangeResult, TransportInventoryLink } from '@/api/pl'
|
||||
import { planApi } from '@/api/pl'
|
||||
import DbPoundSlipQrcodeDialog from '@/components/business/db/DbPoundSlipQrcodeDialog.vue'
|
||||
import { useDictStore } from '@/store/modules/dict'
|
||||
import { pickBxData } from '@/utils/http/bx'
|
||||
import { formatPlanProductListText } from '@/utils/pl-display'
|
||||
|
||||
export function usePlPlanArrangeActions() {
|
||||
const dictStore = useDictStore()
|
||||
|
||||
const plan = ref<Partial<Plan> | null>(null)
|
||||
const products = ref<PlanProduct[]>([])
|
||||
const driverUrl = ref('')
|
||||
const licensePlate = ref('')
|
||||
const inventoryRecords = ref<TransportInventoryLink[]>([])
|
||||
const qrcodeVisible = ref(false)
|
||||
const selectedInventoryId = ref('')
|
||||
const selectedInventoryUnit = ref('')
|
||||
const qrcodeDialogRef = ref<InstanceType<typeof DbPoundSlipQrcodeDialog> | null>(null)
|
||||
|
||||
const showArrangeActions = computed(
|
||||
() =>
|
||||
Boolean(
|
||||
plan.value?.transportStatus === 'arranged' &&
|
||||
plan.value?.followStatus !== 'cancelled' &&
|
||||
(driverUrl.value || inventoryRecords.value.length)
|
||||
)
|
||||
)
|
||||
|
||||
function getUnitLabel(unit: string) {
|
||||
return dictStore.getLabel('crm_product_unit', unit) || unit
|
||||
}
|
||||
|
||||
function resetArrangeActions() {
|
||||
plan.value = null
|
||||
products.value = []
|
||||
driverUrl.value = ''
|
||||
licensePlate.value = ''
|
||||
inventoryRecords.value = []
|
||||
qrcodeVisible.value = false
|
||||
selectedInventoryId.value = ''
|
||||
selectedInventoryUnit.value = ''
|
||||
}
|
||||
|
||||
function applyArrangeResult(result: TransportArrangeResult, contextPlan?: Partial<Plan>, contextProducts?: PlanProduct[]) {
|
||||
if (contextPlan) plan.value = contextPlan
|
||||
if (contextProducts) products.value = contextProducts
|
||||
driverUrl.value = result.driverUrl || ''
|
||||
licensePlate.value = result.licensePlate || ''
|
||||
inventoryRecords.value = result.inventoryRecords || []
|
||||
}
|
||||
|
||||
async function loadArrangeActions(planId: string) {
|
||||
resetArrangeActions()
|
||||
const planRes = await planApi.get(planId)
|
||||
const data = pickBxData<Plan>(planRes)
|
||||
if (!data) return
|
||||
plan.value = data
|
||||
products.value = Array.isArray(data.products) ? data.products : []
|
||||
|
||||
if (data.transportStatus !== 'arranged' || data.followStatus === 'cancelled') {
|
||||
return
|
||||
}
|
||||
|
||||
const infoRes = await planApi.getArrangeInfo(planId)
|
||||
const info = pickBxData<{ driverUrl?: string; licensePlate?: string; inventoryRecords?: TransportInventoryLink[] }>(
|
||||
infoRes
|
||||
)
|
||||
driverUrl.value = info?.driverUrl || ''
|
||||
licensePlate.value = info?.licensePlate || data.licensePlate || ''
|
||||
inventoryRecords.value = info?.inventoryRecords || []
|
||||
}
|
||||
|
||||
function buildPlanSummaryText(options?: {
|
||||
startPoint?: string
|
||||
endPoint?: string
|
||||
licensePlate?: string
|
||||
driverUrl?: string
|
||||
}) {
|
||||
const lines = ['【运输安排】', `计划号:${plan.value?.planNo || '—'}`]
|
||||
lines.push(`车牌:${options?.licensePlate || licensePlate.value || plan.value?.licensePlate || '—'}`)
|
||||
lines.push(`时间:${plan.value?.pickupTime || plan.value?.planDate || '—'}`)
|
||||
const productText = products.value.map(p => formatPlanProductListText(p, getUnitLabel)).join(';')
|
||||
lines.push(`产品:${productText || '—'}`)
|
||||
lines.push(
|
||||
`路线:${plan.value?.pickupAddress || options?.startPoint || '—'} → ${
|
||||
plan.value?.destinationAddress || plan.value?.destinationName || options?.endPoint || '—'
|
||||
}`
|
||||
)
|
||||
lines.push(`司机链接:${options?.driverUrl || driverUrl.value || '—'}`)
|
||||
return lines.join('\n')
|
||||
}
|
||||
|
||||
async function copyDriverUrl(url?: string) {
|
||||
const target = url || driverUrl.value
|
||||
if (!target) return
|
||||
await navigator.clipboard.writeText(target)
|
||||
ElMessage.success('已复制司机链接')
|
||||
}
|
||||
|
||||
async function copyPlanSummary(options?: {
|
||||
startPoint?: string
|
||||
endPoint?: string
|
||||
licensePlate?: string
|
||||
driverUrl?: string
|
||||
}) {
|
||||
await navigator.clipboard.writeText(buildPlanSummaryText(options))
|
||||
ElMessage.success('已复制计划简述')
|
||||
}
|
||||
|
||||
function resolveInventoryUnitLabel(record: TransportInventoryLink) {
|
||||
const product = products.value.find(item => item.id === record.planProductId)
|
||||
const unitRaw = product?.unit || ''
|
||||
return unitRaw ? getUnitLabel(unitRaw) : '吨'
|
||||
}
|
||||
|
||||
async function copyPoundSlipQrcode() {
|
||||
if (!inventoryRecords.value.length) return
|
||||
if (inventoryRecords.value.length === 1) {
|
||||
selectedInventoryId.value = inventoryRecords.value[0].dbInventoryId
|
||||
selectedInventoryUnit.value = resolveInventoryUnitLabel(inventoryRecords.value[0])
|
||||
qrcodeVisible.value = true
|
||||
await nextTick()
|
||||
await qrcodeDialogRef.value?.copyQrcodeImage()
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const { value } = await ElMessageBox.prompt('请选择要复制二维码的产品行', '复制磅单二维码', {
|
||||
inputPlaceholder: inventoryRecords.value.map((item, idx) => `${idx + 1}. ${item.productName}`).join('\n'),
|
||||
confirmButtonText: '确定',
|
||||
inputValidator: val => {
|
||||
const index = Number(val) - 1
|
||||
if (!Number.isInteger(index) || index < 0 || index >= inventoryRecords.value.length) {
|
||||
return '请输入有效序号'
|
||||
}
|
||||
return true
|
||||
}
|
||||
})
|
||||
const index = Number(value) - 1
|
||||
const record = inventoryRecords.value[index]
|
||||
selectedInventoryId.value = record.dbInventoryId
|
||||
selectedInventoryUnit.value = resolveInventoryUnitLabel(record)
|
||||
qrcodeVisible.value = true
|
||||
await nextTick()
|
||||
await qrcodeDialogRef.value?.copyQrcodeImage()
|
||||
} catch {
|
||||
// 用户取消
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
plan,
|
||||
products,
|
||||
driverUrl,
|
||||
licensePlate,
|
||||
inventoryRecords,
|
||||
qrcodeVisible,
|
||||
selectedInventoryId,
|
||||
selectedInventoryUnit,
|
||||
qrcodeDialogRef,
|
||||
showArrangeActions,
|
||||
resetArrangeActions,
|
||||
applyArrangeResult,
|
||||
loadArrangeActions,
|
||||
buildPlanSummaryText,
|
||||
copyDriverUrl,
|
||||
copyPlanSummary,
|
||||
copyPoundSlipQrcode
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
import { getContract } from '@/api/crm/contract'
|
||||
import type { ContractVO } from '@/api/crm/contract/types'
|
||||
import {
|
||||
inventoryApi,
|
||||
type InventoryRecord,
|
||||
type InventoryWeighingRecord
|
||||
} from '@/api/db/inventory'
|
||||
import {
|
||||
planApi,
|
||||
transportApi,
|
||||
type Plan,
|
||||
type PlanProduct,
|
||||
type Transport,
|
||||
type TransportInventoryLink
|
||||
} from '@/api/pl'
|
||||
import type { PlanFormProductRow } from '@/composables/usePlContractToPlan'
|
||||
import { loadVehicleViewBundle, type VehicleViewBundle } from '@/composables/usePlVehicleViewDetail'
|
||||
import { enrichPlanProductsHazardFromCrm } from '@/composables/usePlToxicProductCertCheck'
|
||||
import { pickBxData } from '@/utils/http/bx'
|
||||
|
||||
export interface PlPlanTransportDibangRow {
|
||||
link: TransportInventoryLink
|
||||
inventory: InventoryRecord | null
|
||||
weighing: InventoryWeighingRecord | null
|
||||
}
|
||||
|
||||
export function mapPlanProductToFormRow(item: PlanProduct, index: number): PlanFormProductRow {
|
||||
return {
|
||||
productId: String(item.productId || index),
|
||||
productNo: item.productNo || String(item.productId || index),
|
||||
productName: item.productName || '',
|
||||
model: item.model,
|
||||
categoryName: item.categoryName,
|
||||
unit: item.unit || '吨',
|
||||
quantity: Number(item.quantity || item.inboundEstimateQty || item.outboundEstimateQty || 0),
|
||||
actualQty: Number(
|
||||
item.actualQty ?? item.quantity ?? item.inboundEstimateQty ?? item.outboundEstimateQty ?? 0
|
||||
),
|
||||
packageSpec: item.packageSpec,
|
||||
deliveryMethod: item.deliveryMethod,
|
||||
taxPrice: item.taxPrice ?? item.inboundPrice ?? item.outboundPrice,
|
||||
taxSubtotal: item.taxSubtotal ?? item.inboundAmount ?? item.outboundAmount,
|
||||
taxAmount: item.taxAmount,
|
||||
remark: item.remark,
|
||||
isExplosive: Number(item.isExplosive ?? 0),
|
||||
isToxic: Number(item.isToxic ?? 0)
|
||||
}
|
||||
}
|
||||
|
||||
export function buildContractSnapshotFromPlan(data: Plan, rows: PlanFormProductRow[]): ContractVO {
|
||||
return {
|
||||
id: data.contractId || '',
|
||||
contractNo: data.contractNo || '',
|
||||
contractName: data.contractNo || '',
|
||||
customerId: data.customerId || '',
|
||||
customerName: data.customerName || '',
|
||||
contactName: data.contactName || '',
|
||||
contactMobile: data.contactPhone || '',
|
||||
contractType: '',
|
||||
amount: data.totalAmount || 0,
|
||||
signDate: '',
|
||||
startDate: data.contractStartDate || '',
|
||||
endDate: data.contractEndDate || '',
|
||||
contractPeriod: 0,
|
||||
status: '',
|
||||
approvalStatus: '',
|
||||
contractFile: '',
|
||||
attachmentFiles: '',
|
||||
ownerUserId: '',
|
||||
ownerUserName: '',
|
||||
receivedAmount: 0,
|
||||
unreceivedAmount: 0,
|
||||
invoiceAmount: 0,
|
||||
uninvoiceAmount: 0,
|
||||
partyA: data.partyA || '',
|
||||
partyAAddress: '',
|
||||
partyAContact: '',
|
||||
partyAMobile: '',
|
||||
supplierName: data.supplierName,
|
||||
settlementMethod: data.settlementMethod,
|
||||
partyB: data.partyB || '',
|
||||
partyBAddress: data.destinationAddress || '',
|
||||
partyBContact: data.contactName || '',
|
||||
partyBMobile: data.contactPhone || '',
|
||||
paymentTerms: '',
|
||||
deliveryTerms: '',
|
||||
contractTerms: '',
|
||||
invalidReason: '',
|
||||
invalidTime: '',
|
||||
createTime: '',
|
||||
remark: data.remark || '',
|
||||
products: rows as unknown as ContractVO['products']
|
||||
}
|
||||
}
|
||||
|
||||
export function usePlPlanViewDetail() {
|
||||
const loading = ref(false)
|
||||
const plan = ref<Plan | null>(null)
|
||||
const products = ref<PlanProduct[]>([])
|
||||
const transport = ref<Transport | null>(null)
|
||||
const vehicleBundle = ref<VehicleViewBundle | null>(null)
|
||||
const contractSnapshot = ref<ContractVO | null>(null)
|
||||
const dibangRows = ref<PlPlanTransportDibangRow[]>([])
|
||||
|
||||
async function loadDibangRows(planId: string, data: Plan) {
|
||||
dibangRows.value = []
|
||||
if (data.followStatus === 'cancelled' || data.transportStatus !== 'arranged') {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const infoRes = await planApi.getArrangeInfo(planId)
|
||||
const info = pickBxData<{ inventoryRecords?: TransportInventoryLink[] }>(infoRes)
|
||||
const links = info?.inventoryRecords || []
|
||||
if (!links.length) return
|
||||
|
||||
dibangRows.value = await Promise.all(
|
||||
links.map(async (link) => {
|
||||
let inventory: InventoryRecord | null = null
|
||||
let weighing: InventoryWeighingRecord | null = null
|
||||
try {
|
||||
inventory = await inventoryApi.get(link.dbInventoryId)
|
||||
} catch {
|
||||
inventory = null
|
||||
}
|
||||
try {
|
||||
const related = await inventoryApi.getRelated(link.dbInventoryId)
|
||||
weighing = related?.weighing ?? null
|
||||
} catch {
|
||||
weighing = null
|
||||
}
|
||||
return { link, inventory, weighing }
|
||||
})
|
||||
)
|
||||
} catch {
|
||||
dibangRows.value = []
|
||||
}
|
||||
}
|
||||
|
||||
async function loadDetail(planId: string) {
|
||||
loading.value = true
|
||||
plan.value = null
|
||||
products.value = []
|
||||
transport.value = null
|
||||
vehicleBundle.value = null
|
||||
contractSnapshot.value = null
|
||||
dibangRows.value = []
|
||||
try {
|
||||
const res = await planApi.get(planId)
|
||||
const data = pickBxData<Plan>(res)
|
||||
plan.value = data || null
|
||||
|
||||
const rows = (data?.products || []).map(mapPlanProductToFormRow)
|
||||
products.value = await enrichPlanProductsHazardFromCrm(data?.products || [])
|
||||
|
||||
if (data?.contractId) {
|
||||
try {
|
||||
const contractRes = await getContract(data.contractId)
|
||||
contractSnapshot.value = (contractRes.data ?? contractRes) as ContractVO
|
||||
} catch {
|
||||
contractSnapshot.value = buildContractSnapshotFromPlan(data, rows)
|
||||
}
|
||||
} else if (data) {
|
||||
contractSnapshot.value = buildContractSnapshotFromPlan(data, rows)
|
||||
}
|
||||
|
||||
const detailTasks: Promise<void>[] = []
|
||||
|
||||
if (data?.transportId) {
|
||||
detailTasks.push(
|
||||
transportApi
|
||||
.get(data.transportId)
|
||||
.then((transportRes) => {
|
||||
transport.value = pickBxData<Transport>(transportRes)
|
||||
})
|
||||
.catch(() => {
|
||||
transport.value = null
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
if (data?.vehicleId) {
|
||||
detailTasks.push(
|
||||
loadVehicleViewBundle(data.vehicleId)
|
||||
.then((bundle) => {
|
||||
vehicleBundle.value = bundle
|
||||
})
|
||||
.catch(() => {
|
||||
vehicleBundle.value = null
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
if (detailTasks.length) {
|
||||
await Promise.all(detailTasks)
|
||||
}
|
||||
|
||||
if (data) {
|
||||
await loadDibangRows(planId, data)
|
||||
}
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function resetDetail() {
|
||||
plan.value = null
|
||||
products.value = []
|
||||
transport.value = null
|
||||
vehicleBundle.value = null
|
||||
contractSnapshot.value = null
|
||||
dibangRows.value = []
|
||||
}
|
||||
|
||||
return {
|
||||
loading,
|
||||
plan,
|
||||
products,
|
||||
transport,
|
||||
vehicleBundle,
|
||||
contractSnapshot,
|
||||
dibangRows,
|
||||
loadDetail,
|
||||
resetDetail
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
import { fetchProductDetail } from '@/api/crm/product'
|
||||
import type { PlanProduct } from '@/api/pl'
|
||||
|
||||
export type HazardFlagProduct = {
|
||||
productId?: string
|
||||
productName?: string
|
||||
isToxic?: number
|
||||
isExplosive?: number
|
||||
is_toxic?: number
|
||||
is_explosive?: number
|
||||
}
|
||||
|
||||
function isTruthyHazardFlag(value: unknown) {
|
||||
return value === 1 || value === true || value === '1'
|
||||
}
|
||||
|
||||
export function resolveProductHazardFlags(product: HazardFlagProduct) {
|
||||
const isToxic =
|
||||
isTruthyHazardFlag(product.isToxic) || isTruthyHazardFlag(product.is_toxic)
|
||||
const isExplosive =
|
||||
isTruthyHazardFlag(product.isExplosive) || isTruthyHazardFlag(product.is_explosive)
|
||||
return { isToxic, isExplosive }
|
||||
}
|
||||
|
||||
export function isHazardProduct(product: Pick<PlanProduct, 'isToxic' | 'isExplosive'>) {
|
||||
const flags = resolveProductHazardFlags(product)
|
||||
return flags.isToxic || flags.isExplosive
|
||||
}
|
||||
|
||||
export function getHazardProductLabel(product: Pick<PlanProduct, 'isToxic' | 'isExplosive'>) {
|
||||
const flags = resolveProductHazardFlags(product)
|
||||
if (flags.isExplosive) return '易制爆'
|
||||
if (flags.isToxic) return '易制毒'
|
||||
return ''
|
||||
}
|
||||
|
||||
/** 产品名称后追加易制毒/易制爆标识:毒、爆,或「毒 爆」 */
|
||||
export function formatPlProductNameWithHazardMarks(product: HazardFlagProduct) {
|
||||
const name = product.productName || ''
|
||||
const { isToxic, isExplosive } = resolveProductHazardFlags(product)
|
||||
const marks: string[] = []
|
||||
if (isToxic) marks.push('毒')
|
||||
if (isExplosive) marks.push('爆')
|
||||
if (!marks.length) return name
|
||||
return `${name}${marks.join(' ')}`
|
||||
}
|
||||
|
||||
/** 从 CRM 产品主数据补全易制毒/易制爆标识(合同明细通常不带该字段) */
|
||||
export async function enrichPlanProductsHazardFromCrm<T extends HazardFlagProduct & { productId: string }>(
|
||||
products: T[]
|
||||
): Promise<T[]> {
|
||||
if (!products.length) return products
|
||||
|
||||
const needLookupIds = [
|
||||
...new Set(
|
||||
products
|
||||
.filter(product => {
|
||||
const flags = resolveProductHazardFlags(product)
|
||||
return !flags.isToxic && !flags.isExplosive && product.productId
|
||||
})
|
||||
.map(product => product.productId)
|
||||
)
|
||||
]
|
||||
if (!needLookupIds.length) return products
|
||||
|
||||
const hazardMap = new Map<string, { isToxic: number; isExplosive: 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>
|
||||
hazardMap.set(productId, {
|
||||
isToxic: Number(row.isToxic ?? row.is_toxic ?? 0),
|
||||
isExplosive: Number(row.isExplosive ?? row.is_explosive ?? 0)
|
||||
})
|
||||
} catch {
|
||||
// 单条产品查询失败时跳过
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function findMissingHazardCerts(products: PlanProduct[]) {
|
||||
return products.filter(
|
||||
p => isHazardProduct(p) && (!p.purchaseCertUrl?.trim() || !p.transportCertUrl?.trim())
|
||||
)
|
||||
}
|
||||
|
||||
export function buildMissingHazardCertMessage(products: PlanProduct[]) {
|
||||
const missing = findMissingHazardCerts(products)
|
||||
if (!missing.length) return ''
|
||||
const names = missing.map(p => `「${p.productName}」`).join('、')
|
||||
return `以下产品须上传购买证和运输证:${names}`
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { personnelApi, vehicleApi, type VehicleDetail, type VehiclePersonnelRow } from '@/api/pl'
|
||||
import type { VehiclePersonnelViewRow } from '@/components/business/pl-vehicle-personnel-view-list/index.vue'
|
||||
|
||||
export interface VehicleViewBundle {
|
||||
detail: VehicleDetail
|
||||
personnelList: VehiclePersonnelViewRow[]
|
||||
}
|
||||
|
||||
export async function loadPersonnelWithCerts(
|
||||
personnelList: VehiclePersonnelRow[]
|
||||
): Promise<VehiclePersonnelViewRow[]> {
|
||||
return Promise.all(
|
||||
personnelList.map(async person => {
|
||||
if (!person.personnelId) {
|
||||
return { ...person, certList: [] } as VehiclePersonnelViewRow
|
||||
}
|
||||
try {
|
||||
const res = await personnelApi.get(person.personnelId)
|
||||
const detail = ((res.data ?? res) || {}) as { certList?: VehiclePersonnelViewRow['certList'] }
|
||||
return {
|
||||
...person,
|
||||
certList: detail.certList || []
|
||||
} as VehiclePersonnelViewRow
|
||||
} catch {
|
||||
return { ...person, certList: [] } as VehiclePersonnelViewRow
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
export async function loadVehicleViewBundle(vehicleId: string): Promise<VehicleViewBundle> {
|
||||
const res = await vehicleApi.get(vehicleId)
|
||||
const detail = ((res.data ?? res) || {}) as VehicleDetail
|
||||
const personnelList = await loadPersonnelWithCerts(detail.personnelList || [])
|
||||
return { detail, personnelList }
|
||||
}
|
||||
|
||||
export async function loadVehicleViewBundles(vehicleIds: string[]): Promise<VehicleViewBundle[]> {
|
||||
if (!vehicleIds.length) return []
|
||||
return Promise.all(vehicleIds.map(id => loadVehicleViewBundle(id)))
|
||||
}
|
||||
Reference in new issue
Block a user