<!-- 软件修订申请 --> <script name="RevisionApplyList" lang="ts" setup> import type { DateModelType } from 'element-plus' import { ElLoading, ElMessage, ElMessageBox, dayjs } from 'element-plus' import type { IListQuery, IRevisionApply } from './software-revision' import ApprovalDialog from '@/views/resource/common/approvalDialog.vue' import { SCHEDULE } from '@/utils/scheduleDict' import type { IMenu } from '@/components/buttonBox/buttonBox' import type { TableColumn } from '@/components/NormalTable/table_interface' import { deleteDraft, deleteRevoked, exportSoftwareRevisionList, getRevisionApplyList, refuseApproval, revokeApproval } from '@/api/resource/softwareRevision' import { getDictByCode } from '@/api/system/dict' import { exportFile } from '@/utils/exportUtils' import type { deptType } from '@/global' const { proxy } = getCurrentInstance() as any const router = useRouter() // 定义常量 const buttonBoxActive = 'softwareRevisionApplyApproval' // 存储在sessionstorage里面的字段名,用于记录右上角buttonbox点击状态 // 选中的审批状态按钮 const active = ref('') const menu = ref<IMenu[]>([]) // 审批状态按钮组合 const approvalStatusList = ref<String[]>([ '全部', '已审批', '待审批', '审批', '草稿箱', '审批中', '已通过', '未通过', '已取消', ]) // 弹窗子组件 const apprDial = ref() // 查询条件 const searchQuery = ref<IListQuery>({ applyNo: '', softwareName: '', // 软件名称 softwareVersion: '', createDept: '', createUserName: '', // 申请人 createTimeStart: '', // 申请时间 createTimeEnd: '', // 申请时间 approvalStatus: active.value, // 审批状态 formId: SCHEDULE.SOFTWARE_REVISION_APPROVAL, revisionReason: '', // 软件修订原因 groupCode: '', // 部门 labCode: '', // 实验室 offset: 1, limit: 20, }) const total = ref(0) // 数据条数 const loadingTable = ref(false) // 表格loading const dateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据 // 表头 const columns = ref<TableColumn[]>([ { text: '实验室', value: 'labCodeName', align: 'center' }, { text: '部门', value: 'groupCodeName', align: 'center' }, { text: '文件编号', value: 'applyNo', align: 'center', width: '180' }, { text: '软件名称', value: 'softwareName', align: 'center' }, { text: '版本号', value: 'softwareVersion', align: 'center' }, { text: '软件修订原因', value: 'revisionReason', align: 'center' }, { text: '申请部门', value: 'createDept', align: 'center' }, { text: '申请人', value: 'createUserName', align: 'center', width: '120' }, { text: '申请时间', value: 'createTime', align: 'center', width: '120' }, { text: '审批状态', value: 'approvalStatusName', align: 'center', width: '100' }, ]) const dataList = ref<Array<IRevisionApply>>([]) // 表格数据 const checkoutList = ref<Array<IRevisionApply>>([]) // 多选表格数据 // 多选发生改变时 function handleSelectionChange(e: any) { checkoutList.value = e.map((item: { id: string }) => item.id) } // 跳转到新建的页面 const addRevisionApply = () => { router.push({ query: { type: 'create', status: searchQuery.value.approvalStatus, }, path: 'revision/detail', }) } // 点击编辑按钮 const updateInfo = (row: IRevisionApply) => { sessionStorage.setItem('revisionApplyTaskId', row.taskId!) router.push({ query: { type: 'update', id: row.id, status: row.approvalStatus, processId: row.processId, taskId: row.taskId, }, path: 'revision/detail', }) } // 详情 const detail = (row: IRevisionApply) => { if (active.value === '1') { // 全部或草稿箱 状态的 查看 是可以编辑的组件 updateInfo(row) } else if (active.value === '0') { router.push({ query: { type: 'apply', id: row.id, status: row.approvalStatus, processId: row.processId, taskId: row.taskId, }, path: 'revision/approved', }) } else { // 将行数据存入缓存 用来在路由之间传递数据 sessionStorage.setItem('revisionApplyTaskId', row.taskId!) router.push({ query: { type: 'detail', id: row.id, status: row.approvalStatus, processId: row.processId, taskId: row.taskId, }, path: 'revision/detail', }) } } // 数据查询 function fetchData(isNowPage = false) { loadingTable.value = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 searchQuery.value.offset = 1 } if (searchQuery.value.approvalStatus === '10') { searchQuery.value.approvalStatus = '' } // 审批状态不允许传字典要求传'' getRevisionApplyList(searchQuery.value).then((response) => { if (response.code === 200) { dataList.value = response.data.rows.map((item: IRevisionApply) => { return { ...item, createTime: item.createTime!.length > 16 ? item.createTime!.substring(0, 10) : '', } }) total.value = parseInt(response.data.total) } loadingTable.value = false }).catch(() => { loadingTable.value = false }) } const searchList = () => { fetchData(true) } // 删除 const deleteById = (row: IRevisionApply) => { ElMessageBox.confirm(`是否修订申请 ${row.applyNo}`, '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }).then(() => { if (active.value === '1') { // 草稿箱中的删除记录 deleteDraft({ id: row.id }).then((res) => { if (res.code === 200) { ElMessage.success('软件修订申请删除成功') fetchData() } else { ElMessage.error(`软件修订申请删除失败: ${res.message}`) } }) } else if (active.value === '6') { // 已取消中的删除记录 deleteRevoked({ id: row.id, taskId: row.taskId }).then((res) => { if (res.code === 200) { ElMessage.success('软件修订申请删除成功') fetchData() } else { ElMessage.error(`软件修订申请删除失败: ${res.message}`) } }) } }) } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 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 = { applyNo: '', softwareName: '', // 软件名称 softwareVersion: '', createDept: '', createUserName: '', // 申请人 createTimeStart: '', // 申请时间 createTimeEnd: '', // 申请时间 approvalStatus: active.value, // 审批状态 formId: SCHEDULE.SOFTWARE_REVISION_APPROVAL, revisionReason: '', // 软件修订原因 groupCode: '', // 部门 labCode: '', // 实验室 offset: 1, limit: 20, } fetchData(true) } // ----------------------------------------------审批------------------------------------------------ // 审批按钮点击切换事件 const changeCurrentButton = (val: string) => { active.value = val // 此时的tab window.sessionStorage.setItem(buttonBoxActive, val) // 记录tab状态 reset() // 刷新 } // 流程审批-同意 const approvalAgreeHandler = (row: IRevisionApply) => { apprDial.value.initDialog('agree', row.id, row.taskId, '') } // 流程审批-拒绝 const approvalRefuseHandler = (row: IRevisionApply) => { apprDial.value.initDialog('refuse', row.id, row.taskId, '') } // 取消(撤回审批单) const revokeApprById = (row: IRevisionApply) => { const params = { processInstanceId: row.processId!, comments: '', id: row.id, } ElMessageBox.confirm( '确认取消该审批吗?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ) .then(() => { const loading = ElLoading.service({ lock: true, text: '正在取消中,请耐心等待...', background: 'rgba(255, 255, 255, 0.6)', }) revokeApproval(params).then((res) => { loading.close() ElMessage({ type: 'success', message: '已取消', }) fetchData(true) }) }) } // 流程操作之后刷新 const afterApprovalHandler = () => { fetchData(true) } // 拒绝 const refuseHandler = (param: any) => { const loading = ElLoading.service({ lock: true, text: '加载中...', background: 'rgba(255, 255, 255, 0.6)', }) refuseApproval(param).then((res) => { if (res.code === 200) { ElMessage.success('拒绝审批完成') } else { ElMessage.error(`拒绝审批失败:${res.message}`) } // 关闭弹窗 apprDial.value.handleClose() loading.close() fetchData(true) }) } // 初始化流程审批状态按钮 const getApprovalStatusDict = () => { 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 exportAll = () => { const loading = ElLoading.service({ lock: true, text: '下载中请稍后', background: 'rgba(255, 255, 255, 0.8)', }) if (dataList.value.length > 0) { const params = { applyNo: searchQuery.value.applyNo, softwareName: searchQuery.value.softwareName, // 软件名称 softwareVersion: searchQuery.value.softwareVersion, createDept: searchQuery.value.createDept, createUserName: searchQuery.value.createUserName, // 申请人 createTimeStart: searchQuery.value.createTimeStart, // 申请时间 createTimeEnd: searchQuery.value.createTimeEnd, // 申请时间 approvalStatus: searchQuery.value.approvalStatus, // 审批状态 formId: searchQuery.value.formId, revisionReason: searchQuery.value.revisionReason, // 软件修订原因 groupCode: searchQuery.value.groupCode, // 部门 labCode: searchQuery.value.labCode, // 实验室 offset: 1, limit: 20, ids: checkoutList.value, } exportSoftwareRevisionList(params).then((res) => { const blob = new Blob([res.data]) loading.close() exportFile(blob, '软件修订申请.xlsx') }) loading.close() } else { loading.close() ElMessage.warning('无数据可导出数据') } } // --------------------------------------字典----------------------------------------------- const useDeptList = ref<deptType[]>([]) // 部门 const labDeptList = ref<deptType[]>([]) // 实验室 // 查询字典 const getDictFun = () => { // 实验室 getDictByCode('bizLabCode').then((response) => { labDeptList.value = response.data }) // 部门 getDictByCode('bizGroupCode').then((response) => { useDeptList.value = response.data }) } // -------------------------------------------------------------------------------------------------- const getDict = async () => { getApprovalStatusDict() getDictFun() } watch(dateRange, (val) => { if (val) { searchQuery.value.createTimeStart = dayjs(val[0]).format('YYYY-MM-DD') === 'Invalid Date' ? '' : dayjs(val[0]).format('YYYY-MM-DD') searchQuery.value.createTimeEnd = dayjs(val[1]).format('YYYY-MM-DD') === 'Invalid Date' ? '' : dayjs(val[1]).format('YYYY-MM-DD') } else { searchQuery.value.createTimeStart = '' searchQuery.value.createTimeEnd = '' } }) 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 }) 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-input v-model="searchQuery.applyNo" placeholder="文件编号" clearable /> </search-item> <search-item> <el-input v-model="searchQuery.softwareName" placeholder="软件名称" clearable /> </search-item> <search-item> <el-input v-model="searchQuery.softwareVersion" placeholder="版本号" clearable /> </search-item> <search-item> <el-input v-model="searchQuery.revisionReason" placeholder="软件修订原因" clearable /> </search-item> <search-item> <el-input v-model="searchQuery.createDept" placeholder="申请部门" clearable /> </search-item> <search-item> <el-input v-model="searchQuery.createUserName" placeholder="申请人" clearable /> </search-item> <search-item> <el-date-picker v-model="dateRange" type="daterange" start-placeholder="申请时间(开始)" end-placeholder="申请时间(结束)" /> </search-item> </search-area> <!-- 表格数据展示 --> <table-container title="修订申请列表"> <!-- 表头区域 --> <template #btns-right> <icon-button v-if="active === '0' && proxy.hasPerm(`/resource/software/revision/add`)" icon="icon-add" title="新建" @click="addRevisionApply" /> <icon-button v-if="active === '0'" icon="icon-export" title="导出" @click="exportAll" /> </template> <!-- 表格区域 --> <normal-table id="reportTabel" :data="dataList" :total="total" :columns="columns" :query="{ limit: searchQuery.limit, offset: searchQuery.offset }" :list-loading="loadingTable" is-showmulti-select @change="changePage" @multi-select="handleSelectionChange" > <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="130"> <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/software/revision/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 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="refuseHandler" /> <!-- 右上角按钮集合 --> <button-box :active="active" :menu="menu" @change-current-button="changeCurrentButton" /> </app-container> </template>