提交
This commit is contained in:
1 parent
c90f72fd34
commit
6b6c80f182
100 files changed
+18631
-6278
No files matched your search
@@ -23,16 +23,6 @@ export interface PlanFormProductRow {
|
||||
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'
|
||||
@@ -66,21 +56,21 @@ export function mapContractProducts(products?: ContractProductForm[]) {
|
||||
}
|
||||
|
||||
export function applyContractToPlanForm(contract: ContractVO) {
|
||||
const supplierName = contract.supplierName || contract.partyA
|
||||
const destinationName = contract.customerName || contract.partyB
|
||||
const planType = determinePlPlanType(supplierName, destinationName)
|
||||
// 供方/需方以合同甲乙方可章名为准;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(supplierName),
|
||||
planType,
|
||||
belongsCompany: resolveBelongsCompany(contract.supplierName || contract.partyA),
|
||||
supplierId: contract.supplierId != null ? String(contract.supplierId) : '',
|
||||
supplierName: supplierName || '',
|
||||
supplierName,
|
||||
destinationId: contract.customerId != null ? String(contract.customerId) : '',
|
||||
destinationName: destinationName || '',
|
||||
destinationName,
|
||||
customerId: contract.customerId != null ? String(contract.customerId) : '',
|
||||
customerName: contract.customerName || '',
|
||||
customerName,
|
||||
contactName: contract.contactName || contract.partyBContact || '',
|
||||
contactPhone: contract.contactMobile || contract.partyBMobile || '',
|
||||
partyA: contract.partyA || '',
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
import type { Plan, PlanProduct, TransportArrangeResult, TransportInventoryLink } from '@/api/pl'
|
||||
import type {
|
||||
Plan,
|
||||
PlanProduct,
|
||||
TransportArrangeResult,
|
||||
TransportInventoryLink,
|
||||
TransportSiteLink
|
||||
} from '@/api/pl'
|
||||
import { planApi } from '@/api/pl'
|
||||
import DbPoundSlipQrcodeDialog from '@/components/business/db/DbPoundSlipQrcodeDialog.vue'
|
||||
import { useDictStore } from '@/store/modules/dict'
|
||||
import { formatDateTime } from '@/utils/format'
|
||||
import { pickBxData } from '@/utils/http/bx'
|
||||
import { formatPlanProductListText } from '@/utils/pl-display'
|
||||
import { buildSiteSummaryFromInventoryLinks } from '@/utils/db-site-summary'
|
||||
|
||||
export function usePlPlanArrangeActions() {
|
||||
const dictStore = useDictStore()
|
||||
@@ -12,6 +20,7 @@ export function usePlPlanArrangeActions() {
|
||||
const products = ref<PlanProduct[]>([])
|
||||
const driverUrl = ref('')
|
||||
const licensePlate = ref('')
|
||||
const siteRecords = ref<TransportSiteLink[]>([])
|
||||
const inventoryRecords = ref<TransportInventoryLink[]>([])
|
||||
const qrcodeVisible = ref(false)
|
||||
const selectedInventoryId = ref('')
|
||||
@@ -23,10 +32,21 @@ export function usePlPlanArrangeActions() {
|
||||
Boolean(
|
||||
plan.value?.transportStatus === 'arranged' &&
|
||||
plan.value?.followStatus !== 'cancelled' &&
|
||||
(driverUrl.value || inventoryRecords.value.length)
|
||||
(driverUrl.value || siteRecords.value.length || inventoryRecords.value.length)
|
||||
)
|
||||
)
|
||||
|
||||
const hasSiteInventoryRecords = computed(() => siteRecords.value.length > 0)
|
||||
|
||||
const hasSiteLinks = computed(() => siteRecords.value.some(item => Boolean(item.siteUrl?.trim())))
|
||||
|
||||
/** 勾选「生成地磅单」后才会关联 db_purchase_plan,磅单二维码仅针对这类记录 */
|
||||
const dibangInventoryRecords = computed(() =>
|
||||
inventoryRecords.value.filter(item => Boolean(item.dbPurchasePlanId?.trim()))
|
||||
)
|
||||
|
||||
const hasDibangInventoryRecords = computed(() => dibangInventoryRecords.value.length > 0)
|
||||
|
||||
function getUnitLabel(unit: string) {
|
||||
return dictStore.getLabel('crm_product_unit', unit) || unit
|
||||
}
|
||||
@@ -36,17 +56,23 @@ export function usePlPlanArrangeActions() {
|
||||
products.value = []
|
||||
driverUrl.value = ''
|
||||
licensePlate.value = ''
|
||||
siteRecords.value = []
|
||||
inventoryRecords.value = []
|
||||
qrcodeVisible.value = false
|
||||
selectedInventoryId.value = ''
|
||||
selectedInventoryUnit.value = ''
|
||||
}
|
||||
|
||||
function applyArrangeResult(result: TransportArrangeResult, contextPlan?: Partial<Plan>, contextProducts?: PlanProduct[]) {
|
||||
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 || ''
|
||||
siteRecords.value = result.siteRecords || []
|
||||
inventoryRecords.value = result.inventoryRecords || []
|
||||
}
|
||||
|
||||
@@ -63,28 +89,44 @@ export function usePlPlanArrangeActions() {
|
||||
}
|
||||
|
||||
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 || []
|
||||
const info = pickBxData<{
|
||||
driverUrl?: string
|
||||
driver_url?: string
|
||||
licensePlate?: string
|
||||
license_plate?: string
|
||||
siteRecords?: TransportSiteLink[]
|
||||
site_records?: TransportSiteLink[]
|
||||
inventoryRecords?: TransportInventoryLink[]
|
||||
inventory_records?: TransportInventoryLink[]
|
||||
}>(infoRes)
|
||||
driverUrl.value = info?.driverUrl || info?.driver_url || ''
|
||||
licensePlate.value = info?.licensePlate || info?.license_plate || data.licensePlate || ''
|
||||
siteRecords.value = info?.siteRecords || info?.site_records || []
|
||||
inventoryRecords.value = info?.inventoryRecords || info?.inventory_records || []
|
||||
}
|
||||
|
||||
function buildPlanSummaryText(options?: {
|
||||
startPoint?: string
|
||||
endPoint?: string
|
||||
pickupAddress?: string
|
||||
destinationAddress?: 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 || '—'}`)
|
||||
lines.push(
|
||||
`时间:${formatDateTime(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 || '—'
|
||||
`路线:${options?.pickupAddress || plan.value?.pickupAddress || options?.startPoint || '—'} → ${
|
||||
options?.destinationAddress ||
|
||||
plan.value?.destinationAddress ||
|
||||
plan.value?.destinationName ||
|
||||
options?.endPoint ||
|
||||
'—'
|
||||
}`
|
||||
)
|
||||
lines.push(`司机链接:${options?.driverUrl || driverUrl.value || '—'}`)
|
||||
@@ -98,9 +140,58 @@ export function usePlPlanArrangeActions() {
|
||||
ElMessage.success('已复制司机链接')
|
||||
}
|
||||
|
||||
function buildAllSiteLinksText(records?: TransportSiteLink[]) {
|
||||
const list = records || siteRecords.value
|
||||
return list
|
||||
.filter(item => item.siteUrl)
|
||||
.map(item => `${item.productName || '现场链接'}:${item.siteUrl}`)
|
||||
.join('\n')
|
||||
}
|
||||
|
||||
async function copySiteUrl(url?: string) {
|
||||
const target = (url || siteRecords.value.find(item => item.siteUrl)?.siteUrl || '').trim()
|
||||
if (!target) {
|
||||
ElMessage.warning('暂无现场链接')
|
||||
return
|
||||
}
|
||||
await navigator.clipboard.writeText(target)
|
||||
ElMessage.success('已复制现场链接')
|
||||
}
|
||||
|
||||
async function copyAllSiteUrls(records?: TransportSiteLink[]) {
|
||||
const text = buildAllSiteLinksText(records)
|
||||
if (!text) {
|
||||
ElMessage.warning('暂无现场链接')
|
||||
return
|
||||
}
|
||||
await navigator.clipboard.writeText(text)
|
||||
ElMessage.success('已复制全部现场链接')
|
||||
}
|
||||
|
||||
function buildSiteSummaryText(options?: { licensePlate?: string }) {
|
||||
return buildSiteSummaryFromInventoryLinks({
|
||||
planNo: plan.value?.planNo,
|
||||
licensePlate: options?.licensePlate || licensePlate.value || plan.value?.licensePlate,
|
||||
pickupTime: plan.value?.pickupTime,
|
||||
planDate: plan.value?.planDate,
|
||||
records: siteRecords.value
|
||||
})
|
||||
}
|
||||
|
||||
async function copySiteSummary(options?: { licensePlate?: string }) {
|
||||
if (!hasSiteLinks.value) {
|
||||
ElMessage.warning('暂无现场链接')
|
||||
return
|
||||
}
|
||||
await navigator.clipboard.writeText(buildSiteSummaryText(options))
|
||||
ElMessage.success('已复制现场简述')
|
||||
}
|
||||
|
||||
async function copyPlanSummary(options?: {
|
||||
startPoint?: string
|
||||
endPoint?: string
|
||||
pickupAddress?: string
|
||||
destinationAddress?: string
|
||||
licensePlate?: string
|
||||
driverUrl?: string
|
||||
}) {
|
||||
@@ -115,10 +206,14 @@ export function usePlPlanArrangeActions() {
|
||||
}
|
||||
|
||||
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])
|
||||
const records = dibangInventoryRecords.value
|
||||
if (!records.length) {
|
||||
ElMessage.warning('未勾选生成地磅单,暂无磅单二维码')
|
||||
return
|
||||
}
|
||||
if (records.length === 1) {
|
||||
selectedInventoryId.value = records[0].dbInventoryId
|
||||
selectedInventoryUnit.value = resolveInventoryUnitLabel(records[0])
|
||||
qrcodeVisible.value = true
|
||||
await nextTick()
|
||||
await qrcodeDialogRef.value?.copyQrcodeImage()
|
||||
@@ -127,18 +222,18 @@ export function usePlPlanArrangeActions() {
|
||||
|
||||
try {
|
||||
const { value } = await ElMessageBox.prompt('请选择要复制二维码的产品行', '复制磅单二维码', {
|
||||
inputPlaceholder: inventoryRecords.value.map((item, idx) => `${idx + 1}. ${item.productName}`).join('\n'),
|
||||
inputPlaceholder: records.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) {
|
||||
if (!Number.isInteger(index) || index < 0 || index >= records.length) {
|
||||
return '请输入有效序号'
|
||||
}
|
||||
return true
|
||||
}
|
||||
})
|
||||
const index = Number(value) - 1
|
||||
const record = inventoryRecords.value[index]
|
||||
const record = records[index]
|
||||
selectedInventoryId.value = record.dbInventoryId
|
||||
selectedInventoryUnit.value = resolveInventoryUnitLabel(record)
|
||||
qrcodeVisible.value = true
|
||||
@@ -154,17 +249,26 @@ export function usePlPlanArrangeActions() {
|
||||
products,
|
||||
driverUrl,
|
||||
licensePlate,
|
||||
siteRecords,
|
||||
inventoryRecords,
|
||||
qrcodeVisible,
|
||||
selectedInventoryId,
|
||||
selectedInventoryUnit,
|
||||
qrcodeDialogRef,
|
||||
showArrangeActions,
|
||||
hasSiteInventoryRecords,
|
||||
hasSiteLinks,
|
||||
dibangInventoryRecords,
|
||||
hasDibangInventoryRecords,
|
||||
resetArrangeActions,
|
||||
applyArrangeResult,
|
||||
loadArrangeActions,
|
||||
buildPlanSummaryText,
|
||||
buildSiteSummaryText,
|
||||
copyDriverUrl,
|
||||
copySiteUrl,
|
||||
copyAllSiteUrls,
|
||||
copySiteSummary,
|
||||
copyPlanSummary,
|
||||
copyPoundSlipQrcode
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@ import {
|
||||
type Plan,
|
||||
type PlanProduct,
|
||||
type Transport,
|
||||
type TransportInventoryLink
|
||||
type TransportInventoryLink,
|
||||
type TransportSiteLink
|
||||
} from '@/api/pl'
|
||||
import type { PlanFormProductRow } from '@/composables/usePlContractToPlan'
|
||||
import { loadVehicleViewBundle, type VehicleViewBundle } from '@/composables/usePlVehicleViewDetail'
|
||||
@@ -24,6 +25,10 @@ export interface PlPlanTransportDibangRow {
|
||||
weighing: InventoryWeighingRecord | null
|
||||
}
|
||||
|
||||
export interface PlPlanTransportSiteRow {
|
||||
link: TransportSiteLink
|
||||
}
|
||||
|
||||
export function mapPlanProductToFormRow(item: PlanProduct, index: number): PlanFormProductRow {
|
||||
return {
|
||||
productId: String(item.productId || index),
|
||||
@@ -122,6 +127,22 @@ export function usePlPlanViewDetail() {
|
||||
const vehicleBundle = ref<VehicleViewBundle | null>(null)
|
||||
const contractSnapshot = ref<ContractVO | null>(null)
|
||||
const dibangRows = ref<PlPlanTransportDibangRow[]>([])
|
||||
const siteRows = ref<PlPlanTransportSiteRow[]>([])
|
||||
|
||||
async function loadSiteRows(planId: string, data: Plan) {
|
||||
siteRows.value = []
|
||||
if (data.followStatus === 'cancelled' || data.transportStatus !== 'arranged') {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const infoRes = await planApi.getArrangeInfo(planId)
|
||||
const info = pickBxData<{ siteRecords?: TransportSiteLink[] }>(infoRes)
|
||||
const links = info?.siteRecords || []
|
||||
siteRows.value = links.map(link => ({ link }))
|
||||
} catch {
|
||||
siteRows.value = []
|
||||
}
|
||||
}
|
||||
|
||||
async function loadDibangRows(planId: string, data: Plan) {
|
||||
dibangRows.value = []
|
||||
@@ -165,6 +186,7 @@ export function usePlPlanViewDetail() {
|
||||
vehicleBundle.value = null
|
||||
contractSnapshot.value = null
|
||||
dibangRows.value = []
|
||||
siteRows.value = []
|
||||
try {
|
||||
const res = await planApi.get(planId)
|
||||
const data = pickBxData<Plan>(res)
|
||||
@@ -216,7 +238,7 @@ export function usePlPlanViewDetail() {
|
||||
}
|
||||
|
||||
if (data) {
|
||||
await loadDibangRows(planId, data)
|
||||
await Promise.all([loadSiteRows(planId, data), loadDibangRows(planId, data)])
|
||||
}
|
||||
} finally {
|
||||
loading.value = false
|
||||
@@ -230,6 +252,7 @@ export function usePlPlanViewDetail() {
|
||||
vehicleBundle.value = null
|
||||
contractSnapshot.value = null
|
||||
dibangRows.value = []
|
||||
siteRows.value = []
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -240,6 +263,7 @@ export function usePlPlanViewDetail() {
|
||||
vehicleBundle,
|
||||
contractSnapshot,
|
||||
dibangRows,
|
||||
siteRows,
|
||||
loadDetail,
|
||||
resetDetail
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user