Browse Source

2026-08-05

物料档案管理-》SOP清单-》从文件库添加增加【删除】功能
master
fengyuan_yang 2 months ago
parent
commit
c8db1c78f0
  1. 1
      src/api/qc/qc.js
  2. 154
      src/views/modules/qc/sopFileUpload.vue

1
src/api/qc/qc.js

@ -261,6 +261,7 @@ export const getCustomerList = data => createAPI(`/pms/qc/getCustomerList`,'post
// ===================================== SOP清单 ===================================== // ===================================== SOP清单 =====================================
export const sopListSearch = data => createAPI(`/pms/qc/sopListSearch`,'post',data) export const sopListSearch = data => createAPI(`/pms/qc/sopListSearch`,'post',data)
export const sopAvailableFiles = data => createAPI(`/pms/qc/sopAvailableFiles`,'post',data) export const sopAvailableFiles = data => createAPI(`/pms/qc/sopAvailableFiles`,'post',data)
export const sopAvailableFilesDelete = data => createAPI(`/pms/qc/sopAvailableFiles/delete`,'post',data)
/** 物料SOP「文件上传」弹窗:批量本地上传,写入 file_management(D:\\sop_files + UspInsertSOP) */ /** 物料SOP「文件上传」弹窗:批量本地上传,写入 file_management(D:\\sop_files + UspInsertSOP) */
export const sopFileBatchUpload = data => createAPI(`/pms/qc/sopFileBatchUpload`, 'post', data) export const sopFileBatchUpload = data => createAPI(`/pms/qc/sopFileBatchUpload`, 'post', data)
// 查询检验页面的SOP文件列表(IPQC/IQC/FQC/OQC/过程检验) // 查询检验页面的SOP文件列表(IPQC/IQC/FQC/OQC/过程检验)

154
src/views/modules/qc/sopFileUpload.vue

@ -27,6 +27,7 @@
<el-form-item style="margin-left: 40px"> <el-form-item style="margin-left: 40px">
<el-button type="primary" icon="el-icon-search" @click="getFileList()">查询</el-button> <el-button type="primary" icon="el-icon-search" @click="getFileList()">查询</el-button>
<el-button type="primary" @click="openUploadDialog()">上传文件</el-button> <el-button type="primary" @click="openUploadDialog()">上传文件</el-button>
<el-button type="danger" :disabled="selectedFiles.length === 0" :loading="deleteLoading" @click="deleteSelectedFiles">删除</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
@ -219,7 +220,8 @@ import SopFileManagementUpload from './sopFileManagementUpload'
import { import {
sopAvailableFiles, sopAvailableFiles,
sopFileUploadSave, sopFileUploadSave,
getStandardOperation
getStandardOperation,
sopAvailableFilesDelete
} from '@/api/qc/qc.js' } from '@/api/qc/qc.js'
export default { export default {
@ -243,9 +245,12 @@ export default {
filePageIndex: 1, filePageIndex: 1,
filePageSize: 10, filePageSize: 10,
fileTotalPage: 0, fileTotalPage: 0,
serverFileTotalPage: 0, // 服务端返回的原始总数
fileListLoading: false, fileListLoading: false,
selectedFiles: [], selectedFiles: [],
deleteLoading: false,
uploadedFileList: [], uploadedFileList: [],
pendingAddedFiles: [], // 已添加到下方、需从上方隐藏的文件
selectedUploadedFiles: [], // 已上传文件表格中选中的文件 selectedUploadedFiles: [], // 已上传文件表格中选中的文件
operationList: [] operationList: []
} }
@ -282,15 +287,71 @@ export default {
} }
this.selectedFiles = [] this.selectedFiles = []
this.uploadedFileList = [] this.uploadedFileList = []
this.pendingAddedFiles = []
this.selectedUploadedFiles = [] this.selectedUploadedFiles = []
this.fileList = []
this.originalFileList = [] this.originalFileList = []
this.filePageIndex = 1 this.filePageIndex = 1
this.fileTotalPage = 0
this.serverFileTotalPage = 0
}, },
openUploadDialog () { openUploadDialog () {
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.sopFileManagementUpload.init(this.currentSite, this.currentBuNo) this.$refs.sopFileManagementUpload.init(this.currentSite, this.currentBuNo)
}) })
}, },
// 生成文件唯一键
getFileKey (file) {
if (!file) {
return ''
}
if (file.id !== null && file.id !== undefined && file.id !== '') {
return `id_${file.id}`
}
const site = file.site || ''
const buNo = file.buNo || ''
const fileNo = file.fileNo || ''
const sopRevNo = file.sopRevNo || ''
return `${site}__${buNo}__${fileNo}__${sopRevNo}`
},
// 同步「下方已添加文件」到上方隐藏集合
syncPendingAddedFiles () {
this.pendingAddedFiles = this.uploadedFileList.map(file => ({
id: file.id,
site: file.site,
buNo: file.buNo,
fileNo: file.fileNo,
fileName: file.fileName,
fileType: file.fileType,
sopRevNo: file.sopRevNo
}))
},
// 判断文件是否命中当前搜索条件
isFileMatchCurrentSearch (file) {
const fileNoKeyword = (this.searchForm.fileNo || '').trim().toLowerCase()
const fileNameKeyword = (this.searchForm.fileName || '').trim().toLowerCase()
const fileTypeKeyword = (this.searchForm.fileType || '').trim().toLowerCase()
const sopRevNoKeyword = (this.searchForm.sopRevNo || '').trim().toLowerCase()
const fileNo = String(file.fileNo || '').toLowerCase()
const fileName = String(file.fileName || '').toLowerCase()
const fileType = String(file.fileType || '').toLowerCase()
const sopRevNo = String(file.sopRevNo || '').toLowerCase()
return (!fileNoKeyword || fileNo.indexOf(fileNoKeyword) > -1) &&
(!fileNameKeyword || fileName.indexOf(fileNameKeyword) > -1) &&
(!fileTypeKeyword || fileType.indexOf(fileTypeKeyword) > -1) &&
(!sopRevNoKeyword || sopRevNo.indexOf(sopRevNoKeyword) > -1)
},
// 获取当前查询条件下已添加到下方的条数(用于动态更新上方总数)
getPendingAddedCountForCurrentSearch () {
return this.pendingAddedFiles.filter(file => this.isFileMatchCurrentSearch(file)).length
},
// 刷新上方列表展示(行数据 + 总条数)
refreshFileListView () {
const pendingFileKeys = new Set(this.pendingAddedFiles.map(file => this.getFileKey(file)))
this.fileList = this.originalFileList.filter(file => !pendingFileKeys.has(this.getFileKey(file)))
const pendingCount = this.getPendingAddedCountForCurrentSearch()
this.fileTotalPage = Math.max((this.serverFileTotalPage || 0) - pendingCount, 0)
},
// 获取文件列表 // 获取文件列表
getFileList () { getFileList () {
this.fileListLoading = true this.fileListLoading = true
@ -306,17 +367,21 @@ export default {
}).then(({data}) => { }).then(({data}) => {
if (data && data.code === 0) { if (data && data.code === 0) {
this.originalFileList = data.page.list || [] // 保存原始数据 this.originalFileList = data.page.list || [] // 保存原始数据
// 过滤掉已添加的文件
this.fileList = this.originalFileList.filter(file =>
!this.uploadedFileList.some(uploaded => uploaded.fileNo === file.fileNo && uploaded.sopRevNo === file.sopRevNo)
)
this.fileTotalPage = data.page.totalCount || 0
this.serverFileTotalPage = data.page.totalCount || 0
this.refreshFileListView()
} else { } else {
this.fileList = [] this.fileList = []
this.originalFileList = [] this.originalFileList = []
this.serverFileTotalPage = 0
this.fileTotalPage = 0 this.fileTotalPage = 0
} }
this.fileListLoading = false this.fileListLoading = false
}).catch(() => {
this.fileList = []
this.originalFileList = []
this.serverFileTotalPage = 0
this.fileTotalPage = 0
this.fileListLoading = false
}) })
}, },
// 重置搜索 // 重置搜索
@ -346,10 +411,51 @@ export default {
// 确保选中的文件包含完整数据 // 确保选中的文件包含完整数据
this.selectedFiles = val.map(selectedFile => { this.selectedFiles = val.map(selectedFile => {
// 从原始文件列表中找到完整的文件信息 // 从原始文件列表中找到完整的文件信息
const completeFile = this.fileList.find(file => file.fileNo === selectedFile.fileNo && file.sopRevNo === selectedFile.sopRevNo)
const selectedFileKey = this.getFileKey(selectedFile)
const completeFile = this.fileList.find(file => this.getFileKey(file) === selectedFileKey)
return completeFile || selectedFile return completeFile || selectedFile
}) })
}, },
// 删除上方列表中选中的文件(真实删除file_management)
deleteSelectedFiles () {
if (this.selectedFiles.length === 0) {
this.$message.warning('请先选择要删除的文件')
return
}
this.$confirm(`确定删除选中的 ${this.selectedFiles.length} 个文件吗?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.deleteLoading = true
const deleteList = this.selectedFiles.map(file => ({
id: file.id,
site: file.site,
buNo: file.buNo,
fileNo: file.fileNo,
sopRevNo: file.sopRevNo,
sopUrl: file.sopUrl || ''
}))
sopAvailableFilesDelete(deleteList).then(({ data }) => {
if (data && data.code === 0) {
this.$message.success(`成功删除 ${this.selectedFiles.length} 个文件`)
const deleteFileKeys = new Set(deleteList.map(file => this.getFileKey(file)))
this.uploadedFileList = this.uploadedFileList.filter(file => !deleteFileKeys.has(this.getFileKey(file)))
this.syncPendingAddedFiles()
this.$refs.fileTable && this.$refs.fileTable.clearSelection()
this.selectedFiles = []
this.getFileList()
} else {
this.$message.error((data && data.msg) || '删除失败')
}
}).catch(() => {
this.$message.error('删除失败')
}).finally(() => {
this.deleteLoading = false
})
}).catch(() => {})
},
// 添加选中的文件 // 添加选中的文件
addSelectedFiles () { addSelectedFiles () {
if (this.selectedFiles.length === 0) { if (this.selectedFiles.length === 0) {
@ -362,11 +468,13 @@ export default {
// 添加到已上传列表 // 添加到已上传列表
this.selectedFiles.forEach(file => { this.selectedFiles.forEach(file => {
const exists = this.uploadedFileList.some(uploaded => uploaded.fileNo === file.fileNo && uploaded.sopRevNo === file.sopRevNo)
const fileKey = this.getFileKey(file)
const exists = this.uploadedFileList.some(uploaded => this.getFileKey(uploaded) === fileKey)
if (exists) { if (exists) {
duplicateCount++ duplicateCount++
} else { } else {
this.uploadedFileList.push({ this.uploadedFileList.push({
id: file.id,
site: file.site, site: file.site,
buNo: file.buNo, buNo: file.buNo,
fileNo: file.fileNo, fileNo: file.fileNo,
@ -388,11 +496,8 @@ export default {
if (duplicateCount > 0) { if (duplicateCount > 0) {
this.$message.warning(`存在 ${duplicateCount} 个文件编码和版本号重复的文件,不能重复添加`) this.$message.warning(`存在 ${duplicateCount} 个文件编码和版本号重复的文件,不能重复添加`)
} }
// 从上方列表中移除已添加的文件
this.fileList = this.fileList.filter(file =>
!this.uploadedFileList.some(uploaded => uploaded.fileNo === file.fileNo && uploaded.sopRevNo === file.sopRevNo)
)
this.syncPendingAddedFiles()
this.refreshFileListView()
if (addedCount > 0) { if (addedCount > 0) {
this.$message.success(`已添加 ${addedCount} 个文件`) this.$message.success(`已添加 ${addedCount} 个文件`)
@ -408,26 +513,17 @@ export default {
this.$message.warning('请先选择要删除的文件') this.$message.warning('请先选择要删除的文件')
return return
} }
// 将删除的文件重新添加到上方列表
this.selectedUploadedFiles.forEach(file => {
// 检查原始列表中是否存在该文件
const originalFile = this.originalFileList.find(original => original.fileNo === file.fileNo && original.sopRevNo === file.sopRevNo)
if (originalFile) {
// 检查上方列表中是否已存在
const exists = this.fileList.some(existing => existing.fileNo === file.fileNo && existing.sopRevNo === file.sopRevNo)
if (!exists) {
this.fileList.push(originalFile)
}
}
})
const selectedCount = this.selectedUploadedFiles.length
const selectedFileKeys = new Set(this.selectedUploadedFiles.map(file => this.getFileKey(file)))
// 从已上传列表中移除 // 从已上传列表中移除
this.uploadedFileList = this.uploadedFileList.filter(file => this.uploadedFileList = this.uploadedFileList.filter(file =>
!this.selectedUploadedFiles.some(selected => selected.fileNo === file.fileNo && selected.sopRevNo === file.sopRevNo)
!selectedFileKeys.has(this.getFileKey(file))
) )
this.syncPendingAddedFiles()
this.refreshFileListView()
this.$message.success(`已删除${this.selectedUploadedFiles.length}个文件`)
this.$message.success(`已删除${selectedCount}个文件`)
// 清空选择 // 清空选择
this.$refs.uploadedFileTable && this.$refs.uploadedFileTable.clearSelection() this.$refs.uploadedFileTable && this.$refs.uploadedFileTable.clearSelection()
@ -440,6 +536,8 @@ export default {
// 删除已上传的文件 // 删除已上传的文件
removeUploadedFile (index) { removeUploadedFile (index) {
this.uploadedFileList.splice(index, 1) this.uploadedFileList.splice(index, 1)
this.syncPendingAddedFiles()
this.refreshFileListView()
this.$message.success('文件已移除') this.$message.success('文件已移除')
}, },
// 保存文件 // 保存文件

Loading…
Cancel
Save