611 lines
17 KiB
Vue
611 lines
17 KiB
Vue
<template>
|
||
<el-row>
|
||
<el-col :span="24">
|
||
<baseTitle :title="'项目附件'"></baseTitle>
|
||
</el-col>
|
||
<el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleTabClick" @tab-remove="tabRemove"
|
||
style="margin-left: 15px;margin-top: -10px">
|
||
<el-tab-pane name="all" :closable="false" label="全部">
|
||
</el-tab-pane>
|
||
<el-tab-pane v-for="item in tagsOption" :closable="item.isClose==1&&uploadState"
|
||
:key="item.tagId"
|
||
:label="item.fileTag"
|
||
:name="item.tagId">
|
||
<div class="tag-title">
|
||
<div></div>
|
||
{{ item.fileTag }}
|
||
</div>
|
||
</el-tab-pane>
|
||
|
||
<el-tab-pane name="plus" v-if="uploadState" :closable="false">
|
||
<template #label>
|
||
<div style="margin-top: 4px;">
|
||
<el-icon color="#BEA266">
|
||
<Plus/>
|
||
</el-icon>
|
||
</div>
|
||
</template>
|
||
</el-tab-pane>
|
||
</el-tabs>
|
||
</el-row>
|
||
<div style="margin-top:10px;margin-bottom: 8px;margin-left: 15px;display: flex">
|
||
<!-- <el-button color="#DED0B2" @click="handleUpload">上传附件</el-button>-->
|
||
<file-upload v-if="!isLineBtn&&uploadState&&activeName!='plus'&&activeName!='all'" @getFile="getFile"/>
|
||
|
||
<el-button color="#DED0B2" @click="handleEditTag"
|
||
v-if="activeName!='all'&&activeName!='plus'&&uploadState&&!isDefault"
|
||
style="margin-left: 10px;">编辑
|
||
</el-button>
|
||
</div>
|
||
<fvTable style="width: 100%;min-height:311px;max-height: 311px" v-if="showAttachmentTable" height="311"
|
||
:scrollbar-always-on="true"
|
||
:tableConfig="executeTableConfig" class="execute-apply-table"
|
||
:data="otherAttachmentList" :isSettingCol="false" :pagination="false">
|
||
<template #empty>
|
||
<el-empty :image-size="90" description="暂无数据" style="padding: 0"/>
|
||
</template>
|
||
</fvTable>
|
||
<div class="oper-page-btn" style="margin-right: 90px" v-if="uploadState">
|
||
<el-button color="#DED0B2" @click="handleSubmit()">提交</el-button>
|
||
</div>
|
||
|
||
<file-preview ref="filePreviewRef" :fullscreen="false" v-if="filePreviewShow" :fileName="filePreviewParam.fileName"
|
||
:fileUrl="filePreviewParam.fileUrl"
|
||
:fileType="filePreviewParam.fileType"/>
|
||
<el-dialog v-model="tagNameShow" center width="450" top="40vh">
|
||
<div style="display: flex;align-items: center">标签:
|
||
<el-input v-model="fileParam.tagName" placeholder="请输入标签名称" style="width: 335px;" clearable/>
|
||
</div>
|
||
|
||
<div class="oper" style="display: flex;justify-content: flex-end;margin-top: 10px">
|
||
<el-button color="#DED0B2" @click="changeTag()">确定</el-button>
|
||
<el-button @click="tagNameShow=false">取消</el-button>
|
||
</div>
|
||
</el-dialog>
|
||
</template>
|
||
|
||
<script setup lang="jsx">
|
||
import {addTag, delTag, getTagList, updateTag} from "@/api/project-manage";
|
||
import {ElLoading, ElMessageBox, ElNotification} from "element-plus";
|
||
import {searchImplementationFileList, uploadFileList} from "@/api/project-manage/attachment";
|
||
import {deleteFile, downloadFile} from "@/api/project-demand";
|
||
import {nextTick, onActivated} from "vue";
|
||
|
||
const router = useRouter()
|
||
const route = useRoute()
|
||
const attachmentParam = reactive({
|
||
tag: ''
|
||
})
|
||
const fileParam = ref({
|
||
tagName: ''
|
||
})
|
||
const uploadState = ref(false)
|
||
const tagNameShow = ref(false)
|
||
const isDefault = ref(false)
|
||
const tagsOption = ref([])
|
||
const fileList = ref([])
|
||
const allFiles = ref([])
|
||
const showAttachmentTable = ref(true)
|
||
const activeName = ref('all')
|
||
|
||
const props = defineProps({
|
||
fileNameTableWidth: {
|
||
type: String,
|
||
default: '400'
|
||
},
|
||
isLineBtn: {
|
||
type: Boolean,
|
||
default: false
|
||
},
|
||
})
|
||
const executeTableConfig = reactive({
|
||
columns: [
|
||
{
|
||
prop: 'index',
|
||
type: 'index',
|
||
label: '序号',
|
||
align: 'center',
|
||
width: 85,
|
||
},
|
||
{
|
||
prop: 'originalFileName',
|
||
label: '文件名',
|
||
align: 'center',
|
||
width: props.fileNameTableWidth,
|
||
showOverflowTooltip: false,
|
||
currentRender: ({row, index}) => (
|
||
<div style="color: #2a99ff;cursor: pointer;" onClick={() => clickToPreview(row)}>{row.originalFileName}</div>)
|
||
},
|
||
{
|
||
prop: 'tag',
|
||
label: '标签',
|
||
align: 'center',
|
||
showOverflowTooltip: false,
|
||
},
|
||
{
|
||
prop: 'size',
|
||
label: '文件大小',
|
||
align: 'center',
|
||
currentRender: ({row, index}) => (parseInt(row.size / 1024) + 'KB')
|
||
},
|
||
{
|
||
prop: 'oper',
|
||
label: '操作',
|
||
align: 'center',
|
||
showOverflowTooltip: false,
|
||
currentRender: ({row, index}) => {
|
||
return (
|
||
<div>
|
||
<el-button type="primary" link onClick={() => handleDownload(row)}>下载</el-button>
|
||
{
|
||
uploadState.value ?
|
||
<popover-delete name={row.originalFileName} type={'文件'} btnType={'danger'}
|
||
onDelete={() => deleteSingleFile(row)}/> : ''
|
||
}
|
||
</div>
|
||
)
|
||
}
|
||
}
|
||
]
|
||
})
|
||
// row.newFile ?: ''
|
||
const otherAttachmentList = ref([])
|
||
|
||
const filePreviewParam = ref({
|
||
fileUrl: '',
|
||
fileName: '',
|
||
fileType: 'pdf'
|
||
})
|
||
const filePreviewShow = ref(false)
|
||
const uploadLoading = ref(false)
|
||
const isEdit = ref(false)
|
||
const isCloseByList = (index) => {
|
||
// otherAttachmentList.length>0?false:true
|
||
return otherAttachmentList.value.length == 0;
|
||
}
|
||
const handleDownload = (row) => {
|
||
downloadFile(row.fileId).then(res => {
|
||
const blob = new Blob([res])
|
||
let a = document.createElement('a')
|
||
a.href = URL.createObjectURL(blob)
|
||
a.download = row.originalFileName
|
||
a.click()
|
||
})
|
||
}
|
||
const deleteSingleFile = (row) => {
|
||
console.log("🚀 ~ file: ", row,otherAttachmentList.value)
|
||
console.log("🚀 row.newFile ", row.newFile)
|
||
deleteFile(row.fileId).then(res => {
|
||
ElNotification({
|
||
title: '提示',
|
||
message: res.msg,
|
||
type: res.code === 1000 ? 'success' : 'error'
|
||
})
|
||
if (res.code === 1000) {
|
||
if (row.newFile) {
|
||
const finalList = getLocalList().filter(item => item.fileId !== row.fileId);
|
||
otherAttachmentList.value.splice(otherAttachmentList.value.findIndex((item) => item.fileId === row.fileId), 1);
|
||
localStorage.setItem(`implementAllFileList-${route.query.projectId}`, JSON.stringify(finalList))
|
||
} else {
|
||
otherAttachmentList.value.splice(otherAttachmentList.value.findIndex((item) => item.fileId === row.fileId), 1);
|
||
allFiles.value.splice(allFiles.value.findIndex((item) => item.fileId === row.fileId), 1);
|
||
}
|
||
|
||
// getAttachmentList()
|
||
}
|
||
});
|
||
}
|
||
|
||
const changeTag = async () => {
|
||
let res = null
|
||
if (isEdit.value) {
|
||
res = await updateTag({
|
||
tagId: activeName.value,
|
||
fileTag: fileParam.value.tagName,
|
||
projectId: route.query.projectId,
|
||
})
|
||
changeFileList(fileParam.value.tagName, true)
|
||
} else {
|
||
res = await addTag({
|
||
projectId: route.query.projectId,
|
||
fileTag: fileParam.value.tagName
|
||
})
|
||
|
||
getAttachmentList()
|
||
fileParam.value.tagName = ''
|
||
activeName.value = 'all'
|
||
}
|
||
ElNotification({
|
||
title: '提示',
|
||
message: res.msg,
|
||
type: res.code === 1000 ? 'success' : 'error'
|
||
})
|
||
tagNameShow.value = false;
|
||
}
|
||
const tabRemove = async (val) => {
|
||
if (otherAttachmentList.value && otherAttachmentList.value.length > 0) {
|
||
ElNotification({
|
||
title: '提示',
|
||
message: '该标签下存在文件,不能删除标签。如需删除标签,请先删除该标签下的所有文件。',
|
||
type: 'error'
|
||
})
|
||
return;
|
||
}
|
||
ElMessageBox.confirm(`确认删除名称为${getTagName(val)}的标签吗?`, '系统提示', {
|
||
confirmButtonText: '确定',
|
||
cancelButtonText: '取消',
|
||
type: 'warning'
|
||
}).then(async () => {
|
||
let res = await delTag(val)
|
||
ElNotification({
|
||
title: '提示',
|
||
message: res.msg,
|
||
type: res.code === 1000 ? 'success' : 'error'
|
||
})
|
||
if (res.code === 1000) {
|
||
getTagsOption()
|
||
otherAttachmentList.value = allFiles.value
|
||
}
|
||
})
|
||
}
|
||
const handleEditTag = () => {
|
||
fileParam.value.tagName = getTagName(activeName.value)
|
||
if (otherAttachmentList.value && otherAttachmentList.value.length > 0) {
|
||
ElNotification({
|
||
title: '提示',
|
||
message: '该标签下存在文件,不能编辑标签。如需编辑标签,请先删除该标签下的所有文件。',
|
||
type: 'error'
|
||
})
|
||
return;
|
||
}
|
||
tagNameShow.value = true
|
||
isEdit.value = true
|
||
}
|
||
const getTagName = (name) => {
|
||
const tagArray = tagsOption.value.filter((item1) => item1.tagId == name)
|
||
let tagName = ''
|
||
if (tagArray && tagArray.length > 0) {
|
||
tagName = tagArray[0].fileTag
|
||
}
|
||
return tagName
|
||
}
|
||
const handleTabClick = (item, e) => {
|
||
const defaultArray = tagsOption.value.filter(item1 => item1.tagId == item.props.name)
|
||
if (defaultArray && defaultArray.length > 0) {
|
||
isDefault.value = defaultArray[0].isDefault == 1
|
||
} else {
|
||
isDefault.value = false
|
||
}
|
||
tagNameShow.value = item.props.name == 'plus';
|
||
if (item.props.name == 'plus') {
|
||
isEdit.value = false
|
||
fileParam.value.tagName = ''
|
||
}
|
||
if (item.props.name != 'plus') {
|
||
if (item.props.name == 'all') {
|
||
changeFileList('all')
|
||
} else {
|
||
changeFileList(getTagName(item.props.name))
|
||
}
|
||
// if (item.props.name == 'all') {
|
||
// otherAttachmentList.value = allFiles.value
|
||
// } else {
|
||
// otherAttachmentList.value = allFiles.value.filter(item1 => item1.tag == getTagName(item.props.name))
|
||
// }
|
||
}
|
||
// showAttachmentTable.value = false
|
||
// nextTick(() => {
|
||
// showAttachmentTable.value = true
|
||
// })
|
||
}
|
||
const compositeParam = (item) => {
|
||
return {
|
||
fileId: item.id,
|
||
size: item.size,
|
||
originalFileName: item.originalFilename,
|
||
fileType: item.fileType,
|
||
url: item.url,
|
||
newFile: true,
|
||
tag: getTagName(activeName.value) || '项目实施',
|
||
}
|
||
}
|
||
const getFile = (val) => {
|
||
|
||
console.log('上传文件', val)
|
||
fileList.value = getLocalList()
|
||
let fileObj = compositeParam(val)
|
||
fileList.value.push(fileObj)
|
||
localStorage.setItem(`implementAllFileList-${route.query.projectId}`, JSON.stringify(fileList.value))
|
||
otherAttachmentList.value.push(fileObj)
|
||
// handleSubmit([fileObj])
|
||
}
|
||
|
||
const handleSubmit = async () => {
|
||
if (getLocalList().length == 0) {
|
||
ElNotification({
|
||
title: '提示',
|
||
message: '暂无文件可提交',
|
||
type: 'warning'
|
||
})
|
||
return;
|
||
} else {
|
||
let params = {
|
||
fileList: getLocalList(),
|
||
projectId: route.query.projectId,
|
||
targetState: "30"
|
||
}
|
||
let res = await uploadFileList(params)
|
||
if (res.code !== 1000) {
|
||
ElNotification({
|
||
title: '提示',
|
||
message: res.msg,
|
||
type: 'error'
|
||
})
|
||
} else {
|
||
ElNotification({
|
||
title: '提示',
|
||
message: res.msg,
|
||
type: 'success'
|
||
})
|
||
localStorage.removeItem(`implementAllFileList-${route.query.projectId}`)
|
||
// list.forEach(item => {
|
||
// otherAttachmentList.value.push(item)
|
||
// })
|
||
getAttachmentList()
|
||
fileList.value = []
|
||
}
|
||
// changeFileList('all',true)
|
||
}
|
||
}
|
||
const clickToPreview = (row) => {
|
||
filePreviewShow.value = false
|
||
filePreviewParam.value = {
|
||
fileUrl: row.url,
|
||
fileName: row.originalFileName,
|
||
fileType: row.fileType
|
||
}
|
||
nextTick(() => {
|
||
filePreviewShow.value = true
|
||
})
|
||
}
|
||
const changeFileList = (tag, flag) => {
|
||
let params = {}
|
||
if (tag == 'all') {
|
||
otherAttachmentList.value = allFiles.value
|
||
// params = {
|
||
// targetId: route.query.projectId,
|
||
// targetState: "30",
|
||
// }
|
||
|
||
otherAttachmentList.value = [...otherAttachmentList.value, ...getLocalList()];
|
||
} else {
|
||
const filw = getLocalList().filter(item1 => item1.tag === tag);
|
||
const filteredAllFiles = allFiles.value.filter(item1 => item1.tag === tag);
|
||
|
||
// 使用 fileId 作为唯一标识进行去重
|
||
const seen = new Set();
|
||
const uniqueFiles = [...filteredAllFiles, ...filw].filter(item => {
|
||
if (!seen.has(item.fileId)) {
|
||
seen.add(item.fileId);
|
||
return true;
|
||
}
|
||
return false;
|
||
});
|
||
|
||
otherAttachmentList.value = uniqueFiles;
|
||
// params = {
|
||
// targetId: route.query.projectId,
|
||
// targetState: "30",
|
||
// tag: tag
|
||
// }
|
||
}
|
||
showAttachmentTable.value = false
|
||
|
||
// searchImplementationFileList(params).then(res => {
|
||
// if (res.code === 1000) {
|
||
// if(tag == 'all'&&flag){
|
||
// // allFiles.value = res.data.fileList
|
||
// }else{
|
||
// otherAttachmentList.value =res.data.fileList
|
||
// }
|
||
if (flag) {
|
||
getTagsOption(flag)
|
||
}
|
||
nextTick(() => {
|
||
showAttachmentTable.value = true
|
||
})
|
||
// }
|
||
// })
|
||
}
|
||
const getLocalList = () => {
|
||
if (localStorage.getItem(`implementAllFileList-${route.query.projectId}`) && JSON.parse(localStorage.getItem(`implementAllFileList-${route.query.projectId}`))) {
|
||
return JSON.parse(localStorage.getItem(`implementAllFileList-${route.query.projectId}`))
|
||
} else {
|
||
return []
|
||
}
|
||
}
|
||
const getAttachmentList = () => {
|
||
const loading = ElLoading.service({fullscreen: true})
|
||
let params = {
|
||
targetId: route.query.projectId,
|
||
targetState: "30"
|
||
}
|
||
showAttachmentTable.value = false
|
||
searchImplementationFileList(params).then(res => {
|
||
if (res.code === 1000) {
|
||
otherAttachmentList.value = [...res.data.fileList, ...getLocalList()]
|
||
allFiles.value = [...res.data.fileList, ...getLocalList()]
|
||
uploadState.value = res.data.upload
|
||
getTagsOption()
|
||
nextTick(() => {
|
||
showAttachmentTable.value = true
|
||
})
|
||
activeName.value = 'all'
|
||
loading.close()
|
||
} else {
|
||
ElNotification({
|
||
title: '提示',
|
||
message: res.msg,
|
||
type: 'error'
|
||
})
|
||
loading.close()
|
||
}
|
||
})
|
||
}
|
||
const getTagsOption = (flag) => {
|
||
if (!route.query.projectId) return
|
||
getTagList(route.query.projectId).then(res => {
|
||
if (res.code === 1000) {
|
||
|
||
tagsOption.value = res.data.rows
|
||
let list = []
|
||
if (flag) {
|
||
|
||
list = allFiles.value
|
||
} else {
|
||
list = otherAttachmentList.value
|
||
}
|
||
tagsOption.value.forEach((tag, index) => {
|
||
// const filterArray = list.filter(item => tag.fileTag == item.tag)
|
||
// console.log("🚀 ~ file:filterArray ", filterArray)
|
||
tagsOption.value[index].isClose = 1
|
||
// tagsOption.value[index].isClose = filterArray.length > 0 ? 0 : 1
|
||
})
|
||
console.log("🚀 otherAttachmentList.value", allFiles.value)
|
||
console.log("🚀 ~ file:\tagsOption.value ", tagsOption.value)
|
||
let defaultArray = [
|
||
{
|
||
tagId: 'd1',
|
||
fileTag: '合同(专项任务书)',
|
||
isDefault: 1,
|
||
isClose: 2
|
||
},
|
||
{
|
||
tagId: 'd2',
|
||
fileTag: '周报',
|
||
isDefault: 1,
|
||
isClose: 2
|
||
},
|
||
{
|
||
tagId: 'd3',
|
||
fileTag: '阶段性验收',
|
||
isDefault: 1,
|
||
isClose: 2
|
||
},
|
||
{
|
||
tagId: 'd4',
|
||
fileTag: '科研成果',
|
||
isDefault: 1,
|
||
isClose: 2
|
||
}
|
||
]
|
||
tagsOption.value = [...defaultArray, ...tagsOption.value]
|
||
// if (!res.data.rows || res.data.rows.length == 0) return;
|
||
// activeName.value=res.data.rows[0].tagId
|
||
} else {
|
||
ElNotification({
|
||
title: '提示',
|
||
message: res.msg,
|
||
type: 'error'
|
||
})
|
||
}
|
||
})
|
||
}
|
||
const handleUpload = () => {
|
||
router.push({
|
||
name: 'Implementation/upload',
|
||
query: {
|
||
id: route.query.id,
|
||
projectId: route.query.projectId,
|
||
state: route.query.state,
|
||
step: '30'
|
||
}
|
||
})
|
||
}
|
||
getAttachmentList()
|
||
onActivated(() => {
|
||
getAttachmentList()
|
||
})
|
||
</script>
|
||
<style lang="scss">
|
||
.execute-apply-table {
|
||
//.el-table__header {
|
||
// .el-table__cell:last-child {
|
||
// .cell {
|
||
// margin-left: -108px !important;
|
||
// }
|
||
// }
|
||
//}
|
||
|
||
//.el-table__body {
|
||
// .el-table__cell:last-child {
|
||
// .cell {
|
||
// margin-left: -108px !important;
|
||
// }
|
||
// }
|
||
//}
|
||
.is-leaf:first-child {
|
||
.cell {
|
||
margin-left: -25px !important;
|
||
}
|
||
}
|
||
|
||
.el-table__body {
|
||
.el-table__cell:first-child {
|
||
.cell {
|
||
margin-left: -13px !important;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
</style>
|
||
<style scoped lang="scss">
|
||
:deep(.el-dialog__body) {
|
||
padding: 0 !important;
|
||
}
|
||
|
||
.tag-title {
|
||
display: flex;
|
||
align-items: center;
|
||
margin-top: 15px;
|
||
|
||
> div {
|
||
margin-right: 5px;
|
||
width: 4px;
|
||
height: 20px;
|
||
background-color: #BEA266;
|
||
}
|
||
}
|
||
|
||
:deep(.el-table--fit ) {
|
||
height: 311px !important;
|
||
}
|
||
|
||
:deep(.el-tabs__nav) {
|
||
//width: 75vw;
|
||
}
|
||
|
||
:deep(.el-tabs__item) {
|
||
flex: none !important;
|
||
}
|
||
|
||
:deep(.el-tabs__header) {
|
||
margin-bottom: 0;
|
||
}
|
||
|
||
:deep(.el-tabs__item.is-active) {
|
||
color: #BEA266;
|
||
}
|
||
|
||
:deep(.el-tabs__active-bar) {
|
||
background-color: #BEA266;
|
||
}
|
||
|
||
.file-tag {
|
||
width: 100%;
|
||
display: flex;
|
||
border-bottom: 2px solid #f6f6f6;
|
||
/*align-items: center;*/
|
||
}
|
||
</style>
|