提交
This commit is contained in:
1 parent
dacfdc9ff6
commit
f9676f8759
906 files changed
+533306
-12946
No files matched your search
@@ -0,0 +1,509 @@
|
||||
<template>
|
||||
<div class="attachment-upload">
|
||||
<div class="attachment-list">
|
||||
<el-upload
|
||||
ref="uploadRef"
|
||||
:http-request="handleAttachmentUpload"
|
||||
:show-file-list="false"
|
||||
:before-upload="handleBeforeUpload"
|
||||
:disabled="disabled"
|
||||
multiple
|
||||
:limit="limit"
|
||||
:accept="accept"
|
||||
>
|
||||
<div class="upload-card">
|
||||
<el-icon :size="28" color="#10b981"><Plus /></el-icon>
|
||||
<span class="upload-card-text">上传附件</span>
|
||||
</div>
|
||||
</el-upload>
|
||||
<div
|
||||
v-for="(file, idx) in attachmentList"
|
||||
:key="file.uid || idx"
|
||||
class="attachment-item"
|
||||
:class="{ 'is-uploading': file.status === 'uploading' }"
|
||||
>
|
||||
<div
|
||||
class="attachment-preview"
|
||||
:class="{ 'is-clickable': canPreviewAttachment(file) }"
|
||||
@click.stop="canPreviewAttachment(file) ? handleFilePreview(file) : undefined"
|
||||
>
|
||||
<img
|
||||
v-if="isCrmImageFile(file) && getAttachmentThumbSrc(file)"
|
||||
:src="getAttachmentThumbSrc(file)"
|
||||
:alt="file.name"
|
||||
class="attachment-thumb-img"
|
||||
/>
|
||||
<template v-else-if="file.status === 'uploading'">
|
||||
<el-icon :size="24" color="#94a3b8"><Loading /></el-icon>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="attachment-preview__icon attachment-preview__icon--doc">
|
||||
<el-icon :size="28"><Document /></el-icon>
|
||||
<span v-if="getFileExtension(file.name)" class="attachment-preview__ext">
|
||||
{{ getFileExtension(file.name) }}
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
<div v-if="file.status === 'uploading'" class="attachment-uploading-mask">
|
||||
<el-icon class="is-loading" :size="22"><Loading /></el-icon>
|
||||
</div>
|
||||
</div>
|
||||
<div class="attachment-footer">
|
||||
<span class="attachment-name" :title="file.name">{{ getShortFileName(file.name) }}</span>
|
||||
<div class="attachment-category">
|
||||
<el-select
|
||||
v-model="file.category"
|
||||
placeholder="请选择分类"
|
||||
size="small"
|
||||
style="width: 100%"
|
||||
:disabled="disabled || !getAttachmentOssId(file)"
|
||||
>
|
||||
<el-option label="单章附件" value="single_seal" />
|
||||
<el-option label="双章附件" value="double_seal" />
|
||||
<el-option label="其他附件" value="other" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div v-if="getAttachmentOssId(file) && !disabled" class="attachment-actions">
|
||||
<el-icon class="action-btn" title="预览" @click.stop="handleFilePreview(file)">
|
||||
<ZoomIn />
|
||||
</el-icon>
|
||||
<el-icon class="action-btn" title="下载" @click.stop="handleDownloadAttachment(file)">
|
||||
<Download />
|
||||
</el-icon>
|
||||
<el-icon class="action-btn action-btn--danger" title="删除" @click.stop="handleRemoveAttachmentConfirm(file)">
|
||||
<Delete />
|
||||
</el-icon>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<span v-if="hint" class="upload-hint">{{ hint }}</span>
|
||||
|
||||
<el-dialog
|
||||
v-model="attachmentPreviewVisible"
|
||||
:title="attachmentPreviewFile?.name || '附件预览'"
|
||||
width="860px"
|
||||
align-center
|
||||
destroy-on-close
|
||||
append-to-body
|
||||
modal-class="order-module-dialog-mask"
|
||||
@closed="handleAttachmentPreviewClosed"
|
||||
>
|
||||
<img
|
||||
v-if="attachmentPreviewFile && isCrmImageFile(attachmentPreviewFile) && attachmentPreviewSrc"
|
||||
:src="attachmentPreviewSrc"
|
||||
:alt="attachmentPreviewFile.name"
|
||||
class="attachment-preview-media"
|
||||
/>
|
||||
<iframe
|
||||
v-else-if="attachmentPreviewFile && isCrmPdfFile(attachmentPreviewFile) && attachmentPreviewSrc"
|
||||
:src="attachmentPreviewSrc"
|
||||
class="attachment-preview-media attachment-preview-media--iframe"
|
||||
title="PDF 预览"
|
||||
/>
|
||||
<div v-else class="attachment-preview-fallback">
|
||||
<el-icon :size="40" color="#94a3b8"><Document /></el-icon>
|
||||
<p>该文件类型暂不支持在线预览,请使用下载查看。</p>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { nextTick, ref } from 'vue'
|
||||
import type { UploadInstance, UploadRequestOptions } from 'element-plus'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { Plus, Document, Loading, Download, Delete, ZoomIn } from '@element-plus/icons-vue'
|
||||
import { fetchUploadAttachment } from '@/api/admin'
|
||||
import { $modal } from '@/utils/modal'
|
||||
import {
|
||||
type ContractAttachmentItem,
|
||||
downloadCrmAttachment,
|
||||
isCrmImageFile,
|
||||
isCrmPdfFile,
|
||||
resolveCrmAttachmentUrl
|
||||
} from '@/utils/crm-attachment'
|
||||
import { buildAttachmentUploadFormData, type CrmUploadBizType } from '@/utils/crm-upload'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
bizType: CrmUploadBizType | string
|
||||
limit?: number
|
||||
accept?: string
|
||||
hint?: string
|
||||
disabled?: boolean
|
||||
}>(),
|
||||
{
|
||||
limit: 10,
|
||||
accept: 'image/*,.pdf,.doc,.docx',
|
||||
hint: '支持上传图片、PDF、Word文档等,最多10个文件',
|
||||
disabled: false
|
||||
}
|
||||
)
|
||||
|
||||
const attachmentList = defineModel<ContractAttachmentItem[]>({ default: () => [] })
|
||||
|
||||
const uploadRef = ref<UploadInstance>()
|
||||
const attachmentPreviewVisible = ref(false)
|
||||
const attachmentPreviewFile = ref<ContractAttachmentItem | null>(null)
|
||||
const attachmentPreviewSrc = ref('')
|
||||
|
||||
const getAttachmentOssId = (file: ContractAttachmentItem) => String(file.ossId || file.url || '').trim()
|
||||
|
||||
const getAttachmentThumbSrc = (file: ContractAttachmentItem) => {
|
||||
if (file.localPreview) return file.localPreview
|
||||
const ossId = getAttachmentOssId(file)
|
||||
return ossId ? resolveCrmAttachmentUrl(ossId) : ''
|
||||
}
|
||||
|
||||
const patchAttachmentFile = (uid: string, patch: Partial<ContractAttachmentItem>) => {
|
||||
const idx = attachmentList.value.findIndex((item) => item.uid === uid)
|
||||
if (idx < 0) return
|
||||
const prev = attachmentList.value[idx]
|
||||
if (prev.localPreview && patch.status === 'success') {
|
||||
URL.revokeObjectURL(prev.localPreview)
|
||||
}
|
||||
attachmentList.value[idx] = {
|
||||
...prev,
|
||||
...patch,
|
||||
localPreview: patch.status === 'success' ? undefined : prev.localPreview
|
||||
}
|
||||
}
|
||||
|
||||
const canPreviewAttachment = (file: ContractAttachmentItem) =>
|
||||
Boolean(file.localPreview || getAttachmentOssId(file))
|
||||
|
||||
const resolveAttachmentPreviewSrc = (file: ContractAttachmentItem) => {
|
||||
if (file.localPreview) return file.localPreview
|
||||
const ossId = getAttachmentOssId(file)
|
||||
if (!ossId) return ''
|
||||
if (isCrmImageFile(file) || isCrmPdfFile(file)) {
|
||||
return resolveCrmAttachmentUrl(ossId)
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
const handleAttachmentPreviewClosed = () => {
|
||||
attachmentPreviewFile.value = null
|
||||
attachmentPreviewSrc.value = ''
|
||||
}
|
||||
|
||||
const getFileExtension = (fileName: string) => {
|
||||
if (!fileName) return ''
|
||||
const lastDotIndex = fileName.lastIndexOf('.')
|
||||
if (lastDotIndex === -1) return ''
|
||||
return fileName.substring(lastDotIndex + 1).toUpperCase()
|
||||
}
|
||||
|
||||
const getShortFileName = (fileName: string) => {
|
||||
if (!fileName) return ''
|
||||
const lastDotIndex = fileName.lastIndexOf('.')
|
||||
if (lastDotIndex === -1) return fileName.length > 12 ? fileName.substring(0, 12) + '...' : fileName
|
||||
const name = fileName.substring(0, lastDotIndex)
|
||||
const ext = fileName.substring(lastDotIndex)
|
||||
if (name.length <= 8) return fileName
|
||||
return name.substring(0, 8) + '...' + ext
|
||||
}
|
||||
|
||||
const handleBeforeUpload = (file: File) => {
|
||||
const isValidType = /\.(jpg|jpeg|png|gif|bmp|webp|pdf|doc|docx|txt|mp4|avi|mov)$/i.test(file.name)
|
||||
if (!isValidType) {
|
||||
$modal.msgError('上传文件格式不正确!')
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
const handleAttachmentUpload = async (options: UploadRequestOptions) => {
|
||||
if (attachmentList.value.length >= props.limit) {
|
||||
ElMessage.warning(`最多上传 ${props.limit} 个附件`)
|
||||
options.onError?.(new Error('超出数量限制'))
|
||||
return
|
||||
}
|
||||
|
||||
const uid = `upload-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`
|
||||
const localPreview = isCrmImageFile({ name: options.file.name })
|
||||
? URL.createObjectURL(options.file)
|
||||
: undefined
|
||||
attachmentList.value.push({
|
||||
uid,
|
||||
name: options.file.name,
|
||||
status: 'uploading',
|
||||
category: 'other',
|
||||
localPreview
|
||||
})
|
||||
|
||||
const formData = buildAttachmentUploadFormData(options.file, { bizType: props.bizType })
|
||||
|
||||
try {
|
||||
const res = await fetchUploadAttachment(formData)
|
||||
const fileUrl = String(res?.fileUrl || (res as { url?: string })?.url || '').trim()
|
||||
if (!fileUrl) {
|
||||
throw new Error('上传失败')
|
||||
}
|
||||
patchAttachmentFile(uid, {
|
||||
ossId: fileUrl,
|
||||
url: fileUrl,
|
||||
name: res?.fileName || options.file.name,
|
||||
status: 'success'
|
||||
})
|
||||
options.onSuccess?.(res)
|
||||
$modal.msgSuccess('文件上传成功')
|
||||
} catch (error: any) {
|
||||
const failed = attachmentList.value.find((item) => item.uid === uid)
|
||||
if (failed?.localPreview) {
|
||||
URL.revokeObjectURL(failed.localPreview)
|
||||
}
|
||||
attachmentList.value = attachmentList.value.filter((item) => item.uid !== uid)
|
||||
$modal.msgError(error?.message || '文件上传失败')
|
||||
options.onError?.(error)
|
||||
} finally {
|
||||
await nextTick()
|
||||
uploadRef.value?.clearFiles()
|
||||
}
|
||||
}
|
||||
|
||||
const handleFilePreview = (file: ContractAttachmentItem) => {
|
||||
if (!canPreviewAttachment(file)) {
|
||||
$modal.msgWarning('文件尚未上传完成')
|
||||
return
|
||||
}
|
||||
attachmentPreviewFile.value = file
|
||||
attachmentPreviewSrc.value = resolveAttachmentPreviewSrc(file)
|
||||
attachmentPreviewVisible.value = true
|
||||
}
|
||||
|
||||
const handleRemoveAttachmentConfirm = (file: ContractAttachmentItem) => {
|
||||
$modal
|
||||
.confirm('确定要删除这个文件吗?')
|
||||
.then(() => {
|
||||
const index = attachmentList.value.findIndex((item) => item.uid === file.uid)
|
||||
if (index > -1) {
|
||||
const removed = attachmentList.value[index]
|
||||
if (removed?.localPreview) {
|
||||
URL.revokeObjectURL(removed.localPreview)
|
||||
}
|
||||
attachmentList.value.splice(index, 1)
|
||||
$modal.msgSuccess('文件删除成功')
|
||||
}
|
||||
})
|
||||
.catch(() => {})
|
||||
}
|
||||
|
||||
const handleDownloadAttachment = async (file: ContractAttachmentItem) => {
|
||||
if (!getAttachmentOssId(file)) {
|
||||
$modal.msgError('无法获取文件下载地址')
|
||||
return
|
||||
}
|
||||
try {
|
||||
await downloadCrmAttachment(file)
|
||||
} catch (error) {
|
||||
console.error('下载文件失败:', error)
|
||||
$modal.msgError('下载文件失败,请稍后重试')
|
||||
}
|
||||
}
|
||||
|
||||
const hasUploading = () => attachmentList.value.some((item) => item.status === 'uploading')
|
||||
|
||||
defineExpose({ hasUploading })
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.attachment-upload {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.attachment-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.upload-card {
|
||||
width: 140px;
|
||||
height: 96px;
|
||||
border: 1px dashed #a7f3d0;
|
||||
border-radius: 8px;
|
||||
background: #f0fdf4;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 6px;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
border-color: #10b981;
|
||||
border-style: solid;
|
||||
background: #ecfdf5;
|
||||
}
|
||||
}
|
||||
|
||||
.upload-card-text {
|
||||
font-size: 12px;
|
||||
color: #10b981;
|
||||
font-weight: 500;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.upload-hint {
|
||||
display: block;
|
||||
font-size: 11px;
|
||||
color: #94a3b8;
|
||||
margin-top: 8px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.attachment-item {
|
||||
width: 148px;
|
||||
min-height: 200px;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 8px;
|
||||
background: #fff;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
&.is-uploading {
|
||||
opacity: 0.85;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
border-color: #10b981;
|
||||
box-shadow: 0 2px 8px rgba(16, 185, 129, 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
.attachment-preview {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 110px;
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #f8fafc;
|
||||
overflow: hidden;
|
||||
|
||||
&.is-clickable {
|
||||
cursor: zoom-in;
|
||||
}
|
||||
}
|
||||
|
||||
.attachment-thumb-img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.attachment-uploading-mask {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(255, 255, 255, 0.72);
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.attachment-preview__ext {
|
||||
margin-top: 4px;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.attachment-preview__icon {
|
||||
width: 48px;
|
||||
min-height: 48px;
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
&--doc {
|
||||
background: #e0f2fe;
|
||||
color: #0284c7;
|
||||
}
|
||||
}
|
||||
|
||||
.attachment-footer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 6px 8px;
|
||||
}
|
||||
|
||||
.attachment-name {
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
font-size: 11px;
|
||||
color: #334155;
|
||||
line-height: 1.4;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.attachment-category {
|
||||
margin-top: 6px;
|
||||
|
||||
:deep(.el-select) {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.attachment-actions {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
border-radius: 4px;
|
||||
background: #f1f5f9;
|
||||
color: #64748b;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
background: #10b981;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
&--danger:hover {
|
||||
background: #ef4444;
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
|
||||
.attachment-preview-media {
|
||||
display: block;
|
||||
width: 100%;
|
||||
max-height: 70vh;
|
||||
object-fit: contain;
|
||||
margin: 0 auto;
|
||||
border-radius: 8px;
|
||||
background: #f8fafc;
|
||||
}
|
||||
|
||||
.attachment-preview-media--iframe {
|
||||
height: 70vh;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.attachment-preview-fallback {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
min-height: 240px;
|
||||
color: #64748b;
|
||||
font-size: 14px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,337 @@
|
||||
<template>
|
||||
<SystemViewDialog
|
||||
v-model:visible="visible"
|
||||
:title="contractInfo.contractName || '合同详情'"
|
||||
:icon="Document"
|
||||
width="calc(100vw - 100px)"
|
||||
:code="contractInfo.contractNo"
|
||||
code-label="合同编号"
|
||||
:meta="viewHeroMeta"
|
||||
:sections="viewSections"
|
||||
:loading="loading"
|
||||
:grid-columns="2"
|
||||
dialog-class="contract-view-dialog"
|
||||
modal-class="order-module-dialog-mask"
|
||||
append-to-body
|
||||
>
|
||||
<template #products>
|
||||
<div class="panel dialog-list-panel">
|
||||
<div class="list-body list-wrap dialog-list-body-only">
|
||||
<el-table
|
||||
:data="contractInfo.products || []"
|
||||
class="list-table"
|
||||
stripe
|
||||
empty-text="暂无产品明细"
|
||||
>
|
||||
<el-table-column type="index" label="序号" min-width="60" align="center" header-align="center" />
|
||||
<el-table-column label="产品名称" prop="productName" min-width="140" align="center" header-align="center" show-overflow-tooltip />
|
||||
<el-table-column label="型号/规格" prop="productModel" min-width="120" align="center" header-align="center" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ row.productModel || row.model || '—' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="单位" prop="unit" min-width="80" align="center" header-align="center">
|
||||
<template #default="{ row }">
|
||||
<el-tag
|
||||
v-if="row.unit"
|
||||
:type="dictStore.getTagType('crm_product_unit', row.unit)"
|
||||
size="small"
|
||||
>
|
||||
{{ dictStore.getLabel('crm_product_unit', row.unit) }}
|
||||
</el-tag>
|
||||
<span v-else>—</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="数量" prop="quantity" min-width="90" align="right" header-align="right" />
|
||||
<el-table-column label="单价" min-width="110" align="right" header-align="right">
|
||||
<template #default="{ row }">¥{{ formatAmount(row.price) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="小计" min-width="110" align="right" header-align="right">
|
||||
<template #default="{ row }">¥{{ formatAmount(row.subtotal) }}</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #attachments>
|
||||
<AttachmentUploadField
|
||||
v-if="attachmentValue"
|
||||
:model-value="attachmentValue"
|
||||
disabled
|
||||
/>
|
||||
<p v-else class="view-empty-hint">暂无附件</p>
|
||||
</template>
|
||||
|
||||
<template #approval>
|
||||
<div v-if="approvalList.length" class="contract-approval-flow-scroll">
|
||||
<el-timeline>
|
||||
<el-timeline-item
|
||||
v-for="item in approvalList"
|
||||
:key="item.id"
|
||||
:timestamp="item.approvalTime || '—'"
|
||||
placement="top"
|
||||
>
|
||||
<div class="contract-approval-card">
|
||||
<div class="contract-approval-card-head">
|
||||
<span class="contract-approval-card-user">{{ item.approverName || '—' }}</span>
|
||||
<el-tag
|
||||
v-if="item.approvalResult === 'approved'"
|
||||
type="success"
|
||||
size="small"
|
||||
>已通过</el-tag>
|
||||
<el-tag
|
||||
v-else-if="item.approvalResult === 'rejected'"
|
||||
type="danger"
|
||||
size="small"
|
||||
>已拒绝</el-tag>
|
||||
<el-tag
|
||||
v-else-if="item.approvalResult === 'pending'"
|
||||
type="info"
|
||||
size="small"
|
||||
>待审批</el-tag>
|
||||
</div>
|
||||
<p v-if="item.approvalOpinion" class="contract-approval-opinion">
|
||||
{{ item.approvalOpinion }}
|
||||
</p>
|
||||
</div>
|
||||
</el-timeline-item>
|
||||
</el-timeline>
|
||||
</div>
|
||||
<p v-else class="view-empty-hint">暂无审批记录</p>
|
||||
</template>
|
||||
</SystemViewDialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import { Document } from '@element-plus/icons-vue'
|
||||
import SystemViewDialog, {
|
||||
type ViewField,
|
||||
type ViewSection
|
||||
} from '@/components/business/system-view-dialog/index.vue'
|
||||
import AttachmentUploadField from '@/components/business/attachment-upload-field/index.vue'
|
||||
import { useDictStore } from '@/store/modules/dict'
|
||||
import { getContract, listContractApproval } from '@/api/crm/contract'
|
||||
import { getOpportunity } from '@/api/crm/opportunity'
|
||||
import { getQuote } from '@/api/crm/quote'
|
||||
import type { ContractApprovalVO, ContractVO } from '@/api/crm/contract/types'
|
||||
|
||||
const dictStore = useDictStore()
|
||||
|
||||
const visible = ref(false)
|
||||
const loading = ref(false)
|
||||
const contractInfo = ref<ContractVO>({} as ContractVO)
|
||||
const approvalList = ref<ContractApprovalVO[]>([])
|
||||
|
||||
function formatAmount(amount?: number | string | null) {
|
||||
if (amount == null || amount === '') return '0.00'
|
||||
const num = typeof amount === 'string' ? parseFloat(amount) : amount
|
||||
if (Number.isNaN(num)) return '0.00'
|
||||
return num.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
||||
}
|
||||
|
||||
function tagField(
|
||||
label: string,
|
||||
dictType: string,
|
||||
value?: string | null,
|
||||
extra?: Partial<ViewField>
|
||||
): ViewField {
|
||||
return {
|
||||
label,
|
||||
value: value ? dictStore.getLabel(dictType, value) : '—',
|
||||
tagType: value ? dictStore.getTagType(dictType, value) : undefined,
|
||||
...extra
|
||||
}
|
||||
}
|
||||
|
||||
const attachmentValue = computed(() => {
|
||||
const c = contractInfo.value
|
||||
const parts = [c.contractFile, c.attachmentFiles].filter(Boolean)
|
||||
return parts.join(',')
|
||||
})
|
||||
|
||||
const viewHeroMeta = computed(() => {
|
||||
const c = contractInfo.value
|
||||
const parts: string[] = []
|
||||
if (c.customerName) parts.push(c.customerName)
|
||||
if (c.status) parts.push(dictStore.getLabel('crm_contract_status', c.status))
|
||||
if (c.signDate) parts.push(`签订 ${c.signDate}`)
|
||||
return parts.join(' · ')
|
||||
})
|
||||
|
||||
const viewSections = computed<ViewSection[]>(() => {
|
||||
const c = contractInfo.value
|
||||
if (!c?.id) return []
|
||||
|
||||
const basicFields: ViewField[] = [
|
||||
tagField('合同类型', 'crm_contract_type', c.contractType),
|
||||
tagField('合同模版', 'crm_contract_template', c.contractTemplate),
|
||||
{ label: '客户名称', value: c.customerName },
|
||||
{ label: '关联商机', value: c.opportunityName || '—' },
|
||||
{ label: '关联报价单', value: c.quoteNo || '—' },
|
||||
{ label: '联系人', value: c.contactName },
|
||||
{ label: '联系电话', value: c.contactMobile },
|
||||
{ label: '签订日期', value: c.signDate },
|
||||
{ label: '合同期限', value: c.startDate && c.endDate ? `${c.startDate} ~ ${c.endDate}` : '—' },
|
||||
{ label: '负责人', value: c.ownerUserName },
|
||||
tagField('合同状态', 'crm_contract_status', c.status),
|
||||
tagField('审批状态', 'crm_approval_status', c.approvalStatus)
|
||||
]
|
||||
|
||||
const amountFields: ViewField[] = [
|
||||
{ label: '合同金额', value: `¥${formatAmount(c.amount)}`, money: true },
|
||||
{ label: '已回款金额', value: `¥${formatAmount(c.receivedAmount)}`, money: true },
|
||||
{ label: '未回款金额', value: `¥${formatAmount(c.unreceivedAmount)}`, money: true },
|
||||
{ label: '已开票金额', value: `¥${formatAmount(c.invoiceAmount)}`, money: true }
|
||||
]
|
||||
|
||||
const partyFields: ViewField[] = [
|
||||
{ label: '甲方', value: c.partyA },
|
||||
{ label: '甲方联系人', value: c.partyAContact },
|
||||
{ label: '甲方电话', value: c.partyAMobile },
|
||||
{ label: '乙方', value: c.partyB },
|
||||
{ label: '乙方联系人', value: c.partyBContact },
|
||||
{ label: '乙方电话', value: c.partyBMobile },
|
||||
tagField('结算方式', 'crm_settlement_method', c.settlementMethod)
|
||||
]
|
||||
|
||||
const sections: ViewSection[] = [
|
||||
{ title: '基本信息', fields: basicFields },
|
||||
{ title: '金额信息', fields: amountFields },
|
||||
{ title: '签约主体', fields: partyFields },
|
||||
{
|
||||
title: '产品明细',
|
||||
fields: [],
|
||||
slot: 'products'
|
||||
},
|
||||
{
|
||||
title: '合同附件',
|
||||
fields: [],
|
||||
slot: 'attachments'
|
||||
},
|
||||
{
|
||||
title: '审批记录',
|
||||
fields: [],
|
||||
slot: 'approval'
|
||||
}
|
||||
]
|
||||
|
||||
if (c.paymentTerms) {
|
||||
sections.push({
|
||||
title: '付款条款',
|
||||
fields: [{ label: '付款条款', value: c.paymentTerms, span: true }]
|
||||
})
|
||||
}
|
||||
|
||||
if (c.deliveryTerms) {
|
||||
sections.push({
|
||||
title: '交付条款',
|
||||
fields: [{ label: '交付条款', value: c.deliveryTerms, span: true }]
|
||||
})
|
||||
}
|
||||
|
||||
if (c.remark) {
|
||||
sections.push({
|
||||
title: '备注',
|
||||
fields: [{ label: '备注', value: c.remark, span: true }]
|
||||
})
|
||||
}
|
||||
|
||||
return sections
|
||||
})
|
||||
|
||||
async function loadDetail(id: string | number) {
|
||||
loading.value = true
|
||||
try {
|
||||
await dictStore.loadAllDict()
|
||||
const res = await getContract(id)
|
||||
contractInfo.value = (res as any)?.data || res || ({} as ContractVO)
|
||||
|
||||
if (contractInfo.value?.opportunityId) {
|
||||
try {
|
||||
const oppRes = await getOpportunity(contractInfo.value.opportunityId)
|
||||
if (oppRes?.data) {
|
||||
contractInfo.value.opportunityName = oppRes.data.opportunityName
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
if (contractInfo.value?.quoteId) {
|
||||
try {
|
||||
const quoteRes = await getQuote(contractInfo.value.quoteId)
|
||||
if (quoteRes?.data) {
|
||||
contractInfo.value.quoteNo = quoteRes.data.quoteNo
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const approvalRes = await listContractApproval(id)
|
||||
approvalList.value = (approvalRes as any)?.data || approvalRes || []
|
||||
} catch {
|
||||
approvalList.value = []
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
contractInfo.value = {} as ContractVO
|
||||
approvalList.value = []
|
||||
ElMessage.error('加载合同详情失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function open(id: string | number) {
|
||||
visible.value = true
|
||||
contractInfo.value = {} as ContractVO
|
||||
approvalList.value = []
|
||||
await loadDetail(id)
|
||||
}
|
||||
|
||||
defineExpose({ open })
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.contract-approval-flow-scroll {
|
||||
max-height: 420px;
|
||||
overflow-y: auto;
|
||||
padding-right: 4px;
|
||||
}
|
||||
|
||||
.contract-approval-card {
|
||||
padding: 12px 14px;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 8px;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.contract-approval-card-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.contract-approval-card-user {
|
||||
font-weight: 600;
|
||||
color: #1e293b;
|
||||
}
|
||||
|
||||
.contract-approval-opinion {
|
||||
margin: 8px 0 0;
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
color: #64748b;
|
||||
}
|
||||
</style>
|
||||
|
||||
<style lang="scss">
|
||||
.contract-view-dialog.system-view-dialog {
|
||||
&.el-dialog {
|
||||
max-width: calc(100vw - 100px);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,5 +1,14 @@
|
||||
<template>
|
||||
<el-dialog title="选择产品" v-model="dialogVisible" width="80%" :close-on-click-modal="false" append-to-body>
|
||||
<el-dialog
|
||||
title="选择产品"
|
||||
v-model="dialogVisible"
|
||||
width="80%"
|
||||
align-center
|
||||
append-to-body
|
||||
class="dialog-form-layout"
|
||||
modal-class="order-module-dialog-mask"
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<!-- 查询表单 -->
|
||||
<el-form :model="queryParams" ref="queryFormRef" label-width="90px" class="mb-3">
|
||||
<el-row :gutter="20">
|
||||
@@ -24,64 +33,76 @@
|
||||
<el-col :xl="4" :lg="6" :md="8" :sm="12" :xs="24">
|
||||
<el-form-item label="产品状态" prop="status">
|
||||
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable style="width: 100%">
|
||||
<el-option label="在售" value="on" />
|
||||
<el-option label="下架" value="off" />
|
||||
<el-option
|
||||
v-for="opt in dictStore.getOptions('crm_product_status')"
|
||||
:key="opt.value"
|
||||
:label="opt.label"
|
||||
:value="opt.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="24" style="text-align: right">
|
||||
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
|
||||
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
|
||||
<el-button type="primary" :loading="loading" @click="handleQuery">
|
||||
<el-icon><Search /></el-icon>搜索
|
||||
</el-button>
|
||||
<el-button :loading="loading" @click="resetQuery">
|
||||
<el-icon><Refresh /></el-icon>重置
|
||||
</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form>
|
||||
|
||||
<!-- 产品列表 -->
|
||||
<el-table
|
||||
ref="tableRef"
|
||||
v-loading="loading"
|
||||
:data="productList"
|
||||
@selection-change="handleSelectionChange"
|
||||
@row-dblclick="handleRowDblClick"
|
||||
:max-height="400"
|
||||
border
|
||||
>
|
||||
<el-table-column type="selection" width="55" align="center" />
|
||||
<el-table-column type="index" label="序号" width="60" align="center" />
|
||||
<el-table-column label="产品编号" prop="productNo" width="140" align="center" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="产品名称" prop="productName" min-width="180" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="产品分类" prop="categoryName" width="120" />
|
||||
<el-table-column label="规格型号" prop="model" width="120" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="计量单位" prop="unit" width="100" align="center">
|
||||
<template #default="scope">
|
||||
<DictTag dict-type="crm_product_unit" :value="scope.row.unit" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="税率(%)" prop="taxRate" width="90" align="center">
|
||||
<template #default="scope">
|
||||
<span>{{ scope.row.taxRate || 0 }}%</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" prop="status" width="90" align="center">
|
||||
<template #default="scope">
|
||||
<el-tag :type="scope.row.status === 'on' ? 'success' : 'info'">
|
||||
{{ scope.row.status === 'on' ? '在售' : '下架' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="panel dialog-list-panel">
|
||||
<div class="list-body list-wrap dialog-list-body-only">
|
||||
<el-table
|
||||
ref="tableRef"
|
||||
v-loading="loading"
|
||||
:data="productList"
|
||||
class="list-table"
|
||||
stripe
|
||||
@selection-change="handleSelectionChange"
|
||||
@row-click="handleRowClick"
|
||||
:max-height="400"
|
||||
>
|
||||
<el-table-column type="selection" min-width="55" align="center" header-align="center" />
|
||||
<el-table-column type="index" label="序号" min-width="60" align="center" header-align="center" />
|
||||
<el-table-column label="产品编号" prop="productNo" min-width="140" align="center" header-align="center" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="产品名称" prop="productName" min-width="180" align="center" header-align="center" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="产品分类" prop="categoryName" min-width="120" align="center" header-align="center" />
|
||||
<el-table-column label="规格型号" prop="model" min-width="120" align="center" header-align="center" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="计量单位" prop="unit" min-width="100" align="center" header-align="center">
|
||||
<template #default="scope">
|
||||
<DictTag dict-type="crm_product_unit" :value="scope.row.unit" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="税率(%)" prop="taxRate" min-width="90" align="center" header-align="center">
|
||||
<template #default="scope">
|
||||
<span>{{ scope.row.taxRate || 0 }}%</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" prop="status" min-width="90" align="center" header-align="center">
|
||||
<template #default="scope">
|
||||
<el-tag :type="dictStore.getTagType('crm_product_status', scope.row.status)" size="small">
|
||||
{{ dictStore.getLabel('crm_product_status', scope.row.status) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<!-- 分页 -->
|
||||
<pagination
|
||||
v-show="total > 0"
|
||||
:total="total"
|
||||
v-model:page="queryParams.pageNum"
|
||||
v-model:limit="queryParams.pageSize"
|
||||
@pagination="getList"
|
||||
class="mt-3"
|
||||
/>
|
||||
<pagination
|
||||
v-show="total > 0"
|
||||
:total="total"
|
||||
v-model:page="queryParams.pageNum"
|
||||
v-model:limit="queryParams.pageSize"
|
||||
@pagination="getList"
|
||||
class="pagination list-pager-bar"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 已选产品 -->
|
||||
<el-divider content-position="left">已选产品 ({{ selectedProducts.length }})</el-divider>
|
||||
@@ -94,8 +115,12 @@
|
||||
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="handleClose">取 消</el-button>
|
||||
<el-button type="primary" @click="handleConfirm" :disabled="selectedProducts.length === 0"> 确定 ({{ selectedProducts.length }}) </el-button>
|
||||
<el-button class="btn-ghost" @click="handleClose">
|
||||
<el-icon><Close /></el-icon>取消
|
||||
</el-button>
|
||||
<el-button class="btn-main" type="primary" @click="handleConfirm" :disabled="selectedProducts.length === 0">
|
||||
<el-icon><Check /></el-icon>确定 ({{ selectedProducts.length }})
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
@@ -104,13 +129,18 @@
|
||||
<script setup lang="ts" name="ProductSelector">
|
||||
import { ref, watch } from 'vue'
|
||||
import type { ElFormInstance } from 'element-plus'
|
||||
import { Check, Close, Refresh, Search } from '@element-plus/icons-vue'
|
||||
import { fetchProductList, fetchCategoryTree } from '@/api/crm/product'
|
||||
import DictTag from '@/components/DictTag/index.vue'
|
||||
import { useDictStore } from '@/store/modules/dict'
|
||||
|
||||
const dictStore = useDictStore()
|
||||
|
||||
interface ProductVO {
|
||||
id: string | number
|
||||
productNo?: string
|
||||
productName?: string
|
||||
categoryId?: string | number
|
||||
categoryName?: string
|
||||
model?: string
|
||||
unit?: string
|
||||
@@ -192,6 +222,10 @@ const getList = async () => {
|
||||
const data = (res as any)?.data || res || {};
|
||||
productList.value = data.list || data.rows || [];
|
||||
total.value = data.total ?? 0;
|
||||
// 如果分类树已加载,立即补全 categoryName
|
||||
if (categoryTree.value.length > 0) {
|
||||
resolveCategoryNames()
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取产品列表失败:', error);
|
||||
} finally {
|
||||
@@ -205,6 +239,8 @@ const loadCategoryTree = async () => {
|
||||
const res = await fetchCategoryTree();
|
||||
const tree = (res as any)?.data || res || [];
|
||||
categoryTree.value = convertTreeData(tree);
|
||||
// 分类树加载后,补全已有产品的 categoryName
|
||||
resolveCategoryNames()
|
||||
} catch (error) {
|
||||
console.error('获取产品分类失败:', error);
|
||||
}
|
||||
@@ -219,6 +255,29 @@ const convertTreeData = (data: ProductCategoryVO[]): any[] => {
|
||||
}));
|
||||
};
|
||||
|
||||
/** 从分类树中解析分类名称 */
|
||||
const resolveCategoryName = (categoryId: any, tree: any[]): string => {
|
||||
for (const node of tree) {
|
||||
if (node.value === categoryId || node.id === categoryId) return node.label || ''
|
||||
if (node.children) {
|
||||
const found = resolveCategoryName(categoryId, node.children)
|
||||
if (found) return found
|
||||
}
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
/** 补全产品列表中缺失的 categoryName */
|
||||
const resolveCategoryNames = () => {
|
||||
if (!categoryTree.value.length) return
|
||||
productList.value.forEach((product) => {
|
||||
if (!product.categoryName && product.categoryId != null) {
|
||||
const catId = (product as any).categoryId
|
||||
product.categoryName = resolveCategoryName(catId, categoryTree.value)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/** 搜索按钮操作 */
|
||||
const handleQuery = () => {
|
||||
queryParams.value.pageNum = 1;
|
||||
@@ -231,16 +290,30 @@ const resetQuery = () => {
|
||||
handleQuery();
|
||||
};
|
||||
|
||||
watchDebounced(
|
||||
() => ({
|
||||
productName: queryParams.value.productName,
|
||||
categoryId: queryParams.value.categoryId,
|
||||
status: queryParams.value.status,
|
||||
}),
|
||||
() => {
|
||||
queryParams.value.pageNum = 1;
|
||||
getList();
|
||||
},
|
||||
{ debounce: 300, deep: true }
|
||||
);
|
||||
|
||||
/** 多选框选中数据 */
|
||||
const handleSelectionChange = (selection: ProductVO[]) => {
|
||||
selectedProducts.value = selection;
|
||||
};
|
||||
|
||||
/** 双击行选中/取消选中产品 */
|
||||
const handleRowDblClick = (row: ProductVO) => {
|
||||
// 切换行的选中状态
|
||||
tableRef.value?.toggleRowSelection(row);
|
||||
};
|
||||
/** 单击行选中/取消选中产品(点击复选框列时不重复切换) */
|
||||
const handleRowClick = (row: ProductVO, _column: unknown, event: MouseEvent) => {
|
||||
const target = event.target as HTMLElement
|
||||
if (target.closest('.el-checkbox')) return
|
||||
tableRef.value?.toggleRowSelection(row)
|
||||
}
|
||||
|
||||
/** 移除已选产品 */
|
||||
const handleRemoveSelection = (product: ProductVO) => {
|
||||
|
||||
@@ -6,94 +6,22 @@
|
||||
align-center
|
||||
append-to-body
|
||||
destroy-on-close
|
||||
class="dialog-form-layout"
|
||||
class="dialog-form-layout upload-scan-dialog"
|
||||
modal-class="order-module-dialog-mask"
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<div class="attachment-upload-container">
|
||||
<el-upload
|
||||
ref="uploadRef"
|
||||
:file-list="attachmentList"
|
||||
class="upload-demo"
|
||||
drag
|
||||
list-type="picture-card"
|
||||
:on-preview="handleFilePreview"
|
||||
:action="uploadAction"
|
||||
:headers="uploadHeaders"
|
||||
:data="uploadData"
|
||||
:auto-upload="true"
|
||||
:before-upload="handleBeforeUpload"
|
||||
:on-success="handleUploadSuccess"
|
||||
:on-error="handleUploadError"
|
||||
:on-remove="handleRemoveAttachmentConfirm"
|
||||
:on-change="handleFileChange"
|
||||
multiple
|
||||
:limit="10"
|
||||
:show-file-list="true"
|
||||
accept="image/*,.pdf,.doc,.docx"
|
||||
>
|
||||
<template #tip>
|
||||
<div class="el-upload__tip">支持图片、PDF、Word文档等格式,最多上传10个文件。</div>
|
||||
</template>
|
||||
<ContractAttachmentPanel
|
||||
v-model="attachmentList"
|
||||
:biz-type="CRM_UPLOAD_BIZ_TYPE.CONTRACT_ATTACHMENT"
|
||||
hint="支持上传图片、PDF、Word文档等,最多10个文件"
|
||||
/>
|
||||
|
||||
<!-- 调整拖拽上传图标与文字在同一行、居中对齐 -->
|
||||
<div class="el-upload-dragger1">
|
||||
<el-icon class="el-icon--upload"><UploadFilled /></el-icon>
|
||||
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
|
||||
</div>
|
||||
|
||||
<!-- 自定义文件卡片缩略图(含文件名) -->
|
||||
<template #file="{ file }">
|
||||
<div class="upload-file-card">
|
||||
<!-- 缩略图区域 -->
|
||||
<div class="upload-file-thumb">
|
||||
<ImagePreview v-if="isImageFile(file) && getFileOssId(file)" :src="getFileOssId(file)" class="upload-thumb-image" :isOssId="true" />
|
||||
<div v-else class="upload-file-placeholder">
|
||||
<el-icon><Document /></el-icon>
|
||||
<span class="file-ext">{{ getFileExt(file.name) }}</span>
|
||||
</div>
|
||||
<!-- loading 遮罩只在上传中显示 -->
|
||||
<div v-if="file.status === 'uploading'" class="upload-file-loading">
|
||||
<el-icon class="is-loading"><Loading /></el-icon>
|
||||
<span class="loading-text">上传中...</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 文件名称 -->
|
||||
<div class="upload-file-name" :title="file.name">
|
||||
{{ getShortFileName(file.name) }}
|
||||
</div>
|
||||
|
||||
<!-- 附件分类选择 -->
|
||||
<div class="upload-file-category" v-if="file.status && file.status !== 'ready'">
|
||||
<el-select v-model="file.category" placeholder="选择附件分类" size="small" style="width: 100%" @change="handleCategoryChange(file)">
|
||||
<el-option label="单章附件" value="single_seal" />
|
||||
<el-option label="双章附件" value="double_seal" />
|
||||
<el-option label="其他附件" value="other" />
|
||||
</el-select>
|
||||
</div>
|
||||
|
||||
<!-- 操作按钮区域 - 固定在文件名下方 -->
|
||||
<div class="upload-file-card-actions" v-if="file.status && file.status !== 'ready'">
|
||||
<el-button-group size="small">
|
||||
<el-button type="success" @click.stop="handleDownloadAttachment(file)" title="下载" :disabled="file.status !== 'success'">
|
||||
<el-icon><Download /></el-icon>
|
||||
</el-button>
|
||||
<el-button type="danger" @click.stop="handleRemoveAttachmentConfirm(file)" title="删除">
|
||||
<el-icon><Delete /></el-icon>
|
||||
</el-button>
|
||||
</el-button-group>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</el-upload>
|
||||
</div>
|
||||
<template #footer>
|
||||
<div class="upload-dialog-actions">
|
||||
<el-button @click="handleClose">
|
||||
<el-icon><Close /></el-icon>关闭
|
||||
</el-button>
|
||||
<el-button type="primary" @click="handleSaveAndClose">
|
||||
<el-button type="primary" :loading="saveLoading" @click="handleSaveAndClose">
|
||||
<el-icon><Check /></el-icon>保存并关闭
|
||||
</el-button>
|
||||
</div>
|
||||
@@ -102,480 +30,95 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="UploadDialog">
|
||||
import { ref, computed } from 'vue'
|
||||
import { UploadFilled, Document, Loading, Download, Delete, Close, Check } from '@element-plus/icons-vue'
|
||||
import ImagePreview from '@/components/ImagePreview/index.vue'
|
||||
import { ref } from 'vue'
|
||||
import { Close, Check } from '@element-plus/icons-vue'
|
||||
import ContractAttachmentPanel from './ContractAttachmentPanel.vue'
|
||||
import { uploadAttachments, getContract } from '@/api/crm/contract'
|
||||
import { $modal } from '@/utils/modal'
|
||||
import { useUserStore } from '@/store/modules/user'
|
||||
import {
|
||||
buildUploadFileListFromField,
|
||||
downloadCrmAttachment
|
||||
mapContractAttachmentsPayload,
|
||||
type ContractAttachmentItem
|
||||
} from '@/utils/crm-attachment'
|
||||
import { CRM_UPLOAD_BIZ_TYPE } from '@/utils/crm-upload'
|
||||
|
||||
const userStore = useUserStore()
|
||||
const emit = defineEmits(['success'])
|
||||
|
||||
// 定义事件
|
||||
const emit = defineEmits(['success']);
|
||||
const dialogVisible = ref(false)
|
||||
const contractId = ref<number>()
|
||||
const attachmentList = ref<ContractAttachmentItem[]>([])
|
||||
const saveLoading = ref(false)
|
||||
|
||||
// 对话框显示状态
|
||||
const dialogVisible = ref(false);
|
||||
|
||||
// 合同ID
|
||||
const contractId = ref<number>();
|
||||
|
||||
// 文件列表
|
||||
const attachmentList = ref<any[]>([]);
|
||||
|
||||
// 已上传成功的附件列表(包含ossId和category)
|
||||
const uploadedAttachments = ref<Array<{ ossId: string; category: string }>>([]);
|
||||
|
||||
// 上传地址
|
||||
const uploadAction = computed(() => '/web/admin/attachment/upload');
|
||||
|
||||
// 上传请求头
|
||||
const uploadHeaders = computed(() => ({
|
||||
Authorization: `Bearer ${userStore.accessToken || ''}`
|
||||
}));
|
||||
|
||||
// 上传额外数据
|
||||
const uploadData = computed(() => {
|
||||
return {
|
||||
bizType: 'crm_contract_file'
|
||||
};
|
||||
});
|
||||
|
||||
const uploadRef = ref();
|
||||
|
||||
/** 打开对话框 */
|
||||
const open = async (id: number) => {
|
||||
contractId.value = id;
|
||||
dialogVisible.value = true;
|
||||
attachmentList.value = [];
|
||||
uploadedAttachments.value = [];
|
||||
contractId.value = id
|
||||
dialogVisible.value = true
|
||||
attachmentList.value = []
|
||||
await loadExistingAttachments()
|
||||
}
|
||||
|
||||
// 加载已有的附件数据
|
||||
await loadExistingAttachments();
|
||||
};
|
||||
|
||||
/** 加载已有的附件数据 */
|
||||
const loadExistingAttachments = async () => {
|
||||
if (!contractId.value) return;
|
||||
|
||||
if (!contractId.value) return
|
||||
try {
|
||||
const res = await getContract(contractId.value);
|
||||
const contract = res.data;
|
||||
if (!contract?.attachmentFiles) return;
|
||||
|
||||
attachmentList.value = buildUploadFileListFromField(contract.attachmentFiles);
|
||||
uploadedAttachments.value = attachmentList.value
|
||||
.filter((file) => file.ossId)
|
||||
.map((file) => ({
|
||||
ossId: String(file.ossId),
|
||||
category: String(file.category || 'other')
|
||||
}));
|
||||
const res = await getContract(contractId.value)
|
||||
const contract = res.data
|
||||
if (!contract?.attachmentFiles) return
|
||||
attachmentList.value = buildUploadFileListFromField(
|
||||
contract.attachmentFiles
|
||||
) as ContractAttachmentItem[]
|
||||
} catch (error) {
|
||||
console.error('[附件回显] 加载附件数据失败:', error);
|
||||
console.error('[附件回显] 加载附件数据失败:', error)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** 文件类型判断 */
|
||||
const isImageFile = (file: any) => {
|
||||
const imageTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/bmp', 'image/webp'];
|
||||
// 1. 检查 raw.type(新上传的文件)
|
||||
if (file.raw?.type && imageTypes.includes(file.raw.type)) {
|
||||
return true;
|
||||
const validateAttachments = () => {
|
||||
if (attachmentList.value.some((file) => file.status === 'uploading')) {
|
||||
$modal.msgWarning('仍有附件正在上传,请稍候')
|
||||
return false
|
||||
}
|
||||
// 2. 检查文件名扩展名
|
||||
if (file.name && /\.(jpg|jpeg|png|gif|bmp|webp)$/i.test(file.name)) {
|
||||
return true;
|
||||
}
|
||||
// 3. 检查 URL 扩展名(回显的文件)
|
||||
if (file.url && /\.(jpg|jpeg|png|gif|bmp|webp)(\?|$)/i.test(file.url)) {
|
||||
return true;
|
||||
}
|
||||
// 4. 如果有 ossId,尝试通过 URL 判断(即使 URL 可能被清空)
|
||||
if (file.ossId && file.url && file.url.includes('image')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
/** 获取文件OSS ID */
|
||||
const getFileOssId = (file: any) => {
|
||||
return file.ossId || '';
|
||||
};
|
||||
|
||||
/** 获取文件扩展名 */
|
||||
const getFileExt = (fileName: string) => {
|
||||
const ext = fileName.split('.').pop()?.toUpperCase();
|
||||
return ext || 'FILE';
|
||||
};
|
||||
|
||||
/** 获取缩写的文件名 */
|
||||
const getShortFileName = (fileName: string) => {
|
||||
if (!fileName) return '';
|
||||
|
||||
const lastDotIndex = fileName.lastIndexOf('.');
|
||||
if (lastDotIndex === -1) {
|
||||
return fileName.length > 12 ? fileName.substring(0, 12) + '...' : fileName;
|
||||
}
|
||||
|
||||
const name = fileName.substring(0, lastDotIndex);
|
||||
const ext = fileName.substring(lastDotIndex);
|
||||
|
||||
if (name.length <= 8) {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
return name.substring(0, 8) + '...' + ext;
|
||||
};
|
||||
|
||||
/** 上传前检查 */
|
||||
const handleBeforeUpload = (file: any) => {
|
||||
const isValidType = /\.(jpg|jpeg|png|gif|bmp|webp|pdf|doc|docx|txt)$/i.test(file.name);
|
||||
|
||||
if (!isValidType) {
|
||||
$modal.msgError('上传文件格式不正确!')
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
/** 上传成功 */
|
||||
const handleUploadSuccess = (response: any, file: any) => {
|
||||
const payload = response?.data ?? response;
|
||||
const url = payload?.url || payload?.fileUrl || payload;
|
||||
if (url) {
|
||||
file.url = url;
|
||||
file.ossId = url;
|
||||
file.status = 'success';
|
||||
file.category = file.category || 'other';
|
||||
uploadedAttachments.value.push({
|
||||
ossId: url,
|
||||
category: file.category
|
||||
});
|
||||
$modal.msgSuccess('文件上传成功');
|
||||
} else {
|
||||
file.status = 'error';
|
||||
$modal.msgError(response?.msg || '文件上传失败');
|
||||
}
|
||||
};
|
||||
|
||||
/** 附件分类变更 */
|
||||
const handleCategoryChange = (file: any) => {
|
||||
// 更新已上传附件列表中的分类
|
||||
const index = uploadedAttachments.value.findIndex((item) => item.ossId === file.ossId);
|
||||
if (index !== -1) {
|
||||
uploadedAttachments.value[index].category = file.category;
|
||||
}
|
||||
};
|
||||
|
||||
/** 保存附件到数据库 */
|
||||
const saveAttachments = async () => {
|
||||
if (!contractId.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查是否有附件未选择分类
|
||||
const unclassifiedFiles = attachmentList.value.filter((file) => file.status === 'success' && !file.category);
|
||||
if (unclassifiedFiles.length > 0) {
|
||||
const unclassified = attachmentList.value.filter(
|
||||
(file) => file.status === 'success' && file.ossId && !file.category
|
||||
)
|
||||
if (unclassified.length > 0) {
|
||||
$modal.msgWarning('请为所有附件选择分类')
|
||||
return;
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// 即使没有附件也允许保存(用于清空附件的场景)
|
||||
await uploadAttachments({
|
||||
id: contractId.value,
|
||||
attachments: uploadedAttachments.value
|
||||
});
|
||||
};
|
||||
|
||||
/** 上传失败 */
|
||||
const handleUploadError = (error: any) => {
|
||||
console.error('文件上传失败:', error);
|
||||
$modal.msgError('文件上传失败')
|
||||
};
|
||||
|
||||
/** 文件预览 */
|
||||
const handleFilePreview = (file: any) => {
|
||||
if (isImageFile(file)) {
|
||||
window.open(file.url);
|
||||
} else {
|
||||
handleDownloadAttachment(file);
|
||||
}
|
||||
};
|
||||
|
||||
/** 文件变更 */
|
||||
const handleFileChange = (file: any, fileList: any) => {
|
||||
attachmentList.value = fileList;
|
||||
};
|
||||
|
||||
/** 删除附件确认 */
|
||||
const handleRemoveAttachmentConfirm = (file: any) => {
|
||||
$modal
|
||||
.confirm('确定要删除这个文件吗?')
|
||||
.then(() => {
|
||||
handleRemoveAttachment(file);
|
||||
})
|
||||
.catch(() => {
|
||||
// 取消删除
|
||||
});
|
||||
};
|
||||
|
||||
/** 删除附件 */
|
||||
const handleRemoveAttachment = (file: any) => {
|
||||
const index = attachmentList.value.findIndex((item) => item.uid === file.uid);
|
||||
if (index !== -1) {
|
||||
attachmentList.value.splice(index, 1);
|
||||
}
|
||||
// 从已上传附件列表中移除
|
||||
if (file.ossId) {
|
||||
const uploadIndex = uploadedAttachments.value.findIndex((item) => item.ossId === file.ossId);
|
||||
if (uploadIndex !== -1) {
|
||||
uploadedAttachments.value.splice(uploadIndex, 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/** 下载附件 */
|
||||
const handleDownloadAttachment = async (file: any) => {
|
||||
if (!file.ossId && !file.url) {
|
||||
$modal.msgError('文件信息不完整,无法下载');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await downloadCrmAttachment(file);
|
||||
$modal.msgSuccess('下载成功');
|
||||
} catch (error) {
|
||||
console.error('下载附件失败:', error);
|
||||
$modal.msgError('下载失败');
|
||||
}
|
||||
};
|
||||
|
||||
/** 保存并关闭 */
|
||||
const handleSaveAndClose = async () => {
|
||||
// 检查是否有附件未选择分类
|
||||
const unclassifiedFiles = attachmentList.value.filter((file) => file.status === 'success' && !file.category);
|
||||
if (unclassifiedFiles.length > 0) {
|
||||
$modal.msgWarning('请为所有附件选择分类')
|
||||
return;
|
||||
}
|
||||
if (!contractId.value) return
|
||||
if (!validateAttachments()) return
|
||||
|
||||
saveLoading.value = true
|
||||
try {
|
||||
await saveAttachments();
|
||||
await uploadAttachments({
|
||||
id: contractId.value,
|
||||
attachments: mapContractAttachmentsPayload(attachmentList.value)
|
||||
})
|
||||
$modal.msgSuccess('保存成功')
|
||||
emit('success');
|
||||
dialogVisible.value = false;
|
||||
attachmentList.value = [];
|
||||
uploadedAttachments.value = [];
|
||||
emit('success')
|
||||
handleClose()
|
||||
} catch (error) {
|
||||
console.error('保存附件失败:', error);
|
||||
console.error('保存附件失败:', error)
|
||||
$modal.msgError('保存附件失败')
|
||||
} finally {
|
||||
saveLoading.value = false
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** 关闭对话框 */
|
||||
const handleClose = () => {
|
||||
dialogVisible.value = false;
|
||||
attachmentList.value = [];
|
||||
uploadedAttachments.value = [];
|
||||
};
|
||||
dialogVisible.value = false
|
||||
attachmentList.value = []
|
||||
}
|
||||
|
||||
// 暴露方法给父组件调用
|
||||
defineExpose({
|
||||
open
|
||||
});
|
||||
defineExpose({ open })
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
/* 上传区域容器样式 */
|
||||
.attachment-upload-container {
|
||||
width: 100%;
|
||||
max-height: calc(100vh - 300px);
|
||||
min-height: 200px;
|
||||
overflow-y: auto;
|
||||
padding-right: 8px;
|
||||
border: 1px solid var(--border, #d9e8e2);
|
||||
border-radius: 8px;
|
||||
background: var(--primary-bg, #ecfdf5);
|
||||
}
|
||||
|
||||
.attachment-upload-container .upload-demo {
|
||||
padding: 12px;
|
||||
min-height: 180px;
|
||||
}
|
||||
|
||||
.attachment-upload-container .upload-demo .el-upload {
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.attachment-upload-container .upload-demo .el-upload:hover {
|
||||
border-color: var(--primary, #10b981);
|
||||
}
|
||||
|
||||
.attachment-upload-container .upload-demo .el-upload__tip {
|
||||
font-size: 12px;
|
||||
color: var(--text-muted, #64748b);
|
||||
margin-top: 7px;
|
||||
}
|
||||
|
||||
/* 调整拖拽上传图标与文字在同一行、居中对齐 */
|
||||
.attachment-upload-container .upload-demo .el-upload-dragger1 {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 15px;
|
||||
padding: 0px !important;
|
||||
}
|
||||
|
||||
.attachment-upload-container .upload-demo .el-upload-dragger1 .el-icon--upload {
|
||||
margin: 0;
|
||||
padding: 0px !important;
|
||||
}
|
||||
|
||||
/* 文件卡片占位封面样式 */
|
||||
.attachment-upload-container .upload-demo .upload-file-placeholder {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #909399;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.attachment-upload-container .upload-demo .upload-file-placeholder .el-icon {
|
||||
font-size: 28px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.attachment-upload-container .upload-demo .upload-file-placeholder .file-ext {
|
||||
font-size: 12px;
|
||||
text-transform: uppercase;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* 让附件卡片一行展示 5 个 */
|
||||
.attachment-upload-container :deep(.el-upload-list--picture-card) {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(5, 1fr);
|
||||
gap: 9px;
|
||||
margin-top: 12px;
|
||||
padding-bottom: 16px;
|
||||
}
|
||||
|
||||
/* 确保卡片宽度自适应,增加高度以容纳分类选择框 */
|
||||
.attachment-upload-container :deep(.el-upload-list--picture-card) .el-upload-list__item {
|
||||
margin: 0;
|
||||
height: 220px !important;
|
||||
width: 100% !important;
|
||||
}
|
||||
|
||||
:deep(.el-upload-dragger) {
|
||||
border: 0px !important;
|
||||
padding: 0px !important;
|
||||
}
|
||||
|
||||
:deep(.el-upload-dragger) .el-upload-dragger1 {
|
||||
border: 0px !important;
|
||||
padding: 0px !important;
|
||||
}
|
||||
|
||||
/* 文件卡片样式 */
|
||||
.upload-file-card {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 6px;
|
||||
overflow: hidden;
|
||||
background: #fff;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.upload-file-card:hover {
|
||||
}
|
||||
|
||||
.upload-file-thumb {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 110px;
|
||||
background: #f5f5f5;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.upload-thumb-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.upload-file-loading {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #fff;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.upload-file-loading .el-icon {
|
||||
font-size: 24px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.upload-file-loading .loading-text {
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.upload-file-name {
|
||||
padding: 8px;
|
||||
font-size: 12px;
|
||||
color: #333;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
background: #fff;
|
||||
border-top: 1px solid #e4e7ed;
|
||||
}
|
||||
|
||||
.upload-file-category {
|
||||
padding: 4px 8px;
|
||||
background: #fff;
|
||||
border-top: 1px solid #e4e7ed;
|
||||
}
|
||||
|
||||
.upload-file-card-actions {
|
||||
padding: 6px 8px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
background: #fafafa;
|
||||
border-top: 1px solid #e4e7ed;
|
||||
transition: all 0.3s;
|
||||
height: 38px;
|
||||
}
|
||||
|
||||
.upload-file-card-actions .el-button {
|
||||
padding: 4px 8px;
|
||||
font-size: 14px;
|
||||
.upload-scan-dialog {
|
||||
:deep(.el-dialog__body) {
|
||||
padding-top: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
.upload-dialog-actions {
|
||||
|
||||
Reference in new issue
Block a user