Files
shanxia2.0/web-admin/src/components/business/pl-plan-stop-feedback-panel/index.vue
T
2026-08-30 18:33:13 +08:00

757 lines
24 KiB
Vue

<template>
<div v-if="visible" class="pl-plan-stop-feedback-panel">
<h4 v-if="panelTitle" class="pl-plan-stop-feedback-panel__title">{{ panelTitle }}</h4>
<div class="pl-stop-feedback-cards" :class="cardsLayoutClass">
<section class="pl-stop-feedback-card">
<div class="pl-stop-feedback-ticket">
<div class="pl-stop-feedback-ticket__band pl-stop-feedback-ticket__band--driver">
<span class="pl-stop-feedback-ticket__who">司机回传</span>
<span v-if="driverFeedback?.feedbackTime" class="pl-stop-feedback-ticket__when">{{
formatFeedbackTime(driverFeedback.feedbackTime)
}}</span>
</div>
<p
v-if="!hasDriverFeedback && !editableAttachments"
class="pl-plan-form-empty-hint pl-stop-feedback-ticket__empty"
>
暂无司机回传
</p>
<template v-else>
<div v-if="driverFeedback?.products?.length" class="pl-stop-feedback-ticket__products">
<div
v-for="product in driverFeedback.products"
:key="product.stopProductId"
class="pl-stop-feedback-ticket__product-row"
>
<span class="pl-stop-feedback-ticket__text">{{ product.productName || '产品' }}</span>
<span class="pl-stop-feedback-ticket__text pl-stop-feedback-ticket__text--qty">
{{ formatDriverProductQty(product) }}
</span>
</div>
</div>
<div v-if="driverRemarkDisplay" class="pl-stop-feedback-ticket__line pl-stop-feedback-ticket__line--full">
<span class="pl-stop-feedback-ticket__lab">备注</span>
<span class="pl-stop-feedback-ticket__text">{{ driverRemarkDisplay }}</span>
</div>
<div class="pl-stop-feedback-ticket__foot">
<span class="pl-stop-feedback-ticket__lab">附件</span>
<AttachmentUploadField
v-if="editableAttachments || driverAttachmentCsv"
ref="driverAttachRef"
class="pl-stop-feedback-ticket__attach"
:class="{ 'pl-stop-feedback-ticket__attach--editable': editableAttachments }"
:model-value="driverAttachmentModel"
:disabled="!editableAttachments"
compact
folder="pl/transport/feedback"
accept="image/*,video/*,.pdf"
:limit="15"
@update:model-value="handleDriverAttachmentChange"
/>
<span v-else class="pl-plan-form-empty-hint">—</span>
</div>
</template>
</div>
</section>
<section v-if="showSiteCard" class="pl-stop-feedback-card">
<div class="pl-stop-feedback-ticket">
<div class="pl-stop-feedback-ticket__band pl-stop-feedback-ticket__band--site">
<span class="pl-stop-feedback-ticket__who">现场回传</span>
<span v-if="siteFeedback?.feedbackTime" class="pl-stop-feedback-ticket__when">{{
formatFeedbackTime(siteFeedback.feedbackTime)
}}</span>
</div>
<p
v-if="!hasSiteFeedback && !editableAttachments"
class="pl-plan-form-empty-hint pl-stop-feedback-ticket__empty"
>
暂无现场回传
</p>
<template v-else>
<div v-if="siteFeedback?.products?.length" class="pl-stop-feedback-ticket__products">
<div
v-for="product in siteFeedback.products"
:key="product.stopProductId"
class="pl-stop-feedback-ticket__product-row"
>
<span class="pl-stop-feedback-ticket__text">{{ product.productName || '产品' }}</span>
<span class="pl-stop-feedback-ticket__text pl-stop-feedback-ticket__text--qty">
<span class="pl-stop-feedback-ticket__val pl-stop-feedback-ticket__val--highlight">{{
formatSiteProductQty(product).qty
}}</span>
<span class="pl-stop-feedback-ticket__unit">{{ formatSiteProductQty(product).unit }}</span>
</span>
</div>
</div>
<div class="pl-stop-feedback-ticket__lines">
<div
v-if="
(siteFeedback?.quantity != null && !siteFeedback?.products?.length) ||
siteFeedback?.businessType
"
class="pl-stop-feedback-ticket__row"
>
<div
v-if="siteFeedback?.quantity != null && !siteFeedback?.products?.length"
class="pl-stop-feedback-ticket__line"
>
<span class="pl-stop-feedback-ticket__lab">数量</span>
<span class="pl-stop-feedback-ticket__text pl-stop-feedback-ticket__text--qty">
<span class="pl-stop-feedback-ticket__val pl-stop-feedback-ticket__val--highlight">{{
siteFeedback.quantity
}}</span>
<span class="pl-stop-feedback-ticket__unit">吨</span>
</span>
</div>
<div v-if="siteFeedback?.businessType" class="pl-stop-feedback-ticket__line">
<span class="pl-stop-feedback-ticket__lab">业务类型</span>
<span class="pl-stop-feedback-ticket__text">{{
formatSiteBusinessType(siteFeedback.businessType)
}}</span>
</div>
</div>
<div v-if="siteFeedback?.remark" class="pl-stop-feedback-ticket__line pl-stop-feedback-ticket__line--full">
<span class="pl-stop-feedback-ticket__lab">备注</span>
<span class="pl-stop-feedback-ticket__text">{{ siteFeedback.remark }}</span>
</div>
</div>
<div class="pl-stop-feedback-ticket__foot">
<span class="pl-stop-feedback-ticket__lab">附件</span>
<AttachmentUploadField
v-if="editableAttachments || siteAttachmentCsv"
ref="siteAttachRef"
class="pl-stop-feedback-ticket__attach"
:class="{ 'pl-stop-feedback-ticket__attach--editable': editableAttachments }"
:model-value="siteAttachmentModel"
:disabled="!editableAttachments"
compact
folder="pl/transport/site-feedback"
accept="image/*,video/*,.pdf"
:limit="15"
@update:model-value="handleSiteAttachmentChange"
/>
<span v-else class="pl-plan-form-empty-hint">—</span>
</div>
</template>
</div>
</section>
<section v-if="showDibangCard" class="pl-stop-feedback-card">
<div class="pl-stop-feedback-ticket">
<div class="pl-stop-feedback-ticket__band pl-stop-feedback-ticket__band--dibang">
<span class="pl-stop-feedback-ticket__who">地磅单</span>
<span v-if="dibangRows.length === 1" class="pl-stop-feedback-ticket__when">{{
dibangBatchNo(dibangRows[0])
}}</span>
</div>
<p
v-if="!dibangRows.length"
class="pl-plan-form-empty-hint pl-stop-feedback-ticket__empty"
>
暂无关联地磅单
</p>
<template v-else>
<div
v-for="(row, idx) in dibangRows"
:key="row.link.dbInventoryId || idx"
class="pl-stop-feedback-dibang-item"
:class="{ 'pl-stop-feedback-dibang-item--split': dibangRows.length > 1 }"
>
<p class="pl-stop-feedback-ticket__product">
{{ dibangProductLabel(row, idx) }}
</p>
<div class="pl-stop-feedback-ticket__qty pl-stop-feedback-ticket__qty--compact">
<div>
<div class="pl-stop-feedback-ticket__lab">{{
row.weighing ? '净重(吨)' : '数量(吨)'
}}</div>
<div class="pl-stop-feedback-ticket__val pl-stop-feedback-ticket__val--highlight">{{
dibangPrimaryQty(row)
}}</div>
</div>
<div>
<div class="pl-stop-feedback-ticket__lab">{{
row.weighing ? '毛/皮(吨)' : '状态'
}}</div>
<div
class="pl-stop-feedback-ticket__val"
:class="
row.weighing
? 'pl-stop-feedback-ticket__val--highlight'
: 'pl-stop-feedback-ticket__val--sm'
"
>
{{ dibangSecondaryQty(row) }}
</div>
</div>
</div>
<div class="pl-stop-feedback-ticket__lines pl-stop-feedback-ticket__lines--compact">
<div class="pl-stop-feedback-ticket__row">
<div class="pl-stop-feedback-ticket__line">
<span class="pl-stop-feedback-ticket__lab">单号</span>
<span class="pl-stop-feedback-ticket__text">{{ dibangBatchNo(row) }}</span>
</div>
<div class="pl-stop-feedback-ticket__line">
<span class="pl-stop-feedback-ticket__lab">业务</span>
<span class="pl-stop-feedback-ticket__text">{{ dibangBusinessType(row) }}</span>
</div>
</div>
<div class="pl-stop-feedback-ticket__line pl-stop-feedback-ticket__line--full">
<span class="pl-stop-feedback-ticket__lab">往来</span>
<span class="pl-stop-feedback-ticket__text">{{ dibangPartner(row) }}</span>
</div>
</div>
<p v-if="!row.weighing" class="pl-plan-form-empty-hint pl-stop-feedback-ticket__hint">
尚未关联地磅明细
</p>
</div>
</template>
</div>
</section>
</div>
</div>
</template>
<script setup lang="ts">
import { computed, ref } from 'vue'
import type { TransportStopFeedback } from '@/api/pl'
import AttachmentUploadField from '@/components/business/attachment-upload-field/index.vue'
import { formatKgToTon } from '@/components/business/db/db-related-view'
import type { PlanFormProductRow } from '@/composables/usePlContractToPlan'
import type { PlPlanTransportDibangRow } from '@/composables/usePlPlanViewDetail'
import { formatDateTime } from '@/utils/format'
import { isPlInternalCustomerName } from '@/utils/pl-internal-customer'
const props = withDefaults(
defineProps<{
stopLabel?: string
customerName?: string
generateDibang?: number
dibangRows?: PlPlanTransportDibangRow[]
/** 用于解析 CRM 标准产品名(库内 link.productName 可能是别名) */
planProductRows?: PlanFormProductRow[]
driverFeedback?: TransportStopFeedback | null
siteFeedback?: TransportStopFeedback | null
/** 段级无备注时回退展示(如运输单级司机回传备注) */
fallbackRemark?: string
/** 无回传数据时也展示卡片空态 */
showWhenEmpty?: boolean
/** 归档弹窗等场景:允许编辑段级回传附件 */
editableAttachments?: boolean
driverAttachmentUrls?: string
siteAttachmentUrls?: string
}>(),
{
stopLabel: '',
customerName: '',
generateDibang: 0,
dibangRows: () => [],
planProductRows: () => [],
driverFeedback: null,
siteFeedback: null,
fallbackRemark: '',
showWhenEmpty: true,
editableAttachments: false,
driverAttachmentUrls: '',
siteAttachmentUrls: ''
}
)
const emit = defineEmits<{
'update:driverAttachmentUrls': [value: string]
'update:siteAttachmentUrls': [value: string]
}>()
const driverAttachRef = ref<InstanceType<typeof AttachmentUploadField> | null>(null)
const siteAttachRef = ref<InstanceType<typeof AttachmentUploadField> | null>(null)
const isInternalCustomer = computed(() => isPlInternalCustomerName(props.customerName))
const showSiteCard = computed(() => isInternalCustomer.value)
const showDibangCard = computed(
() => isInternalCustomer.value && (props.generateDibang === 1 || (props.dibangRows?.length ?? 0) > 0)
)
const cardCount = computed(() => {
let count = 1
if (showSiteCard.value) count += 1
if (showDibangCard.value) count += 1
return count
})
const cardsLayoutClass = computed(() => {
if (cardCount.value >= 3) return 'is-cols-3'
if (cardCount.value === 2) return 'is-cols-2'
return 'is-cols-1'
})
const driverRemarkDisplay = computed(() => {
const stopRemark = (props.driverFeedback?.remark || '').trim()
if (stopRemark) return stopRemark
return (props.fallbackRemark || '').trim()
})
const hasDriverFeedback = computed(() =>
Boolean(
driverRemarkDisplay.value ||
props.driverFeedback?.attachmentUrls?.length ||
props.driverFeedback?.products?.length ||
props.driverFeedback?.feedbackTime
)
)
const hasSiteFeedback = computed(() =>
Boolean(
props.siteFeedback?.quantity != null ||
props.siteFeedback?.remark ||
props.siteFeedback?.attachmentUrls?.length ||
props.siteFeedback?.products?.length ||
props.siteFeedback?.feedbackTime
)
)
const hasAnyFeedback = computed(
() =>
hasDriverFeedback.value ||
hasSiteFeedback.value ||
(props.dibangRows?.length ?? 0) > 0
)
const visible = computed(() => props.showWhenEmpty || hasAnyFeedback.value)
const panelTitle = computed(() =>
props.stopLabel ? `${props.stopLabel} · 执行回传` : '执行回传'
)
const driverAttachmentCsv = computed(() => (props.driverFeedback?.attachmentUrls || []).join(','))
const siteAttachmentCsv = computed(() => (props.siteFeedback?.attachmentUrls || []).join(','))
const driverAttachmentModel = computed({
get: () =>
props.editableAttachments ? props.driverAttachmentUrls || '' : driverAttachmentCsv.value,
set: (value: string) => {
if (props.editableAttachments) {
emit('update:driverAttachmentUrls', value)
}
}
})
const siteAttachmentModel = computed({
get: () =>
props.editableAttachments ? props.siteAttachmentUrls || '' : siteAttachmentCsv.value,
set: (value: string) => {
if (props.editableAttachments) {
emit('update:siteAttachmentUrls', value)
}
}
})
function handleDriverAttachmentChange(value: string) {
if (props.editableAttachments) {
emit('update:driverAttachmentUrls', value)
}
}
function handleSiteAttachmentChange(value: string) {
if (props.editableAttachments) {
emit('update:siteAttachmentUrls', value)
}
}
function hasAttachmentUploading() {
return Boolean(driverAttachRef.value?.hasUploading?.() || siteAttachRef.value?.hasUploading?.())
}
defineExpose({ hasAttachmentUploading })
function formatFeedbackTime(value?: string) {
return formatDateTime(value) || '—'
}
function formatSiteBusinessType(value?: string) {
const text = (value || '').trim()
if (text === 'outbound') return '出库'
if (text === 'inbound') return '入库'
return text || '—'
}
function formatDriverProductQty(product: NonNullable<TransportStopFeedback['products']>[number]) {
const qty = product.actualQty
const unit = product.unit || '吨'
if (qty == null) return '—'
return `${qty} ${unit}`
}
function formatSiteProductQty(product: NonNullable<TransportStopFeedback['products']>[number]) {
const qty = product.actualQty ?? product.quantity
const unit = product.unit || '吨'
if (qty == null) return { qty: '—', unit: '' }
return { qty: String(qty), unit: ` ${unit}` }
}
function resolvePlanProductRow(row: PlPlanTransportDibangRow) {
const id = String(row.link.planProductId || '').trim()
if (!id) return undefined
return (props.planProductRows || []).find((p) => String(p.id || '').trim() === id)
}
function dibangProductLabel(row: PlPlanTransportDibangRow, idx: number): string {
const planRow = resolvePlanProductRow(row)
// 优先 CRM 标准名;link.productName / planRow.productName 可能是别名
const product = (
String(planRow?.standardProductName || '').trim() ||
row.inventory?.product ||
row.weighing?.cargoName ||
String(planRow?.productName || '').trim() ||
row.link.productName ||
''
).trim()
const specification = (
String(planRow?.model || '').trim() ||
row.inventory?.specification ||
row.weighing?.specification ||
''
).trim()
if (!product && !specification) return `地磅 ${idx + 1}`
if (!specification) return product
if (!product) return specification
if (product.endsWith(specification)) {
const base = product.slice(0, -specification.length).trimEnd()
return base ? `${base} ${specification}` : specification
}
return `${product} ${specification}`
}
function dibangBatchNo(row: PlPlanTransportDibangRow): string {
return row.weighing?.batchNo || row.inventory?.batchNo || row.link.batchNo || '—'
}
function dibangBusinessType(row: PlPlanTransportDibangRow): string {
return row.weighing?.businessType || row.inventory?.businessType || '—'
}
function dibangPartner(row: PlPlanTransportDibangRow): string {
if (row.inventory?.partnerCompany) return row.inventory.partnerCompany
const weighing = row.weighing
if (!weighing) return '—'
const businessType = dibangBusinessType(row)
if (businessType === '入库') return weighing.supplier || weighing.consignee || '—'
return weighing.consignee || weighing.supplier || '—'
}
function dibangPrimaryQty(row: PlPlanTransportDibangRow): string {
if (row.weighing) return formatKgToTon(row.weighing.netWeight)
if (row.inventory?.quantity != null && row.inventory.quantity !== undefined) {
return String(row.inventory.quantity)
}
return '—'
}
function dibangSecondaryQty(row: PlPlanTransportDibangRow): string {
if (row.weighing) {
return `${formatKgToTon(row.weighing.grossWeight)} / ${formatKgToTon(row.weighing.tareWeight)}`
}
return row.inventory?.status || '—'
}
</script>
<style scoped lang="scss">
.pl-plan-stop-feedback-panel {
margin-top: 12px;
padding-top: 12px;
border-top: 1px dashed #e2e8f0;
}
.pl-plan-stop-feedback-panel__title {
margin: 0 0 10px;
font-size: 13px;
font-weight: 600;
color: #475569;
}
.pl-stop-feedback-cards {
display: grid;
gap: 10px;
align-items: stretch;
&.is-cols-1 {
grid-template-columns: minmax(0, 280px);
}
&.is-cols-2 {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
&.is-cols-3 {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
}
.pl-stop-feedback-card {
min-width: 0;
min-height: 100%;
border: 1px solid #e2e8f0;
border-radius: 8px;
overflow: hidden;
background: #fff;
}
.pl-stop-feedback-ticket {
display: flex;
flex-direction: column;
min-height: 100%;
background: #fff;
}
.pl-stop-feedback-ticket__band {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
padding: 8px 10px;
border-bottom: 1px solid #e2e8f0;
&--driver {
background: linear-gradient(90deg, #ecfdf5 0%, #f8fafc 100%);
}
&--site {
background: linear-gradient(90deg, #eff6ff 0%, #f8fafc 100%);
}
&--dibang {
background: linear-gradient(90deg, #fff7ed 0%, #f8fafc 100%);
}
// 标题栏与正文第一行间距
& + * {
margin-top: 5px;
}
}
.pl-stop-feedback-ticket__who {
font-size: 12px;
font-weight: 600;
color: #1e293b;
}
.pl-stop-feedback-ticket__when {
flex-shrink: 0;
max-width: 52%;
font-size: 11px;
color: #64748b;
text-align: right;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.pl-stop-feedback-ticket__product {
margin: 0;
padding: 0 10px;
font-size: 12px;
font-weight: 500;
color: #334155;
}
.pl-stop-feedback-ticket__qty {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 8px;
padding: 8px 10px;
&--compact {
padding-top: 4px;
}
}
.pl-stop-feedback-ticket__lab {
font-size: 11px;
color: #64748b;
}
.pl-stop-feedback-ticket__val {
margin-top: 2px;
font-size: 16px;
font-weight: 600;
color: #0f172a;
line-height: 1.2;
&--highlight {
font-size: 18px;
font-weight: 700;
color: #059669;
font-variant-numeric: tabular-nums;
}
&--sm {
font-size: 12px;
font-weight: 500;
}
}
.pl-stop-feedback-ticket__lines {
padding: 0 10px 8px;
display: flex;
flex-direction: column;
gap: 4px;
&--compact {
padding-top: 0;
}
}
.pl-stop-feedback-ticket__row {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 8px;
padding: 0;
}
.pl-stop-feedback-ticket__line {
display: flex;
flex-direction: column;
gap: 2px;
min-width: 0;
padding: 0 10px 6px;
}
.pl-stop-feedback-ticket__lines .pl-stop-feedback-ticket__line {
padding: 0;
}
.pl-stop-feedback-ticket__lines .pl-stop-feedback-ticket__line--full {
padding: 0;
}
.pl-stop-feedback-ticket__text {
font-size: 12px;
color: #1e293b;
word-break: break-word;
line-height: 1.4;
}
.pl-stop-feedback-ticket__products {
display: flex;
flex-direction: column;
gap: 4px;
padding: 0 10px;
}
.pl-stop-feedback-ticket__product-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 6px;
}
.pl-stop-feedback-ticket__text--qty {
display: inline-flex;
align-items: baseline;
gap: 2px;
flex-shrink: 0;
font-size: 12px;
font-weight: 400;
color: #64748b;
.pl-stop-feedback-ticket__val--highlight {
font-size: 18px;
font-weight: 700;
color: #059669;
font-variant-numeric: tabular-nums;
line-height: 1.2;
}
}
.pl-stop-feedback-ticket__unit {
font-size: 12px;
font-weight: 400;
color: #64748b;
}
.pl-stop-feedback-ticket__foot {
display: flex;
flex-direction: column;
gap: 4px;
margin-top: auto;
padding: 8px 10px 10px;
border-top: 1px solid #f1f5f9;
}
.pl-stop-feedback-ticket__empty {
padding: 7px 10px 12px;
flex: 1;
}
.pl-stop-feedback-ticket__hint {
margin: 0;
padding: 0 10px 8px;
font-size: 12px;
}
.pl-stop-feedback-dibang-item {
&--split + &--split {
border-top: 1px dashed #e2e8f0;
margin-top: 4px;
padding-top: 4px;
}
}
.pl-plan-form-empty-hint {
margin: 0;
font-size: 12px;
color: var(--mint-text-muted, #94a3b8);
}
.pl-stop-feedback-ticket__attach {
:deep(.attachment-list) {
gap: 4px;
}
:deep(.attachment-item) {
width: 56px;
border-radius: 6px;
}
:deep(.attachment-preview) {
height: 40px;
}
}
.pl-stop-feedback-ticket__attach--editable {
:deep(.upload-card) {
width: 88px;
height: 66px;
}
:deep(.attachment-item) {
width: 88px;
}
:deep(.attachment-preview) {
height: 66px;
}
}
@media (max-width: 1280px) {
.pl-stop-feedback-cards.is-cols-3 {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
}
@media (max-width: 900px) {
.pl-stop-feedback-cards.is-cols-2,
.pl-stop-feedback-cards.is-cols-3 {
grid-template-columns: 1fr;
}
.pl-stop-feedback-cards.is-cols-1 {
grid-template-columns: 1fr;
max-width: none;
}
}
</style>