<!-- 文件审批 --> <script name="FileApprovalList" lang="ts" setup> import { ElLoading, ElMessage, ElMessageBox } from 'element-plus' import type { DateModelType } from 'element-plus' import type { IFileApprovalForm, IListQuery } from './approval-interface' // import ApprovalDialog from '@/views/resource/common/approvalDialog.vue' import type { IMenu } from '@/components/buttonBox/buttonBox' import { exportFile } from '@/utils/exportUtils' import type { TableColumn } from '@/components/NormalTable/table_interface' import { getDictByCode } from '@/api/system/dict' import { approvalDelete, cancelApproval, draftDelete, exportFileApprovalList, getFileApprovalFormList, refuseApproval, rejectApproval } from '@/api/resource/fileApproval' import type { deptType } from '@/global' import { getFileChangeFormList } from '@/api/resource/fileChange' import useBridgeCount from '@/components/buttonBox/useBridgeCount' import ApprovalDialog from '@/components/Approval/ApprovalDialogCustom.vue' import customApproval from '/public/config/customApproval.json' // 定义常量 const buttonBoxActive = 'fileApproval' // 存储在sessionstorage里面的字段名,用于记录右上角buttonbox点击状态 const flowFormId = 'zyglwjsp' // 资源管理 - 文件审批 const { proxy } = getCurrentInstance() as any const router = useRouter() // 选中的审批状态按钮 const active = ref('') const menu = ref<IMenu[]>([]) // 审批状态按钮组合 const approvalStatusList = ref<String[]>([ '全部', '已审批', '待审批', '审批', '草稿箱', '审批中', '已通过', '未通过', '已取消', ]) // 弹窗子组件 const apprDial = ref() // 查询条件 const searchQuery = ref<IListQuery>({ approvalStatus: active.value, // 审批状态类型code,导出接口不用传 beginTime: '', // 开始时间 createUserName: '', // 创建人 endTime: '', // 结束时间 fileChangeCode: '', // 文件更改申请单 fileName: '', // 文件名称 fileNo: '', // 文件编号 fileType: '', // 文件类别(字典code) fileVersion: '', // 版本号 formId: flowFormId, // 表单id(流程定义对应的表单id,等价于业务id),导出接口不用传 groupCode: '', // 部门 labCode: '', // 实验室 offset: 1, limit: 20, }) const total = ref(0) // 数据条数 const totalToApproval = ref(0) // 待审批数据条数 const totalApproval = ref(0) // 审批中数据条数 const totalRefuse = ref(0) // 未通过数据条数 const loadingTable = ref(false) // 表格loading // 表头 const columns = ref<TableColumn[]>([ { text: '实验室', value: 'labCodeName', align: 'center', width: '120' }, { text: '部门', value: 'groupCodeName', align: 'center', width: '120' }, { text: '文件类型', value: 'fileTypeName', align: 'center' }, { text: '文件编号', value: 'fileNo', align: 'center' }, { text: '文件名称', value: 'fileName', align: 'center' }, { text: '版本号', value: 'fileVersion', align: 'center' }, { text: '文件更改申请单', value: 'fileChangeApplyCode_hide', width: '180', align: 'center', followLink: true }, { text: '创建人', value: 'createUserName', align: 'center' }, { text: '创建时间', value: 'createTime', align: 'center', width: '180' }, ]) const statusColumn = ref<TableColumn>({ text: '审批状态', value: 'approvalStatusName', align: 'center', width: '100' }) const fileApprovalFormList = ref<Array<IFileApprovalForm>>([]) // 表格数据 const dateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据 const checkoutList = ref<string[]>([]) // 选中的内容 // -----------------------------------------字典-------------------------------------------------------------- const useDeptList = ref<deptType[]>([]) // 部门 const labDeptList = ref<deptType[]>([]) // 实验室 const fileTypeList = ref<deptType[]>([]) // 文件类型 // 查询字典 const getDictFun = () => { // 实验室 getDictByCode('bizLabCode').then((response) => { labDeptList.value = response.data }) // 部门 getDictByCode('bizGroupCode').then((response) => { useDeptList.value = response.data }) // 文件类型 getDictByCode('bizFileType').then((response) => { fileTypeList.value = response.data }) } // ----------------------------------------列表数据---------------------------------------------------- // 跳转到新建的页面 const addFileApproval = () => { router.push({ query: { type: 'add', status: searchQuery.value.approvalStatus, }, path: 'approval/detail', }) } // 点击编辑按钮 const updateInfo = (row: IFileApprovalForm) => { router.push({ query: { type: 'edit', id: row.id, status: searchQuery.value.approvalStatus, approvalStatusName: row.approvalStatusName, processId: row.processId, // 流程实例id taskId: row.taskId, // 任务id decisionItem: row.decisionItem, }, path: 'approval/detail', }) } // 点击查看(或编辑)按钮 const detail = (row: IFileApprovalForm) => { if (row.approvalStatus === '1' || row.approvalStatus === '6') { // 全部或草稿箱 状态的 查看 是可以编辑的组件 updateInfo(row) } else { router.push({ query: { type: 'detail', id: row.id, status: searchQuery.value.approvalStatus, approvalStatusName: active.value === '0' ? '全部' : active.value === '7' ? '已审批' : row.approvalStatusName, // 审批状态名称 processId: row.processId, // 流程实例id taskId: row.taskId, // 任务id decisionItem: row.decisionItem, }, path: 'approval/detail', }) } } // 删除草稿箱中的审批单 const deleteById = (row: any) => { ElMessageBox.confirm(`是否删除文件审批单${row.fileNo}`, '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }).then(() => { if (active.value === '1') { draftDelete({ id: row.id }).then((res) => { if (res.code === 200) { ElMessage.success('删除成功') fetchData(true) } else { ElMessage.error('删除失败') } }) } else if (active.value === '6') { approvalDelete({ id: row.id, taskId: row.taskId }).then((res) => { if (res.code === 200) { ElMessage.success('删除成功') fetchData(true) } else { ElMessage.error('删除失败') } }) } }) } // 数据查询 function fetchData(isNowPage = false) { loadingTable.value = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 searchQuery.value.offset = 1 } if (searchQuery.value.approvalStatus === '10') { searchQuery.value.approvalStatus = '' } // 审批状态不允许传字典要求传'' getFileApprovalFormList(searchQuery.value).then((response) => { if (response.code === 200) { fileApprovalFormList.value = response.data.rows.map((item: { createTime: string; fileChangeApplyCode: string }) => { return { ...item, // fileChangeApplyCode: item.fileChangeApplyCode ? item.fileChangeApplyCode : '/', // 文件更改申请单编号 followLinkArr: [item.fileChangeApplyCode], fileChangeApplyCode_hide: item.fileChangeApplyCode ? '' : '/', } }) total.value = parseInt(response.data.total) } loadingTable.value = false }).catch(() => { loadingTable.value = false }) // 获取待审批,审批中,未通过数据数量 useBridgeCount(searchQuery.value).then((res: any) => { totalToApproval.value = res.totalToApproval // 待审批数据条数 totalApproval.value = res.totalApproval // 审批中数据条数 totalRefuse.value = res.totalRefuse // 未通过数据条数 }) } const searchList = () => { fetchData(true) } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 const changePage = (val: { size?: number; page?: number }) => { if (val && val.size) { searchQuery.value.limit = val.size } if (val && val.page) { searchQuery.value.offset = val.page } fetchData(true) } // 重置 const reset = () => { searchQuery.value = { approvalStatus: active.value, // 审批状态类型code,导出接口不用传 beginTime: '', // 开始时间 createUserName: '', // 创建人 endTime: '', // 结束时间 fileChangeCode: '', // 文件更改申请单 fileName: '', // 文件名称 fileNo: '', // 文件编号 fileType: '', // 文件类别(字典code) fileVersion: '', // 版本号 formId: flowFormId, // 表单id(流程定义对应的表单id,等价于业务id),导出接口不用传 groupCode: '', // 部门 labCode: '', // 实验室 offset: 1, limit: 20, } dateRange.value = ['', ''] fetchData(true) } // 审批按钮点击切换事件 const changeCurrentButton = (val: string) => { active.value = val // 此时的tab window.sessionStorage.setItem(buttonBoxActive, val) // 记录tab状态 const hasStatus = columns.value.filter((col) => { return col.value === statusColumn.value.value }) if (val === '0') { // 全部的时候不要显示审批状态 if (hasStatus.length > 0) { columns.value.pop() } } else { // 其他状态下要显示审批状态字段 if (hasStatus.length === 0) { columns.value.push(statusColumn.value) } } reset() // 刷新 } // 流程审批-同意 const approvalAgreeHandler = (row: IFileApprovalForm) => { apprDial.value.initDialog('agree', row.taskId, row.id, row.processId) } // 流程审批-驳回 const approvalRejectHandler = (row: IFileApprovalForm) => { apprDial.value.initDialog('reject', row.taskId, row.id) } // 流程审批-拒绝 const approvalRefuseHandler = (row: IFileApprovalForm) => { apprDial.value.initDialog('refuse', row.taskId, row.id) } // 取消(撤回审批单) const revokeApprById = (row: IFileApprovalForm) => { const params = { processInstanceId: row.processId!, comments: '', id: row.id, } ElMessageBox.confirm( '确认取消该审批吗?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ) .then(() => { cancelApproval(params).then((res) => { ElMessage({ type: 'success', message: '已取消', }) fetchData(true) }) }) } // 流程操作之后刷新 const afterApprovalHandler = () => { fetchData(true) } // 拒绝 const approvalFormRefuseHandler = (comments: string, taskId: string, id: string) => { const param = { id, taskId, // 任务id comments, // 拒绝原因 } refuseApproval(param).then((res) => { if (res.code === 200) { ElMessage.success('已拒绝') } else { ElMessage.error(`拒绝失败:${res.message}`) } fetchData(true) }) } // 驳回 const reject = (comments: string, taskId: string, id: string) => { const params = { id, taskId, // 任务id comments, // 拒绝原因 } rejectApproval(params).then((res) => { ElMessage({ type: 'success', message: '已驳回', }) fetchData(true) }) } // 初始化流程审批状态按钮 const getApprovalStatusDict = async () => { await getDictByCode('approvalStatus').then((res) => { if (res.code === 200) { approvalStatusList.value.forEach((item) => { const tempFindData = res.data.find((e: { name: string; value: string }) => e.name === item) if (tempFindData) { menu.value.push({ name: tempFindData.name, id: `${tempFindData.value}`, }) } }) } }) } const getDict = async () => { await getApprovalStatusDict() getDictFun() // 获取实验室、部门 } // 多选发生改变时 function handleSelectionChange(e: any) { checkoutList.value = e.map((item: { id: string }) => item.id) } // 导出 const exportAll = () => { const loading = ElLoading.service({ lock: true, text: '下载中请稍后', background: 'rgba(255, 255, 255, 0.8)', }) if (fileApprovalFormList.value.length > 0) { const params = { approvalStatus: searchQuery.value.approvalStatus, // 审批状态类型code,导出接口不用传 beginTime: searchQuery.value.beginTime, // 开始时间 createUserName: searchQuery.value.createUserName, // 创建人 endTime: searchQuery.value.endTime, // 结束时间 fileChangeCode: searchQuery.value.fileChangeCode, // 文件更改申请单 fileName: searchQuery.value.fileName, // 文件名称 fileNo: searchQuery.value.fileNo, // 文件编号 fileType: searchQuery.value.fileType, // 文件类别(字典code) fileVersion: searchQuery.value.fileVersion, // 版本号 groupCode: searchQuery.value.groupCode, // 部门 labCode: searchQuery.value.labCode, // 实验室 offset: 1, limit: 20, ids: checkoutList.value, } exportFileApprovalList(params).then((res) => { const blob = new Blob([res.data]) loading.close() exportFile(blob, '文件审批列表.xlsx') }) loading.close() } else { loading.close() ElMessage.warning('无数据可导出数据') } } // 点击文件更改申请单 const handleClickFollowLink = async (row: any, title: string) => { const params = { approvalStatus: '0', // 审批状态类型code,导出接口不用传 beginTime: '', // 开始时间 changeReason: '', // 更改原因 createUserName: '', // 创建人 endTime: '', // 结束时间 fileName: '', // 文件名称 fileNo: '', // 文件编号(可用于体系文件详情中查询文件发放通知单列表) fileType: '', // 文件类别(字典code) formId: 'zyglwjggsq', // 表单id(流程定义对应的表单id,等价于业务id),导出接口不用传 formName: '', // 通知单名称 formNo: title, // 通知单编号 groupCode: '', // 部门 labCode: '', // 实验室 offset: 1, limit: 20, } const loading = ElLoading.service() const response = await getFileChangeFormList(params) if (response.data && response.data.rows && response.data.rows.length) { const row = response.data.rows[0] router.push({ query: { id: row.id, processId: row.processId, taskId: row.taskId, }, path: '/file/change/approved/detail', }) } loading.close() } watch(() => active.value, (val) => { if (val === '10') { // 审批把审批状态加上 if (columns.value[columns.value.length - 1].value !== 'approvalStatusName') { columns.value.push({ text: '审批状态', value: 'approvalStatusName', align: 'center' }) } } else { // 其他不显示审批状态 if (columns.value[columns.value.length - 1].value === 'approvalStatusName') { columns.value.pop() } } }, { immediate: true }) watch(dateRange, (val) => { if (val) { searchQuery.value.beginTime = `${val[0]}` searchQuery.value.endTime = `${val[1]}` } else { searchQuery.value.beginTime = '' searchQuery.value.endTime = '' } }) onMounted(async () => { await getDict() if (sessionStorage.getItem(buttonBoxActive) !== undefined && sessionStorage.getItem(buttonBoxActive) !== null) { active.value = sessionStorage.getItem(buttonBoxActive)! } else { active.value = '0' // 全部 } }) </script> <template> <app-container> <!-- 筛选条件 --> <search-area :need-clear="true" @search="searchList" @clear="reset"> <search-item> <el-select v-model="searchQuery.labCode" placeholder="实验室" class="short-input" filterable clearable > <el-option v-for="item in labDeptList" :key="item.id" :label="item.name" :value="item.value" /> </el-select> </search-item> <search-item> <el-select v-model="searchQuery.groupCode" placeholder="部门" class="short-input" filterable clearable > <el-option v-for="item in useDeptList" :key="item.id" :label="item.name" :value="item.value" /> </el-select> </search-item> <search-item> <el-select v-model="searchQuery.fileType" class="short-input" placeholder="文件类型" clearable> <el-option v-for="item in fileTypeList" :key="item.id" :value="item.value" :label="item.name" /> </el-select> </search-item> <search-item> <el-input v-model.trim="searchQuery.fileNo" placeholder="文件编号" clearable /> </search-item> <search-item> <el-input v-model.trim="searchQuery.fileName" placeholder="文件名称" clearable /> </search-item> <search-item> <el-input v-model.trim="searchQuery.fileVersion" placeholder="版本号" clearable /> </search-item> <search-item> <el-input v-model.trim="searchQuery.fileChangeCode" placeholder="文件更改申请单" clearable /> </search-item> <search-item> <el-input v-model.trim="searchQuery.createUserName" placeholder="创建人" clearable /> </search-item> <search-item> <el-date-picker v-model="dateRange" class="short-input" type="datetimerange" range-separator="至" format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss" start-placeholder="创建时间(开始)" end-placeholder="创建时间(结束)" /> </search-item> </search-area> <!-- 表格数据展示 --> <table-container> <!-- 表头区域 --> <template #btns-right> <icon-button v-if="proxy.hasPerm('/resource/file/approval/add') && active === '0'" icon="icon-add" title="新建" @click="addFileApproval" /> <icon-button v-if="active === '0'" icon="icon-export" title="导出" @click="exportAll" /> </template> <!-- 表格区域 --> <normal-table :data="fileApprovalFormList" :total="total" :columns="columns" :query="{ limit: searchQuery.limit, offset: searchQuery.offset }" :list-loading="loadingTable" is-showmulti-select @change="changePage" @multi-select="handleSelectionChange" @handle-click-follow-link="handleClickFollowLink" > <template #preColumns> <el-table-column label="序号" width="55" align="center"> <template #default="scope"> {{ (searchQuery.offset - 1) * searchQuery.limit + scope.$index + 1 }} </template> </el-table-column> </template> <template #columns> <el-table-column fixed="right" label="操作" align="center" width="180"> <template #default="{ row }"> <el-button size="small" type="primary" link @click="detail(row)"> 查看 </el-button> <el-button v-if="(row.approvalStatus === '1' || row.approvalStatus === '6') && proxy.hasPerm('/resource/file/approval/del')" size="small" type="danger" link @click="deleteById(row)"> 删除 </el-button> <template v-if="row.approvalStatus === '2'"> <el-button size="small" type="primary" link @click="approvalAgreeHandler(row)"> 同意 </el-button> <el-button v-if="`${row.decisionItem}` === '1' || `${row.decisionItem}` === '2'" size="small" link type="warning" @click="approvalRejectHandler(row)" > 驳回 </el-button> <el-button v-if="`${row.decisionItem}` === '1' || `${row.decisionItem}` === '3'" size="small" type="danger" link @click="approvalRefuseHandler(row)"> 拒绝 </el-button> </template> <template v-if="row.approvalStatus === '3'"> <el-button size="small" type="info" link @click="revokeApprById(row)"> 取消 </el-button> </template> </template> </el-table-column> </template> </normal-table> </table-container> <!-- 审批单弹窗 --> <!-- <approval-dialog ref="apprDial" @on-success="afterApprovalHandler" @on-refuse="approvalFormRefuseHandler" /> --> <!-- 审批弹窗-审批人自选 --> <approval-dialog ref="apprDial" :last-name="customApproval.approvalLastName.fileApproval" approval-module="fileApproval" @on-success="afterApprovalHandler" @refuse="approvalFormRefuseHandler" @reject="reject" /> <!-- 右上角按钮集合 --> <button-box :active="active" :total-refuse="totalRefuse" :total-approval="totalApproval" :total-to-approval="totalToApproval" :menu="menu" @change-current-button="changeCurrentButton" /> </app-container> </template>