1125 lines
33 KiB
Vue
1125 lines
33 KiB
Vue
<!-- 出库物料编辑区(细胞 / 质检物料 / 纸质材料) -->
|
||
<!-- eslint-disable vue/no-v-model-argument -->
|
||
<template>
|
||
<div class="outbound-material-form-sections">
|
||
<div class="material-sections">
|
||
<!-- 出库细胞 -->
|
||
<section class="section-card">
|
||
<div class="section-head">
|
||
<h3 class="section-title section-title--mint-bar">出库细胞</h3>
|
||
<el-button type="primary" size="small" class="btn-main" @click="openCellSelect">
|
||
<el-icon><Plus /></el-icon>
|
||
添加细胞产品
|
||
</el-button>
|
||
</div>
|
||
<div class="list-body list-wrap inner-table-wrap">
|
||
<el-table
|
||
:data="cellRows"
|
||
class="list-table inner-table"
|
||
stripe
|
||
max-height="280"
|
||
empty-text="请从细胞产品库勾选"
|
||
>
|
||
<el-table-column type="index" label="序号" min-width="56" align="center" />
|
||
<el-table-column
|
||
prop="productCode"
|
||
label="产品编码"
|
||
min-width="160"
|
||
show-overflow-tooltip
|
||
/>
|
||
<el-table-column
|
||
prop="productName"
|
||
label="产品名称"
|
||
min-width="120"
|
||
show-overflow-tooltip
|
||
/>
|
||
<el-table-column prop="productTypeName" label="产品类型" min-width="100" />
|
||
<el-table-column prop="specName" label="规格" min-width="90" />
|
||
<el-table-column prop="passage" label="代次" min-width="70" align="center" />
|
||
<el-table-column
|
||
prop="storageSlotName"
|
||
label="储物格"
|
||
min-width="140"
|
||
show-overflow-tooltip
|
||
/>
|
||
<el-table-column label="状态" min-width="90" align="center">
|
||
<template #default="{ row }">
|
||
<el-tag
|
||
v-if="row.productStatus"
|
||
:type="cellProductStatusTagType(row.productStatus) as any"
|
||
size="small"
|
||
>
|
||
{{ cellProductStatusLabel(row.productStatus) }}
|
||
</el-tag>
|
||
<span v-else>—</span>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="操作" min-width="80" align="center" fixed="right">
|
||
<template #default="{ $index }">
|
||
<el-button type="danger" link size="small" @click="removeCellRow($index)">
|
||
<el-icon><Delete /></el-icon>
|
||
删除
|
||
</el-button>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
</div>
|
||
</section>
|
||
|
||
<!-- 使用的物料 -->
|
||
<section class="section-card">
|
||
<div class="section-head">
|
||
<h3 class="section-title section-title--mint-bar">使用的物料</h3>
|
||
<el-button type="primary" size="small" class="btn-main" @click="addMaterialRow">
|
||
<el-icon><Plus /></el-icon>
|
||
添加物料
|
||
</el-button>
|
||
</div>
|
||
<el-table
|
||
v-if="materialRows.length"
|
||
:data="materialRows"
|
||
:row-key="(row) => row._rowKey"
|
||
stripe
|
||
class="list-table inner-table"
|
||
max-height="280"
|
||
>
|
||
<el-table-column type="index" label="序号" min-width="56" align="center" />
|
||
<el-table-column label="物料名称" min-width="180">
|
||
<template #default="{ row, $index }">
|
||
<el-select
|
||
v-model="row.materialId"
|
||
filterable
|
||
remote
|
||
reserve-keyword
|
||
clearable
|
||
placeholder="输入物料名称检索"
|
||
:loading="materialOptionsLoading"
|
||
:remote-method="remoteSearchMaterials"
|
||
class="inner-cell-input"
|
||
@visible-change="(visible) => visible && remoteSearchMaterials('')"
|
||
@change="(v) => onMaterialSelect($index, v)"
|
||
>
|
||
<el-option
|
||
v-for="opt in materialOptions"
|
||
:key="opt.id"
|
||
:label="opt.label"
|
||
:value="opt.id"
|
||
:disabled="isMaterialOptionDisabled(opt.id, $index)"
|
||
/>
|
||
</el-select>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="规格型号" min-width="120">
|
||
<template #default="{ row }">{{ row.specModel || '—' }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="计划用量" min-width="130">
|
||
<template #default="{ row }">
|
||
<el-input-number
|
||
v-model="row.qty"
|
||
:min="0.0001"
|
||
:precision="4"
|
||
:step="1"
|
||
controls-position="right"
|
||
class="inner-cell-input"
|
||
/>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="单位" min-width="72" align="center">
|
||
<template #default="{ row }">{{ row.unit || '—' }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="当前库存" min-width="100" align="center">
|
||
<template #default="{ row }">
|
||
{{ stockQtyDisplay(row.materialId) }}
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="操作" min-width="80" align="center" fixed="right">
|
||
<template #default="{ $index }">
|
||
<el-button type="danger" link size="small" @click="removeMaterialRow($index)">
|
||
<el-icon><Delete /></el-icon>
|
||
删除
|
||
</el-button>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
<p v-else class="section-empty-hint">点击「添加物料」从质检物料库勾选并填写计划用量</p>
|
||
</section>
|
||
|
||
<!-- 纸质材料 -->
|
||
<section class="section-card">
|
||
<div class="section-head">
|
||
<h3 class="section-title section-title--mint-bar">纸质材料</h3>
|
||
<el-button type="primary" size="small" class="btn-main" @click="addPaperRow">
|
||
<el-icon><Plus /></el-icon>
|
||
添加纸质材料
|
||
</el-button>
|
||
</div>
|
||
<el-table
|
||
v-if="paperRows.length"
|
||
:data="paperRows"
|
||
:row-key="(row) => row._rowKey"
|
||
stripe
|
||
class="list-table inner-table"
|
||
max-height="280"
|
||
>
|
||
<el-table-column type="index" label="序号" min-width="56" align="center" />
|
||
<el-table-column label="名称" min-width="200">
|
||
<template #default="{ row }">
|
||
<el-select
|
||
v-model="row.paperName"
|
||
filterable
|
||
allow-create
|
||
default-first-option
|
||
clearable
|
||
placeholder="请选择或输入材料名称"
|
||
class="inner-cell-input"
|
||
>
|
||
<el-option
|
||
v-for="opt in PAPER_NAME_OPTIONS"
|
||
:key="opt"
|
||
:label="opt"
|
||
:value="opt"
|
||
/>
|
||
</el-select>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="份数" min-width="120">
|
||
<template #default="{ row }">
|
||
<el-input-number
|
||
v-model="row.copies"
|
||
:min="1"
|
||
:precision="0"
|
||
:step="1"
|
||
controls-position="right"
|
||
class="inner-cell-input"
|
||
/>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="附件" min-width="320">
|
||
<template #default="{ row, $index }">
|
||
<div class="paper-att-cards">
|
||
<div
|
||
v-for="(att, attIdx) in row.attachments"
|
||
:key="attIdx"
|
||
class="paper-att-card"
|
||
:class="{
|
||
'paper-att-card--image': isImageFile(att),
|
||
'paper-att-card--video': isVideoFile(att)
|
||
}"
|
||
:title="att.fileName"
|
||
>
|
||
<div
|
||
class="paper-att-card__preview"
|
||
:class="{
|
||
'is-clickable': isImageFile(att) || isVideoFile(att)
|
||
}"
|
||
@click="
|
||
(isImageFile(att) || isVideoFile(att)) && handlePreviewPaperAttachment(att)
|
||
"
|
||
>
|
||
<img
|
||
v-if="isImageFile(att)"
|
||
:src="fullFileUrl(att.attachmentUrl)"
|
||
:alt="att.fileName || '附件'"
|
||
/>
|
||
<template v-else-if="isVideoFile(att)">
|
||
<div class="paper-att-card__type-icon paper-att-card__type-icon--video">
|
||
<el-icon><VideoPlay /></el-icon>
|
||
</div>
|
||
</template>
|
||
<template v-else>
|
||
<el-icon class="paper-att-card__type-icon paper-att-card__type-icon--doc">
|
||
<Document />
|
||
</el-icon>
|
||
<span class="paper-att-card__name">{{ att.fileName || '附件' }}</span>
|
||
</template>
|
||
</div>
|
||
<div class="paper-att-card__actions">
|
||
<el-icon
|
||
v-if="isImageFile(att) || isVideoFile(att)"
|
||
class="paper-att-card__action"
|
||
title="预览"
|
||
@click.stop="handlePreviewPaperAttachment(att)"
|
||
>
|
||
<View />
|
||
</el-icon>
|
||
<el-icon
|
||
class="paper-att-card__action"
|
||
title="下载"
|
||
@click.stop="handleDownloadPaperAttachment(att)"
|
||
>
|
||
<Download />
|
||
</el-icon>
|
||
<el-icon
|
||
class="paper-att-card__action paper-att-card__action--danger"
|
||
title="删除"
|
||
@click.stop="removePaperAttachment($index, attIdx)"
|
||
>
|
||
<Delete />
|
||
</el-icon>
|
||
</div>
|
||
</div>
|
||
<el-upload
|
||
:auto-upload="false"
|
||
:show-file-list="false"
|
||
accept="image/*,video/*,.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.txt,.zip,.rar"
|
||
@change="(file) => handlePaperAttachmentChange($index, file)"
|
||
>
|
||
<div
|
||
class="paper-att-card paper-att-card--trigger"
|
||
:class="{ 'is-loading': row._uploading }"
|
||
>
|
||
<el-icon class="paper-att-card__trigger-icon"><Plus /></el-icon>
|
||
<span>{{ row._uploading ? '上传中' : '上传' }}</span>
|
||
</div>
|
||
</el-upload>
|
||
</div>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="操作" min-width="80" align="center" fixed="right">
|
||
<template #default="{ $index }">
|
||
<el-button type="danger" link size="small" @click="removePaperRow($index)">
|
||
<el-icon><Delete /></el-icon>
|
||
删除
|
||
</el-button>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
<p v-else class="section-empty-hint">点击「添加纸质材料」逐条填写名称、份数并上传附件;仅作台账留存,不扣库存</p>
|
||
</section>
|
||
|
||
<el-form label-position="top" class="biz-dialog-form">
|
||
<el-form-item label="备注">
|
||
<el-input
|
||
v-model="formRemark"
|
||
type="textarea"
|
||
:rows="2"
|
||
placeholder="可选"
|
||
maxlength="512"
|
||
show-word-limit
|
||
/>
|
||
</el-form-item>
|
||
</el-form>
|
||
</div>
|
||
|
||
<!-- 细胞产品选择 -->
|
||
<el-dialog
|
||
v-model="cellSelectVisible"
|
||
title="选择细胞产品"
|
||
width="1200px"
|
||
class="dialog-form-layout"
|
||
align-center
|
||
destroy-on-close
|
||
append-to-body
|
||
:close-on-click-modal="false"
|
||
style="backdrop-filter: none"
|
||
>
|
||
<el-input
|
||
v-model="cellSearchKeyword"
|
||
placeholder="搜索产品编码或名称"
|
||
clearable
|
||
style="margin-bottom: 12px"
|
||
@input="loadCellProductOptions"
|
||
>
|
||
<template #prefix>
|
||
<el-icon><Search /></el-icon>
|
||
</template>
|
||
</el-input>
|
||
<div class="list-body list-wrap">
|
||
<el-table
|
||
ref="cellSelectTableRef"
|
||
class="list-table"
|
||
:data="cellProductOptions"
|
||
stripe
|
||
row-key="id"
|
||
height="380"
|
||
v-loading="cellProductLoading"
|
||
@selection-change="onCellSelectionChange"
|
||
>
|
||
<el-table-column
|
||
type="selection"
|
||
min-width="45"
|
||
align="center"
|
||
:selectable="isCellRowSelectable"
|
||
/>
|
||
<el-table-column prop="productCode" label="产品编码" min-width="180" show-overflow-tooltip />
|
||
<el-table-column prop="productName" label="产品名称" min-width="120" show-overflow-tooltip />
|
||
<el-table-column prop="productTypeName" label="产品类型" min-width="90" />
|
||
<el-table-column prop="passage" label="代次" min-width="70" align="center" />
|
||
<el-table-column prop="storageSlotName" label="储物格" min-width="140" show-overflow-tooltip />
|
||
<el-table-column label="状态" min-width="90" align="center">
|
||
<template #default="{ row }">
|
||
<el-tag :type="cellProductStatusTagType(row.productStatus) as any" size="small">
|
||
{{ cellProductStatusLabel(row.productStatus) }}
|
||
</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column prop="batchNo" label="批次号" min-width="110" show-overflow-tooltip />
|
||
<el-table-column prop="specName" label="规格" min-width="90" show-overflow-tooltip />
|
||
</el-table>
|
||
</div>
|
||
<template #footer>
|
||
<el-button @click="cellSelectVisible = false">取消</el-button>
|
||
<el-button type="primary" :disabled="!cellSelectedRows.length" @click="confirmCellSelect">
|
||
确定(已选 {{ cellSelectedRows.length }} 项)
|
||
</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<el-dialog
|
||
v-model="previewVisible"
|
||
title="文件预览"
|
||
width="800px"
|
||
align-center
|
||
destroy-on-close
|
||
append-to-body
|
||
style="backdrop-filter: none"
|
||
>
|
||
<div v-if="previewType === 'image'" class="preview-container">
|
||
<img
|
||
:src="previewUrl"
|
||
alt="预览"
|
||
style="max-width: 100%; max-height: 70vh; display: block; margin: 0 auto"
|
||
/>
|
||
</div>
|
||
<div v-else class="preview-container">
|
||
<video
|
||
:src="previewUrl"
|
||
controls
|
||
style="max-width: 100%; max-height: 70vh; display: block; margin: 0 auto"
|
||
/>
|
||
</div>
|
||
</el-dialog>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { ElMessage } from 'element-plus'
|
||
import {
|
||
Plus,
|
||
Delete,
|
||
Search,
|
||
Document,
|
||
Download,
|
||
View,
|
||
VideoPlay
|
||
} from '@element-plus/icons-vue'
|
||
import { fetchUploadAttachment } from '@/api/business'
|
||
import { fetchCellProductList } from '@/api/cell-product'
|
||
import { fetchQcMaterialList, type QcMaterialOption } from '@/api/qc-material'
|
||
import type { OutboundReleaseCellRow } from '@/api/outbound-release-review'
|
||
import { downloadAttachmentFile } from '@/utils/download-attachment'
|
||
import { cellProductStatusLabel, cellProductStatusTagType } from '@/utils/status-tag-registry'
|
||
|
||
const props = withDefaults(
|
||
defineProps<{
|
||
/** 出库交接等需扣库存场景:仅允许选择已冻存细胞,且已选行保留可选 */
|
||
requireFrozenCellProduct?: boolean
|
||
}>(),
|
||
{
|
||
requireFrozenCellProduct: false
|
||
}
|
||
)
|
||
|
||
type AttachmentLike = {
|
||
fileName?: string
|
||
fileUrl?: string
|
||
attachmentUrl?: string
|
||
fileType?: string
|
||
}
|
||
|
||
type PaperAttachment = {
|
||
attachmentUrl: string
|
||
fileName: string
|
||
fileType?: string
|
||
}
|
||
|
||
type PaperRow = {
|
||
_rowKey: string
|
||
paperName: string
|
||
copies?: number
|
||
attachments: PaperAttachment[]
|
||
_uploading?: boolean
|
||
}
|
||
|
||
type MaterialRow = {
|
||
_rowKey: string
|
||
materialId: string
|
||
materialName: string
|
||
specModel: string
|
||
unit: string
|
||
qty?: number
|
||
remark?: string
|
||
}
|
||
|
||
const PAPER_NAME_OPTIONS = ['细胞产品检测报告', '出库单', '接收确认书']
|
||
|
||
defineOptions({ name: 'OutboundMaterialFormSections' })
|
||
|
||
const loading = ref(false)
|
||
const formRemark = ref('')
|
||
const cellRows = ref<OutboundReleaseCellRow[]>([])
|
||
const materialRows = ref<MaterialRow[]>([])
|
||
const paperRows = ref<PaperRow[]>([])
|
||
const materialOptions = ref<QcMaterialOption[]>([])
|
||
const materialOptionsLoading = ref(false)
|
||
|
||
const cellSelectVisible = ref(false)
|
||
const cellSearchKeyword = ref('')
|
||
const cellProductOptions = ref<Record<string, any>[]>([])
|
||
const cellProductLoading = ref(false)
|
||
const cellSelectedRows = ref<Record<string, any>[]>([])
|
||
const cellSelectTableRef = ref()
|
||
|
||
const previewVisible = ref(false)
|
||
const previewUrl = ref('')
|
||
const previewType = ref<'image' | 'video'>('image')
|
||
|
||
const minioBaseUrl = (import.meta.env.VITE_MINIO_BASE_URL || '').replace(/\/$/, '')
|
||
|
||
let materialRowSeq = 0
|
||
let paperRowSeq = 0
|
||
function nextMaterialRowKey() {
|
||
materialRowSeq += 1
|
||
return `mr_${Date.now()}_${materialRowSeq}`
|
||
}
|
||
function nextPaperRowKey() {
|
||
paperRowSeq += 1
|
||
return `pr_${Date.now()}_${paperRowSeq}`
|
||
}
|
||
|
||
function fullFileUrl(url: string) {
|
||
if (!url) return ''
|
||
if (url.startsWith('http://') || url.startsWith('https://') || url.startsWith('/')) {
|
||
return url
|
||
}
|
||
return minioBaseUrl ? `${minioBaseUrl}/${url.replace(/^\//, '')}` : url
|
||
}
|
||
|
||
function isImageFile(file: AttachmentLike) {
|
||
const url = (file.fileUrl || file.attachmentUrl || '').toLowerCase()
|
||
const name = (file.fileName || '').toLowerCase()
|
||
return (
|
||
/\.(jpg|jpeg|png|gif|bmp|webp|svg)(\?|$)/.test(url) ||
|
||
/\.(jpg|jpeg|png|gif|bmp|webp|svg)$/.test(name) ||
|
||
(file.fileType || '').startsWith('image/')
|
||
)
|
||
}
|
||
|
||
function isVideoFile(file: AttachmentLike) {
|
||
const url = (file.fileUrl || file.attachmentUrl || '').toLowerCase()
|
||
const name = (file.fileName || '').toLowerCase()
|
||
return (
|
||
/\.(mp4|webm|ogg|mov|avi)(\?|$)/.test(url) ||
|
||
/\.(mp4|webm|ogg|mov|avi)$/.test(name) ||
|
||
(file.fileType || '').startsWith('video/')
|
||
)
|
||
}
|
||
|
||
function mapMaterialListToOptions(list: Array<Record<string, any>>): QcMaterialOption[] {
|
||
return (list || []).map((m) => ({
|
||
id: String(m.id || ''),
|
||
label: `${m.materialName || ''}${m.materialCode ? ` (${m.materialCode})` : ''}`.trim(),
|
||
materialCode: String(m.materialCode || ''),
|
||
materialName: String(m.materialName || ''),
|
||
specModel: String(m.specModel || ''),
|
||
unit: String(m.unit || ''),
|
||
stockQty: Number(m.stockQty ?? 0)
|
||
}))
|
||
}
|
||
|
||
function ensureMaterialsInOptions(rows: MaterialRow[]) {
|
||
const merged = [...materialOptions.value]
|
||
for (const row of rows) {
|
||
const id = String(row.materialId || '')
|
||
if (!id || merged.some((o) => o.id === id)) continue
|
||
merged.push({
|
||
id,
|
||
label: row.materialName || id,
|
||
materialCode: '',
|
||
materialName: row.materialName || '',
|
||
specModel: row.specModel || '',
|
||
unit: row.unit || '',
|
||
stockQty: 0
|
||
})
|
||
}
|
||
materialOptions.value = merged
|
||
}
|
||
|
||
async function remoteSearchMaterials(query: string) {
|
||
materialOptionsLoading.value = true
|
||
try {
|
||
const res = await fetchQcMaterialList({
|
||
page: 1,
|
||
pageSize: 100,
|
||
keyword: query?.trim() || undefined
|
||
})
|
||
materialOptions.value = mapMaterialListToOptions(res.list || [])
|
||
ensureMaterialsInOptions(materialRows.value)
|
||
} catch {
|
||
materialOptions.value = []
|
||
ensureMaterialsInOptions(materialRows.value)
|
||
} finally {
|
||
materialOptionsLoading.value = false
|
||
}
|
||
}
|
||
|
||
function stockQtyDisplay(materialId: string) {
|
||
const opt = materialOptions.value.find((o) => o.id === materialId)
|
||
if (!opt || opt.stockQty == null) return '—'
|
||
return String(opt.stockQty)
|
||
}
|
||
|
||
function isMaterialOptionDisabled(materialId: string, currentIndex: number) {
|
||
return materialRows.value.some((r, i) => i !== currentIndex && r.materialId === materialId)
|
||
}
|
||
|
||
function onMaterialSelect(index: number, id: string) {
|
||
const row = materialRows.value[index]
|
||
if (!row) return
|
||
if (!id) {
|
||
row.materialId = ''
|
||
row.materialName = ''
|
||
row.specModel = ''
|
||
row.unit = ''
|
||
return
|
||
}
|
||
if (isMaterialOptionDisabled(id, index)) {
|
||
ElMessage.warning('该物料已在列表中,请勿重复添加')
|
||
row.materialId = ''
|
||
return
|
||
}
|
||
const opt = materialOptions.value.find((o) => o.id === id)
|
||
row.materialId = id
|
||
row.materialName = opt?.materialName || ''
|
||
row.specModel = opt?.specModel || ''
|
||
row.unit = opt?.unit || ''
|
||
}
|
||
|
||
function addMaterialRow() {
|
||
materialRows.value.push({
|
||
_rowKey: nextMaterialRowKey(),
|
||
materialId: '',
|
||
materialName: '',
|
||
specModel: '',
|
||
unit: '',
|
||
qty: undefined
|
||
})
|
||
}
|
||
|
||
function removeMaterialRow(index: number) {
|
||
materialRows.value.splice(index, 1)
|
||
}
|
||
|
||
function addPaperRow() {
|
||
paperRows.value.push({
|
||
_rowKey: nextPaperRowKey(),
|
||
paperName: '',
|
||
copies: 1,
|
||
attachments: []
|
||
})
|
||
}
|
||
|
||
function removePaperRow(index: number) {
|
||
paperRows.value.splice(index, 1)
|
||
}
|
||
|
||
function removePaperAttachment(rowIndex: number, attachmentIndex: number) {
|
||
const row = paperRows.value[rowIndex]
|
||
if (!row) return
|
||
row.attachments.splice(attachmentIndex, 1)
|
||
}
|
||
|
||
function attachmentFileName(url: string) {
|
||
return url.split('/').pop() || '附件'
|
||
}
|
||
|
||
function parseAttachmentList(urlStr: string): PaperAttachment[] {
|
||
if (!urlStr?.trim()) return []
|
||
return urlStr
|
||
.split(',')
|
||
.map((u) => u.trim())
|
||
.filter(Boolean)
|
||
.map((url) => ({
|
||
attachmentUrl: url,
|
||
fileName: attachmentFileName(url)
|
||
}))
|
||
}
|
||
|
||
function mapPaperRowsFromApi(
|
||
paperMaterials: Array<{
|
||
paperName?: string
|
||
copies?: number
|
||
attachmentUrl?: string
|
||
}> = [],
|
||
legacyUrls = ''
|
||
) {
|
||
if (paperMaterials.length) {
|
||
return paperMaterials.map((p) => ({
|
||
_rowKey: nextPaperRowKey(),
|
||
paperName: p.paperName || '',
|
||
copies: p.copies && p.copies > 0 ? p.copies : 1,
|
||
attachments: parseAttachmentList(p.attachmentUrl || '')
|
||
}))
|
||
}
|
||
if (!legacyUrls.trim()) return []
|
||
return legacyUrls
|
||
.split(',')
|
||
.map((u) => u.trim())
|
||
.filter(Boolean)
|
||
.map((attachmentUrl) => ({
|
||
_rowKey: nextPaperRowKey(),
|
||
paperName: attachmentFileName(attachmentUrl),
|
||
copies: 1,
|
||
attachments: [{ attachmentUrl, fileName: attachmentFileName(attachmentUrl) }]
|
||
}))
|
||
}
|
||
|
||
function removeCellRow(index: number) {
|
||
cellRows.value.splice(index, 1)
|
||
}
|
||
|
||
function isCellRowSelectable(row: Record<string, any>) {
|
||
const ids = new Set(cellRows.value.map((c) => c.cellProductId))
|
||
if (ids.has(row.id)) return false
|
||
if (props.requireFrozenCellProduct && row.productStatus && row.productStatus !== 'frozen') {
|
||
return false
|
||
}
|
||
return true
|
||
}
|
||
|
||
function onCellSelectionChange(rows: Record<string, any>[]) {
|
||
cellSelectedRows.value = rows
|
||
}
|
||
|
||
function openCellSelect() {
|
||
cellSearchKeyword.value = ''
|
||
cellSelectedRows.value = []
|
||
cellSelectVisible.value = true
|
||
loadCellProductOptions()
|
||
}
|
||
|
||
async function loadCellProductOptions() {
|
||
cellProductLoading.value = true
|
||
try {
|
||
const res = await fetchCellProductList({
|
||
page: 1,
|
||
pageSize: 100,
|
||
keyword: cellSearchKeyword.value?.trim() || undefined,
|
||
productStatus: props.requireFrozenCellProduct ? 'frozen' : undefined
|
||
})
|
||
cellProductOptions.value = res.list || []
|
||
} finally {
|
||
cellProductLoading.value = false
|
||
}
|
||
}
|
||
|
||
function confirmCellSelect() {
|
||
if (!cellSelectedRows.value.length) return
|
||
const existing = new Set(cellRows.value.map((c) => c.cellProductId))
|
||
let added = 0
|
||
for (const row of cellSelectedRows.value) {
|
||
if (existing.has(row.id)) continue
|
||
cellRows.value.push({
|
||
cellProductId: row.id,
|
||
productCode: row.productCode || '',
|
||
productName: row.productName || '',
|
||
productTypeName: row.productTypeName || '',
|
||
specName: row.specName || '',
|
||
passage: row.passage || '',
|
||
batchNo: row.batchNo || '',
|
||
storageSlotName: row.storageSlotName || '',
|
||
productStatus: row.productStatus || ''
|
||
})
|
||
existing.add(row.id)
|
||
added += 1
|
||
}
|
||
if (added) {
|
||
cellSelectVisible.value = false
|
||
}
|
||
}
|
||
|
||
async function loadFromApiData(data: {
|
||
remark?: string
|
||
cells?: OutboundReleaseCellRow[]
|
||
qcMaterials?: Array<{
|
||
qcMaterialId?: string
|
||
materialName?: string
|
||
specModel?: string
|
||
unit?: string
|
||
qty?: number
|
||
remark?: string
|
||
}>
|
||
paperMaterials?: Array<{
|
||
paperName?: string
|
||
copies?: number
|
||
attachmentUrl?: string
|
||
}>
|
||
paperAttachments?: string
|
||
}) {
|
||
formRemark.value = data.remark || ''
|
||
cellRows.value = (data.cells || []).map((c) => ({ ...c }))
|
||
materialRows.value = (data.qcMaterials || []).map((m) => ({
|
||
_rowKey: nextMaterialRowKey(),
|
||
materialId: m.qcMaterialId || '',
|
||
materialName: m.materialName || '',
|
||
specModel: m.specModel || '',
|
||
unit: m.unit || '',
|
||
qty: m.qty,
|
||
remark: m.remark || ''
|
||
}))
|
||
paperRows.value = mapPaperRowsFromApi(data.paperMaterials, data.paperAttachments)
|
||
await remoteSearchMaterials('')
|
||
}
|
||
|
||
function validateMaterial() {
|
||
if (paperRows.value.some((r) => r._uploading)) {
|
||
ElMessage.warning('纸质材料附件上传中,请稍候')
|
||
return false
|
||
}
|
||
for (const row of materialRows.value) {
|
||
if (!row.materialId) {
|
||
ElMessage.warning('请为每条物料选择名称')
|
||
return false
|
||
}
|
||
const qty = row.qty
|
||
if (qty == null || !Number.isFinite(Number(qty)) || Number(qty) <= 0) {
|
||
ElMessage.warning('物料计划用量须大于 0')
|
||
return false
|
||
}
|
||
}
|
||
for (const row of paperRows.value) {
|
||
if (!row.paperName?.trim()) {
|
||
ElMessage.warning('请填写每条纸质材料的名称')
|
||
return false
|
||
}
|
||
const copies = row.copies
|
||
if (copies == null || !Number.isFinite(Number(copies)) || Number(copies) <= 0) {
|
||
ElMessage.warning('纸质材料份数须大于 0')
|
||
return false
|
||
}
|
||
if (!row.attachments.length) {
|
||
ElMessage.warning('请为每条纸质材料上传附件')
|
||
return false
|
||
}
|
||
}
|
||
return true
|
||
}
|
||
|
||
function buildSavePayload() {
|
||
return {
|
||
remark: formRemark.value.trim() || undefined,
|
||
paperMaterials: paperRows.value.map((p) => ({
|
||
paperName: p.paperName.trim(),
|
||
copies: Number(p.copies),
|
||
attachmentUrl: p.attachments.map((a) => a.attachmentUrl).join(',')
|
||
})),
|
||
cells: cellRows.value.map((c) => ({
|
||
cellProductId: String(c.cellProductId || ''),
|
||
remark: c.remark
|
||
})),
|
||
qcMaterials: materialRows.value.map((m) => ({
|
||
materialId: m.materialId,
|
||
qty: Number(m.qty),
|
||
remark: m.remark
|
||
}))
|
||
}
|
||
}
|
||
|
||
onMounted(() => {
|
||
void remoteSearchMaterials('')
|
||
})
|
||
|
||
function resetState() {
|
||
cellRows.value = []
|
||
materialRows.value = []
|
||
paperRows.value = []
|
||
formRemark.value = ''
|
||
cellSelectVisible.value = false
|
||
}
|
||
|
||
function handlePreviewPaperAttachment(att: PaperAttachment) {
|
||
if (!att.attachmentUrl) return
|
||
previewUrl.value = fullFileUrl(att.attachmentUrl)
|
||
previewType.value = isVideoFile(att) ? 'video' : 'image'
|
||
previewVisible.value = true
|
||
}
|
||
|
||
function handleDownloadPaperAttachment(att: PaperAttachment) {
|
||
if (!att.attachmentUrl) return
|
||
downloadAttachmentFile(
|
||
{
|
||
fileName: att.fileName,
|
||
fileUrl: att.attachmentUrl,
|
||
fileType: att.fileType || ''
|
||
},
|
||
{ fullFileUrl }
|
||
)
|
||
}
|
||
|
||
async function handlePaperAttachmentChange(
|
||
index: number,
|
||
uploadFile: { raw?: File }
|
||
) {
|
||
const file = uploadFile.raw
|
||
const row = paperRows.value[index]
|
||
if (!file || !row || row._uploading) return
|
||
row._uploading = true
|
||
try {
|
||
const fd = new FormData()
|
||
fd.append('folder', 'outbound-release-material')
|
||
fd.append('file', file)
|
||
const res = await fetchUploadAttachment(fd)
|
||
row.attachments.push({
|
||
attachmentUrl: res.fileUrl,
|
||
fileName: file.name || res.fileName || attachmentFileName(res.fileUrl),
|
||
fileType: res.fileType || file.type || ''
|
||
})
|
||
} catch {
|
||
ElMessage.error('文件上传失败')
|
||
} finally {
|
||
row._uploading = false
|
||
}
|
||
}
|
||
|
||
defineExpose({
|
||
loading,
|
||
loadFromApiData,
|
||
resetState,
|
||
validateMaterial,
|
||
buildSavePayload,
|
||
remoteSearchMaterials
|
||
})
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
.material-summary {
|
||
margin-bottom: 16px;
|
||
padding: 12px 16px;
|
||
background: #f8fafc;
|
||
border-radius: 8px;
|
||
border: 1px solid #e2e8f0;
|
||
display: grid;
|
||
grid-template-columns: repeat(3, 1fr);
|
||
gap: 8px 20px;
|
||
}
|
||
|
||
.material-summary-row {
|
||
display: flex;
|
||
gap: 8px;
|
||
font-size: 13px;
|
||
}
|
||
|
||
.material-summary-label {
|
||
color: #64748b;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.material-summary-value {
|
||
color: #1e293b;
|
||
font-weight: 500;
|
||
}
|
||
|
||
.material-sections {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 20px;
|
||
}
|
||
|
||
.section-card {
|
||
border: 1px solid #e2e8f0;
|
||
border-radius: 8px;
|
||
padding: 12px 16px 16px;
|
||
background: #fff;
|
||
}
|
||
|
||
.section-head {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
margin-bottom: 12px;
|
||
gap: 12px;
|
||
}
|
||
|
||
.section-title {
|
||
margin: 0;
|
||
font-size: 14px;
|
||
font-weight: 600;
|
||
color: #1e293b;
|
||
}
|
||
|
||
.section-empty-hint {
|
||
margin: 0;
|
||
font-size: 13px;
|
||
color: #94a3b8;
|
||
}
|
||
|
||
.inner-cell-input {
|
||
width: 100%;
|
||
}
|
||
|
||
.paper-att-cards {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 8px;
|
||
|
||
:deep(.el-upload) {
|
||
display: block;
|
||
line-height: normal;
|
||
}
|
||
}
|
||
|
||
.paper-att-card {
|
||
width: 100px;
|
||
height: 72px;
|
||
border: 1px solid #e2e8f0;
|
||
border-radius: 6px;
|
||
background: #f8fafc;
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: stretch;
|
||
justify-content: center;
|
||
padding: 0;
|
||
position: relative;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.paper-att-card__preview {
|
||
flex: 1;
|
||
min-height: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
justify-content: center;
|
||
padding: 6px 4px;
|
||
overflow: hidden;
|
||
|
||
&.is-clickable {
|
||
cursor: pointer;
|
||
}
|
||
|
||
img {
|
||
width: 100%;
|
||
height: 100%;
|
||
object-fit: cover;
|
||
display: block;
|
||
}
|
||
}
|
||
|
||
.paper-att-card--image,
|
||
.paper-att-card--video {
|
||
.paper-att-card__preview {
|
||
padding: 0;
|
||
}
|
||
}
|
||
|
||
.paper-att-card__type-icon {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 22px;
|
||
margin-bottom: 2px;
|
||
|
||
&--doc {
|
||
color: #0284c7;
|
||
}
|
||
|
||
&--video {
|
||
width: 36px;
|
||
height: 36px;
|
||
border-radius: 8px;
|
||
background: #ede9fe;
|
||
color: #7c3aed;
|
||
font-size: 20px;
|
||
margin-bottom: 4px;
|
||
}
|
||
}
|
||
|
||
.paper-att-card__name {
|
||
width: 100%;
|
||
font-size: 11px;
|
||
color: #334155;
|
||
text-align: center;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
line-height: 1.2;
|
||
}
|
||
|
||
.paper-att-card__actions {
|
||
position: absolute;
|
||
top: 2px;
|
||
right: 2px;
|
||
display: flex;
|
||
gap: 2px;
|
||
opacity: 0;
|
||
transition: opacity 0.15s;
|
||
}
|
||
|
||
.paper-att-card:hover .paper-att-card__actions {
|
||
opacity: 1;
|
||
}
|
||
|
||
.paper-att-card__action {
|
||
width: 18px;
|
||
height: 18px;
|
||
border-radius: 3px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 10px;
|
||
color: #fff;
|
||
background: rgba(0, 0, 0, 0.35);
|
||
cursor: pointer;
|
||
|
||
&:hover {
|
||
background: #047857;
|
||
}
|
||
|
||
&--danger:hover {
|
||
background: #ef4444;
|
||
}
|
||
}
|
||
|
||
.paper-att-card--trigger {
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 4px;
|
||
padding: 6px 4px;
|
||
border: 1px dashed #a8d4c4;
|
||
background: transparent;
|
||
cursor: pointer;
|
||
transition: border-color 0.2s, background 0.2s;
|
||
|
||
&:hover {
|
||
border-color: #047857;
|
||
background: #e8f4ee;
|
||
}
|
||
|
||
&.is-loading {
|
||
pointer-events: none;
|
||
opacity: 0.6;
|
||
}
|
||
}
|
||
|
||
.paper-att-card__trigger-icon {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-size: 16px;
|
||
color: #047857;
|
||
margin: 0;
|
||
line-height: 1;
|
||
}
|
||
|
||
.paper-att-card--trigger span {
|
||
font-size: 11px;
|
||
color: #64748b;
|
||
line-height: 1.2;
|
||
text-align: center;
|
||
}
|
||
|
||
.preview-container {
|
||
text-align: center;
|
||
}
|
||
</style>
|