|
|
|
@ -27,6 +27,7 @@ |
|
|
|
<el-form-item style="margin-left: 40px"> |
|
|
|
<el-button type="primary" icon="el-icon-search" @click="getFileList()">查询</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> |
|
|
|
|
|
|
|
@ -219,7 +220,8 @@ import SopFileManagementUpload from './sopFileManagementUpload' |
|
|
|
import { |
|
|
|
sopAvailableFiles, |
|
|
|
sopFileUploadSave, |
|
|
|
getStandardOperation |
|
|
|
getStandardOperation, |
|
|
|
sopAvailableFilesDelete |
|
|
|
} from '@/api/qc/qc.js' |
|
|
|
|
|
|
|
export default { |
|
|
|
@ -243,9 +245,12 @@ export default { |
|
|
|
filePageIndex: 1, |
|
|
|
filePageSize: 10, |
|
|
|
fileTotalPage: 0, |
|
|
|
serverFileTotalPage: 0, // 服务端返回的原始总数 |
|
|
|
fileListLoading: false, |
|
|
|
selectedFiles: [], |
|
|
|
deleteLoading: false, |
|
|
|
uploadedFileList: [], |
|
|
|
pendingAddedFiles: [], // 已添加到下方、需从上方隐藏的文件 |
|
|
|
selectedUploadedFiles: [], // 已上传文件表格中选中的文件 |
|
|
|
operationList: [] |
|
|
|
} |
|
|
|
@ -282,15 +287,71 @@ export default { |
|
|
|
} |
|
|
|
this.selectedFiles = [] |
|
|
|
this.uploadedFileList = [] |
|
|
|
this.pendingAddedFiles = [] |
|
|
|
this.selectedUploadedFiles = [] |
|
|
|
this.fileList = [] |
|
|
|
this.originalFileList = [] |
|
|
|
this.filePageIndex = 1 |
|
|
|
this.fileTotalPage = 0 |
|
|
|
this.serverFileTotalPage = 0 |
|
|
|
}, |
|
|
|
openUploadDialog () { |
|
|
|
this.$nextTick(() => { |
|
|
|
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 () { |
|
|
|
this.fileListLoading = true |
|
|
|
@ -306,17 +367,21 @@ export default { |
|
|
|
}).then(({data}) => { |
|
|
|
if (data && data.code === 0) { |
|
|
|
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 { |
|
|
|
this.fileList = [] |
|
|
|
this.originalFileList = [] |
|
|
|
this.serverFileTotalPage = 0 |
|
|
|
this.fileTotalPage = 0 |
|
|
|
} |
|
|
|
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 => { |
|
|
|
// 从原始文件列表中找到完整的文件信息 |
|
|
|
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 |
|
|
|
}) |
|
|
|
}, |
|
|
|
// 删除上方列表中选中的文件(真实删除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 () { |
|
|
|
if (this.selectedFiles.length === 0) { |
|
|
|
@ -362,11 +468,13 @@ export default { |
|
|
|
|
|
|
|
// 添加到已上传列表 |
|
|
|
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) { |
|
|
|
duplicateCount++ |
|
|
|
} else { |
|
|
|
this.uploadedFileList.push({ |
|
|
|
id: file.id, |
|
|
|
site: file.site, |
|
|
|
buNo: file.buNo, |
|
|
|
fileNo: file.fileNo, |
|
|
|
@ -388,11 +496,8 @@ export default { |
|
|
|
if (duplicateCount > 0) { |
|
|
|
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) { |
|
|
|
this.$message.success(`已添加 ${addedCount} 个文件`) |
|
|
|
@ -408,26 +513,17 @@ export default { |
|
|
|
this.$message.warning('请先选择要删除的文件') |
|
|
|
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.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() |
|
|
|
@ -440,6 +536,8 @@ export default { |
|
|
|
// 删除已上传的文件 |
|
|
|
removeUploadedFile (index) { |
|
|
|
this.uploadedFileList.splice(index, 1) |
|
|
|
this.syncPendingAddedFiles() |
|
|
|
this.refreshFileListView() |
|
|
|
this.$message.success('文件已移除') |
|
|
|
}, |
|
|
|
// 保存文件 |
|
|
|
|