<!-- 巡查报告管理 -->
|
<template>
|
<basic-container>
|
<el-form ref="queryParamsRef" :model="searchParams" class="gd-search-form">
|
<el-form-item label="模糊搜索" prop="nickName">
|
<el-input
|
class="gd-input gray"
|
v-model="searchParams.nickName"
|
placeholder="请输入"
|
clearable
|
@clear="handleSearch"
|
/>
|
</el-form-item>
|
|
<el-form-item label="文档类型" prop="resultType">
|
<el-select
|
class="gd-select gray"
|
popper-class="gd-select-popper"
|
v-model="searchParams.resultType"
|
placeholder="请选择"
|
clearable
|
@change="handleSearch"
|
>
|
<el-option
|
v-for="item in dictObj.patrolTaskType"
|
:key="item.dictKey"
|
:label="item.dictValue"
|
:value="item.dictKey"
|
/>
|
</el-select>
|
</el-form-item>
|
|
<el-form-item class="gd-search-actions">
|
<el-button :icon="RefreshRight" @click="resetForm"></el-button>
|
<el-button class="search-btn" :icon="Search" @click="handleSearch"></el-button>
|
</el-form-item>
|
</el-form>
|
|
<div class="gd-table-toolbar">
|
<el-button :icon="Download" color="#4C34FF" type="primary" @click="handleDownload">文档下载</el-button>
|
<el-button :icon="Upload" color="#4C34FF" type="primary" @click="handleUpload">文档上传</el-button>
|
</div>
|
|
<div class="gd-table-container" v-loading="loading">
|
<div class="gd-table-content gd-table-content-bg">
|
<el-table class="gd-table" :data="list" @selection-change="handleSelectionChange">
|
<el-table-column type="selection" width="46" />
|
<el-table-column type="index" width="64" label="序号" />
|
<el-table-column prop="nickName" show-overflow-tooltip label="文档名称" />
|
<el-table-column prop="attachSize" show-overflow-tooltip label="文档大小" />
|
<el-table-column prop="deptName" show-overflow-tooltip label="文档归属" />
|
<!-- <el-table-column prop="resultType" show-overflow-tooltip label="文档类型" /> -->
|
<el-table-column prop="resultType" show-overflow-tooltip label="文档类型">
|
<template v-slot="{ row }">
|
{{ getDictLabel(row.resultType, dictObj.patrolTaskType) }}
|
</template>
|
</el-table-column>
|
<el-table-column label="操作" class-name="operation-btns">
|
<template v-slot="{ row }">
|
<el-link @click="seeOnlineWord(row)">查看</el-link>
|
<el-link @click="openForm(row)">在线编辑</el-link>
|
<el-link @click="handleDelete(row)">删除</el-link>
|
</template>
|
</el-table-column>
|
</el-table>
|
</div>
|
|
<div class="gd-pagination-parent">
|
<el-pagination
|
popper-class="gd-select-popper"
|
v-model:current-page="searchParams.current"
|
v-model:page-size="searchParams.size"
|
layout="total, prev, pager, next, sizes"
|
:total="total"
|
@change="getList"
|
/>
|
</div>
|
</div>
|
<el-dialog
|
class="gd-dialog"
|
append-to-body
|
v-model="isShowEditView"
|
:title="titleTxt"
|
:width="pxToRem(800)"
|
:close-on-click-modal="false"
|
:destroy-on-close="true"
|
@close="handleClose"
|
>
|
<el-form class="gd-dialog-form" ref="ruleFormRef" :model="editParams" :rules="rules" label-width="140px">
|
<el-form-item label="文档名称" prop="nickName">
|
<el-input v-model="editParams.nickName" class="gd-input" placeholder="请输入" />
|
</el-form-item>
|
<el-form-item label="文档类型" prop="resultType" v-if="titleTxt === '上传巡查报告'">
|
<el-select
|
class="gd-select"
|
popper-class="gd-select-popper"
|
v-model="editParams.resultType"
|
placeholder="请选择"
|
clearable
|
>
|
<el-option
|
v-for="item in dictObj.patrolTaskType"
|
:key="item.dictKey"
|
:label="item.dictValue"
|
:value="item.dictKey"
|
/>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="上传文件" prop="link" v-if="titleTxt === '上传巡查报告'">
|
{{ uploadName }}
|
<el-upload class="avatar-uploader" action="" :show-file-list="false" :before-upload="onUploadFileBefore">
|
<el-button size="small" type="primary">点击上传</el-button>
|
</el-upload>
|
</el-form-item>
|
</el-form>
|
<!-- </div> -->
|
<template #footer>
|
<el-button color="#F2F3F5" @click="isShowEditView = false">取消</el-button>
|
<el-button
|
class="save-btn"
|
color="#4C34FF"
|
:loading="submitting"
|
:disabled="submitting"
|
@click="submit(ruleFormRef)"
|
>
|
保存
|
</el-button>
|
</template>
|
</el-dialog>
|
<PreviewFiles v-model="previewVisible" :src="searchUrl" type="docx" />
|
<!-- <el-image v-if="previewVisibleImg" :src="searchUrl" fit="contain" style="height: 100%;width: 100%" /> -->
|
<el-image-viewer
|
v-if="previewVisibleImg"
|
:url-list="[searchUrl]"
|
@close="previewVisibleImg = false"
|
></el-image-viewer>
|
</basic-container>
|
</template>
|
<script setup>
|
import { Search, RefreshRight, Download, Upload, Delete } from '@element-plus/icons-vue'
|
import { fjPageApi, fjSubmitApi, fjRemoveApi, fjDetailApi, fjUploadApi } from './inspectionRequestApi'
|
import { useStore } from 'vuex'
|
import { ref, computed, inject, onMounted } from 'vue'
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
import { getDictLabel } from '@ztzf/utils'
|
import PreviewFiles from '@/components/PreviewFiles/PreviewFiles.vue'
|
import { getDictionaryByCode } from '@/api/system/dictbiz'
|
|
const store = useStore()
|
const userInfo = computed(() => store.getters.userInfo)
|
|
// 初始化查询参数
|
const initSearchParams = () => ({
|
nickName: '',
|
resultType: '',
|
current: 1, // 当前页
|
size: 10, // 每页大小
|
})
|
|
// 查看文档
|
const previewVisible = ref(false)
|
const previewVisibleImg = ref(false)
|
const searchUrl = ref('')
|
|
// 上传名称
|
const uploadName = ref('')
|
|
const dictObj = ref({
|
patrolTaskType: [], // 巡查任务类型
|
})
|
|
const searchParams = ref(initSearchParams()) // 查询参数
|
const total = ref(0) // 总条数
|
const loading = ref(true) // 列表加载中
|
const list = ref([]) // 列表数据
|
const selectedIds = ref([]) // 勾选的ID列表
|
const selectedFiles = ref([]) // 勾选的文件列表
|
const queryParamsRef = ref(null) // 查询表单实例
|
|
const isShowEditView = ref(false)
|
const titleTxt = ref('上传巡查报告')
|
const editParams = ref({
|
id: '',
|
nickName: '',
|
resultType: '',
|
link: '',
|
})
|
const ruleFormRef = ref()
|
const submitting = ref(false)
|
const rules = ref({
|
nickName: [{ required: true, message: '请输入文档名称', trigger: ['blur'] }],
|
resultType: [{ required: true, message: '请选择文档类型', trigger: ['change'] }],
|
link: [{ required: true, message: '请上传文件', trigger: ['change'] }],
|
})
|
|
// 获取字典
|
function getDictList() {
|
getDictionaryByCode('patrolTaskType').then(res => {
|
dictObj.value = res.data.data
|
})
|
}
|
|
// 获取列表
|
async function getList() {
|
loading.value = true
|
try {
|
const res = await fjPageApi({ ...searchParams.value })
|
list.value = res?.data?.data?.records ?? []
|
total.value = res?.data?.data?.total ?? 0
|
} finally {
|
loading.value = false
|
}
|
}
|
|
// 重置查询
|
function resetForm() {
|
queryParamsRef.value?.resetFields()
|
searchParams.value.current = 1
|
getList()
|
}
|
|
// 查询
|
function handleSearch() {
|
searchParams.value.current = 1
|
getList()
|
}
|
|
// 新增/编辑/查看 弹框
|
function openForm(row) {
|
isShowEditView.value = true
|
titleTxt.value = '编辑'
|
editParams.value.id = row.id
|
editParams.value.nickName = row.nickName
|
editParams.value.resultType = row.resultType
|
editParams.value.link = row.link
|
}
|
|
// 在线查看文档
|
function seeOnlineWord(row) {
|
// 获取点之后的文件格式名
|
const fileType = row?.link?.split('.').pop() || ''
|
if (!row.link) {
|
ElMessage.warning('文件链接不存在')
|
return
|
} else if (
|
!row.link.includes('docx') &&
|
!row.link.includes('pdf') &&
|
!row.link.includes('png') &&
|
!row.link.includes('jpg')
|
) {
|
ElMessage.warning(`${fileType}文件格式,可以下载再查看`)
|
return
|
} else if (row.link.includes('png') || row.link.includes('jpg')) {
|
previewVisibleImg.value = true
|
searchUrl.value = row.link
|
return
|
} else if (row.link.includes('docx') || row.link.includes('pdf')) {
|
previewVisible.value = true
|
searchUrl.value = row.link
|
return
|
}
|
}
|
|
// 删除
|
async function handleDelete(row) {
|
const tips = row ? '该条' : '选中的项'
|
await ElMessageBox.confirm(`确认删除${tips}吗?`, '提示', {
|
type: 'warning',
|
customClass: 'gd-confirm-custom',
|
confirmButtonClass: 'gd-confirm-button',
|
cancelButtonClass: 'gd-confirm-cancel-button',
|
})
|
const ids = row ? row.id : selectedIds.value.join(',')
|
await fjRemoveApi({ ids })
|
ElMessage.success('删除成功')
|
selectedIds.value = []
|
getList()
|
}
|
|
// 勾选值设置
|
function handleSelectionChange(rows) {
|
selectedFiles.value = rows
|
selectedIds.value = rows.map(item => item.id)
|
}
|
|
// 文档下载
|
async function handleDownload() {
|
// 如果是勾选一个可以直接下载,超过一个打包下载
|
// 依次下载每个文件(添加延迟以避免浏览器限制)
|
if (selectedFiles.value.length === 0) {
|
ElMessage.warning('请选择要下载的文件')
|
return
|
}
|
selectedFiles.value.forEach((file, index) => {
|
setTimeout(() => {
|
if (file.link) {
|
const a = document.createElement('a')
|
a.href = file.link
|
a.download = file.originalName || `attachment_${index + 1}`
|
document.body.appendChild(a)
|
a.click()
|
document.body.removeChild(a)
|
}
|
}, index * 300) // 300ms delay between downloads
|
})
|
}
|
|
// 文档上传
|
async function handleUpload() {
|
isShowEditView.value = true
|
titleTxt.value = '上传巡查报告'
|
}
|
|
// 上传文件前处理
|
function onUploadFileBefore(file) {
|
// 执行文件上传
|
let data = new FormData()
|
data.append('file', file)
|
|
fjUploadApi(data).then(res => {
|
if (res.data.code === 200) {
|
ElMessage.success('上传成功')
|
// 保存文件URL到表单
|
uploadName.value = res.data.data.originalName
|
editParams.value.link = res.data.data.link
|
} else {
|
ElMessage.error(res.msg || '上传失败')
|
}
|
})
|
|
return false // 阻止组件的默认上传行为
|
}
|
|
// 保存上传文件数据
|
async function submit(formValidate) {
|
if (!formValidate) return
|
await formValidate.validate(async (valid, fields) => {
|
if (valid) {
|
submitting.value = true
|
try {
|
await fjSubmitApi({ ...editParams.value })
|
ElMessage.success('保存成功')
|
isShowEditView.value = false
|
getList()
|
} finally {
|
submitting.value = false
|
}
|
}
|
})
|
}
|
|
function handleClose() {
|
// 清除表单内容
|
uploadName.value = ''
|
editParams.value = {
|
id: '',
|
nickName: '',
|
resultType: '',
|
uploadFile: '',
|
}
|
}
|
|
onMounted(() => {
|
getDictList()
|
getList()
|
})
|
</script>
|
<style scoped lang="scss"></style>
|