This commit is contained in:
zlwu committed 2026-06-23 23:30:57 +08:00
1 parent c90f72fd34
commit 6b6c80f182
100 files changed
+18631 -6278

No files matched your search

@@ -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
}