<!-- 文件审批公共模板 --> <script lang="ts" setup> import { ElLoading, ElMessage, ElMessageBox } from 'element-plus' import type { TableRow } from './approve-interface' import type { fileResType } from '@/views/measure/file/file-interface' import { printJSON } from '@/utils/printUtils' import { approvalCancel, approvalDelete, approvallistPageApi, approvallistPageDetailApi, deleteApi, exportFileApi, submitFile } from '@/api/measure/file' import ApprovalDialog from '@/components/Approval/ApprovalDialog.vue' import { getDictByCode } from '@/api/system/dict' import { exportFile } from '@/utils/exportUtils' import { SCHEDULE } from '@/utils/scheduleDict' import type { TableColumn } from '@/components/NormalTable/table_interface' const props = defineProps({ name: { type: String, default: '', }, approvalStatusMap: { type: Object, default: () => { return {} }, }, approvalStatusReserveMap: { type: Object, default: () => { return {} }, }, }) const { proxy } = getCurrentInstance() as any const $router = useRouter() const approvalStatus = ref('0') // 审批状态字典 const approvalStatusMap = ref({ ...props.approvalStatusMap }) // 审批状态字典{1:草稿箱} const approvalStatusReserveMap = ref({ ...props.approvalStatusReserveMap }) // 审批状态字典{草稿箱: 1} const activeTitle = ref('') // active对应的审批状态名字 watch(() => props.name, () => { activeTitle.value = props.name approvalStatus.value = approvalStatusReserveMap.value[props.name] }, { deep: true, immediate: true }) const searchQuery = reactive({ fileNo: '', // 编号 fileName: '', // 名称 fileCode: '', // 文件号 createUser: '', // 创建人 createTime: '', // 创建 approvalStatus: approvalStatus.value || '0', // 审批状态 limit: 20, offset: 1, fileType: '', // 文件类别 formId: SCHEDULE.FILE_APPROVAL, ids: [] as string[], }) // 查询参数 const loadingTable = ref<boolean>(false) // 表格loading const total = ref<number>(0) // 数据总条数 const columns = ref<TableColumn[]>([ { text: '名称', value: 'fileName', align: 'center' }, { text: '编号', value: 'fileNo', align: 'center' }, { text: '文件号', value: 'fileCode', align: 'center' }, { text: '类别', value: 'fileType', align: 'center' }, { text: '创建人', value: 'create', align: 'center' }, { text: '创建时间', value: 'createTime', align: 'center' }, { text: '审批状态', value: 'approvalStatusName', align: 'center' }, ]) // 表格 const list = ref<TableRow[]>([]) // 表格数据 // 获取数据列表 const getList = () => { loadingTable.value = true approvallistPageApi(searchQuery).then((res) => { if (res.code === 200) { list.value = res.data.rows.map((item: TableRow) => { return { ...item, approvalStatus: approvalStatusMap.value[item.approvalStatus], } }) total.value = res.data.total } loadingTable.value = false }).catch((_) => { loadingTable.value = false }) } const fileTypeList = ref<fileResType[]>([]) // 获取文件类别 const getFileType = () => { getDictByCode('fileType').then((res) => { fileTypeList.value = res.data }) } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 const changePage = (val: { size?: number; page?: number }) => { if (val && val.size) { searchQuery.limit = val.size } if (val && val.page) { searchQuery.offset = val.page } getList() } // 详情 const detail = (row: TableRow) => { $router.push({ name: 'approveDetail', query: { title: '详情', ...row, }, }) } const edit = (row: TableRow) => { $router.push({ name: 'approveDetail', query: { title: '编辑', ...row, }, }) } // 删除 const remove = (row: TableRow) => { ElMessageBox.confirm( `确认删除${row.fileName}吗?`, '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ) .then(() => { if (row.approvalStatusName == '待审批') { approvalDelete({ id: row.id, taskId: row.taskId }).then((res) => { if (res.code === 200) { ElMessage({ type: 'success', message: '删除成功', }) getList() } }) } else { deleteApi({ id: row.id }).then((res) => { if (res.code === 200) { ElMessage({ type: 'success', message: '删除成功', }) getList() } }) } }) } // 取消 const cancel = (row: TableRow) => { const { processId } = row ElMessageBox.confirm( `确认取消${row.fileName}吗?`, '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ) .then(() => { approvalCancel({ processInstanceId: processId }).then((res) => { if (res.code === 200) { ElMessage({ type: 'success', message: '取消成功', }) getList() } }) }) } // 提交 const submit = (row: TableRow) => { const { id } = row ElMessageBox.confirm( `确认提交${row.fileName}吗?`, '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ) .then(() => { submitFile({ id, formId: SCHEDULE.FILE_APPROVAL }).then((res) => { if (res.code === 200) { ElMessage({ type: 'success', message: '提交成功', }) getList() } }) }) } // 搜索 const search = () => { getList() } // 审批结束回调 const approvalSuccess = () => { search() } const approvalDialog = ref() // 审批操作 const approval = (type: string, processId: string) => { approvalDialog.value.initDialog(type, processId) } // 重置 const reset = () => { searchQuery.fileNo = '' searchQuery.fileName = '' searchQuery.fileCode = '' getList() } // 表格被选中的行 const selectList = ref<TableRow[]>([]) // 表格多选 const multiSelect = (row: TableRow[]) => { selectList.value = row } // 导出 const exportExcelBtn = () => { const loading = ElLoading.service({ lock: true, text: 'Loading', background: 'rgba(255, 255, 255, 0.8)', }) searchQuery.ids = [] if (selectList.value.length) { selectList.value.forEach((item) => { searchQuery.ids?.push(item.id as string) }) } exportFileApi({ ...searchQuery, limit: undefined, offset: undefined }).then((res) => { exportFile(res.data, props.name) loading.close() searchQuery.ids = [] }).catch((_) => { loading.close() }) } // 打印 function printList() { const selectIds = selectList.value.map(item => item.id) const properties = columns.value.map((item) => { return { field: item.value, displayName: item.text, } }) if (selectIds.length <= 0 && list.value.length > 0) { printJSON(list.value, properties, props.name) } else if (selectIds.length > 0) { const printList = list.value.filter(item => selectIds.includes(item.id)) printJSON(printList, properties, props.name) } else { ElMessage('无可打印内容') } } onMounted(() => { getFileType() getList() }) </script> <template> <div> <!-- 布局 --> <app-container> <!-- 筛选条件 --> <search-area :need-clear="true" @search="search" @clear="reset"> <search-item> <el-input v-model="searchQuery.fileNo" placeholder="编号" clearable class="w-50 m-2" /> </search-item> <search-item> <el-input v-model="searchQuery.fileName" placeholder="名称" clearable class="w-50 m-2" /> </search-item> <search-item> <el-input v-model="searchQuery.fileCode" placeholder="文件号" clearable class="w-50 m-2" /> </search-item> <search-item> <el-select v-model="searchQuery.fileType" class="m-2" placeholder="文件类别" clearable> <el-option v-for="item in fileTypeList" :key="item.id" :label="item.name" :value="item.value" /> </el-select> </search-item> <search-item> <el-date-picker v-model="searchQuery.createTime" type="datetime" format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss" placeholder="创建时间" /> </search-item> <search-item> <el-input v-model="searchQuery.createUser" placeholder="创建人" clearable class="w-50 m-2" /> </search-item> </search-area> <table-container> <!-- 表头区域 --> <template #btns-right> <icon-button v-if="proxy.hasPerm('/file/approve/export')" icon="icon-export" title="导出" @click="exportExcelBtn" /> <icon-button v-if="proxy.hasPerm('/file/approve/print')" icon="icon-print" title="打印" @click="printList" /> </template> <!-- 表格区域 --> <normal-table id="print" :data="list" :total="total" :columns="columns" :query="{ limit: searchQuery.limit, offset: searchQuery.offset }" :list-loading="loadingTable" :is-showmulti-select="true" :is-multi="true" @change="changePage" @multi-select="multiSelect" > <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 label="操作" align="center" width="250"> <template #default="{ row }"> <el-button size="small" type="primary" link @click="detail(row)"> 查看 </el-button> <el-button v-if="proxy.hasPerm('/file/approve/edit') && ['草稿箱', '已取消'].includes(activeTitle)" size="small" type="primary" link @click="edit(row)"> 编辑 </el-button> <el-button v-if="proxy.hasPerm('/file/approve/edit') && ['草稿箱', '已取消'].includes(activeTitle)" size="small" type="primary" link @click="submit(row)"> 提交 </el-button> <template v-if="['全部', '待审批'].includes(activeTitle)"> <el-button v-if="proxy.hasPerm('/file/approve/agree')" size="small" type="primary" link :disabled="row.approvalStatusName !== '待审批'" @click="approval('agree', row.taskId)"> 同意 </el-button> <el-button v-if="proxy.hasPerm('/file/approve/reject')" size="small" type="primary" link :disabled="row.approvalStatusName !== '待审批' || row.decisionItem === 3" @click="approval('reject', row.taskId)"> 驳回 </el-button> <el-button v-if="proxy.hasPerm('/file/approve/refuse')" size="small" type="primary" link :disabled="row.approvalStatusName !== '待审批' || row.decisionItem === 1 || row.decisionItem === 2" @click="approval('refuse', row.taskId)"> 拒绝 </el-button> </template> <el-button v-if="proxy.hasPerm('/file/approve/cancle') && ['审批中', '全部'].includes(activeTitle)" size="small" type="primary" link @click="cancel(row)"> 取消 </el-button> <el-button v-if="proxy.hasPerm('/file/approve/delete') && !['已通过', '未通过'].includes(activeTitle)" size="small" type="danger" link @click="remove(row)"> 删除 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> <approval-dialog ref="approvalDialog" @on-success="approvalSuccess" /> </app-container> </div> </template> <style lang="scss" scoped> .normal-input { width: 170px !important; } .normal-date { width: 170px !important; } .normal-select { width: 170px !important; } :deep(.el-table__header) { background-color: #bbb; } </style>