<!-- 证书管理列表 --> <script name="BusinessCertManageList" lang="ts" setup> import { getCurrentInstance, ref } from 'vue' import { ElLoading, ElMessage, ElMessageBox, dayjs } from 'element-plus' import type { DateModelType } from 'element-plus' import type { IList, IListQuery } from './cert-interface' import ApprovalDialog from '@/components/Approval/ApprovalDialog.vue' import type { TableColumn } from '@/components/NormalTable/table_interface' import { printPdf } from '@/utils/printUtils' import { exportFile } from '@/utils/exportUtils' import { getDictByCode } from '@/api/system/dict' import { changePrintStatus, exportCertList, getCertList, refuseCert, submitApproval } from '@/api/business/certManage/cert' import { SCHEDULE } from '@/utils/scheduleDict' import type { deptType, dictType } from '@/global' import ButtonBox from '@/components/buttonBox/buttonBox.vue' import type { IMenu } from '@/components/buttonBox/buttonBox' import { getPhotoUrl } from '@/api/system/tool' const { proxy } = getCurrentInstance() as any const $router = useRouter() const buttonBoxActive = 'CertPrint' // 存储在sessionstorage里面的字段名,用于记录右上角buttonbox点击状态 // 右上角按钮 const menu = ref<IMenu[]>([]) // 右上角审批状态按钮组合 const active = ref('') // 选中的按钮 const activeTitle = ref('') // active对应的审批状态名字 const dateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据 const measureValidDateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据 // 查询条件 const listQuery = ref<IListQuery>({ approvalStatus: active.value, // 审批状态类型code,导出接口不用传 certificateReportNo: '', // 证书报告编号 certificateReportName: '', // 证书报告名称 customerId: '', // 委托方id customerName: '', // 委托方 deptName: '', // 使用部门 sampleNo: '', // 受检智能模型编号 sampleName: '', // 受检智能模型名称 model: '', // 规格型号 manufactureNo: '', // 出厂编号 measureCategory: '', // 检校类别(字典code) traceDateStart: '', // 测试、校准或检定日期开始 traceDateEnd: '', // 测试、校准或检定日期结束 conclusion: '', // 结论(所检项目合格/不合格/除*外其余所检项目合格,用户手选) measureValidDateStart: '', // 检定有效期开始 measureValidDateEnd: '', // 检定有效期结束 labCode: '', // 实验室代码(字典code) groupCode: '', // 组别代码(字典code) createUserName: '', // 检定员 formId: SCHEDULE.CERTIFICATE_PRINT_APPROVAL, // 表单id printStatus: '', // 打印状态(未打印传1,其他状态不传) offset: 1, limit: 20, }) // 表头 const columns = ref<TableColumn[]>([ { text: '证书编号', value: 'certificateNo', width: '160', align: 'center' }, { text: '证书名称', value: 'certificateName', align: 'center' }, { text: '任务单编号', value: 'orderNo', width: '160', align: 'center' }, { text: '委托方', value: 'customerName', align: 'center' }, { text: '使用部门', value: 'deptName', align: 'center' }, { text: '智能模型名称', value: 'sampleName', align: 'center' }, { text: '规格型号', value: 'model', align: 'center' }, { text: '出厂编号', value: 'manufactureNo', align: 'center' }, { text: '检校类别', value: 'measureCategoryName', align: 'center' }, { text: '检定日期', value: 'traceDate', align: 'center', width: '120' }, { text: '检定结论', value: 'conclusion', align: 'center' }, { text: '检定有效期', value: 'measureValidDate', align: 'center', width: '120' }, { text: '实验室', value: 'labCodeName', align: 'center', width: '100' }, { text: '部门', value: 'groupCodeName', align: 'center', width: '120' }, { text: '检定员', value: 'createUserName', align: 'center' }, { text: '打印状态', value: 'printStatusName', width: '85', align: 'center' }, ]) // 表格数据 const list = ref<IList[]>([]) // 总数 const total = ref(0) // 表格加载状态 const loadingTable = ref(false) // 选中的内容 const checkoutList = ref<string[]>([]) // --------------------------------------字典--------------------------------------------- const measureCategoryList = ref<dictType[]>([])// 检校类别 const conclusionList = ref<dictType[]>([])// 检定结论 const useDeptList = ref<deptType[]>([]) // 所属部门列表 const labDeptList = ref<deptType[]>([]) // 实验室 function getDict() { loadingTable.value = true // 检校类别 getDictByCode('measureCategory').then((response) => { measureCategoryList.value = response.data }) // 结论 getDictByCode('bizConclusion').then((response) => { conclusionList.value = response.data }) // 实验室 getDictByCode('bizGroupCodeEquipment').then((response) => { labDeptList.value = response.data }) // 部门 getDictByCode('bizGroupCode').then((response) => { useDeptList.value = response.data }) // eslint-disable-next-line no-async-promise-executor return new Promise(async (resolve, reject) => { const data_Print = await getDictByCode('printStatus') const data_approval = await getDictByCode('approvalStatus') const response = [...data_Print.data, ...data_approval.data] // 制作右上角的菜单 const tempMenu = ['未打印', '全部', '待审批', '审批中', '已通过', '未通过'] tempMenu.forEach((item) => { const tempFindData = response.find((e: { name: string; value: string }) => e.name === item) if (tempFindData) { menu.value.push({ name: tempFindData.name, id: `${tempFindData.value}`, }) } }) if (window.sessionStorage.getItem(buttonBoxActive)) { active.value = window.sessionStorage.getItem(buttonBoxActive)! } else { active.value = menu.value.find(item => item.name === '未打印')!.id as string // 全部 } }) } // -----------------------------------------列表数据--------------------------------------------- // 数据查询 function fetchData(isNowPage = false) { loadingTable.value = true if (!isNowPage) { // 是否显示当前页,否则跳转第一页 listQuery.value.offset = 1 } if (activeTitle.value == '未打印') { listQuery.value.printStatus = '1'; listQuery.value.approvalStatus = 'null' } else { listQuery.value.printStatus = '' } getCertList(listQuery.value).then((response) => { list.value = response.data.rows.map((item: { traceDate: string; measureValidDate: string; labCodeName: string }) => { return { ...item, traceDate: item.traceDate ? dayjs(item.traceDate).format('YYYY-MM-DD') : item.traceDate, // 检定日期 measureValidDate: item.measureValidDate ? dayjs(item.measureValidDate).format('YYYY-MM-DD') : item.measureValidDate, // 检定有效期 labCodeName: item.labCodeName === '海口' ? '海口实验室' : item.labCodeName === '西昌' ? '西昌实验室' : item.labCodeName, } }) total.value = parseInt(response.data.total) loadingTable.value = false }) } // 多选发生改变时 function handleSelectionChange(e: any) { checkoutList.value = e.map((item: { id: string }) => item.id) } // 点击搜索 const searchList = () => { fetchData(true) } // 点击重置 const clearList = () => { listQuery.value = { approvalStatus: active.value, // 审批状态类型code,导出接口不用传 certificateReportNo: '', // 证书报告编号 certificateReportName: '', // 证书报告名称 customerId: '', // 委托方id customerName: '', // 委托方 deptName: '', // 使用部门 sampleNo: '', // 受检智能模型编号 sampleName: '', // 受检智能模型名称 model: '', // 规格型号 manufactureNo: '', // 出厂编号 measureCategory: '', // 检校类别(字典code) traceDateStart: '', // 测试、校准或检定日期开始 traceDateEnd: '', // 测试、校准或检定日期结束 conclusion: '', // 结论(所检项目合格/不合格/除*外其余所检项目合格,用户手选) measureValidDateStart: '', // 检定有效期开始 measureValidDateEnd: '', // 检定有效期结束 labCode: '', // 实验室代码(字典code) groupCode: '', // 组别代码(字典code) createUserName: '', // 检定员 formId: SCHEDULE.CERTIFICATE_PRINT_APPROVAL, // 表单id printStatus: '', // 打印状态(未打印传1,其他状态不传) offset: 1, limit: 20, } dateRange.value = ['', ''] // 清空时间 measureValidDateRange.value = ['', ''] fetchData(true) } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 const changePage = (val: { size?: number; page?: number }) => { if (val && val.size) { listQuery.value.limit = val.size } if (val && val.page) { listQuery.value.offset = val.page } fetchData(true) } // --------------------------------------------审批------------------------------------------ const approvalDialog = ref() // 审批组件ref // 审批 const handleDistribute = (row: IList, status: string) => { if (status === 'agree') { approvalDialog.value.initDialog('agree', row.taskId) fetchData(true) } else { approvalDialog.value.initDialog('refuse', row.taskId, row.id) fetchData(true) } } // 拒绝 const refuse = (comments: string, taskId: string, id: string) => { const params = { id, taskId, // 任务id comments, // 拒绝原因 } refuseCert(params).then((res) => { ElMessage({ type: 'success', message: '已拒绝', }) fetchData(true) }) } // 审批结束回调 const approvalSuccess = () => { fetchData(true) } // ----------------------------------------按钮---------------------------------------------- // 导出 const exportAll = () => { const loading = ElLoading.service({ lock: true, text: '下载中请稍后', background: 'rgba(255, 255, 255, 0.8)', }) if (list.value.length > 0) { const params = { approvalStatus: listQuery.value.approvalStatus, // 审批状态类型code,导出接口不用传 certificateReportNo: listQuery.value.certificateReportNo, // 证书报告编号 certificateReportName: listQuery.value.certificateReportName, // 证书报告名称 customerId: listQuery.value.customerId, // 委托方id customerName: listQuery.value.customerName, // 委托方 deptName: listQuery.value.deptName, // 使用部门 sampleNo: listQuery.value.sampleNo, // 受检智能模型编号 sampleName: listQuery.value.sampleName, // 受检智能模型名称 model: listQuery.value.model, // 规格型号 manufactureNo: listQuery.value.manufactureNo, // 出厂编号 measureCategory: listQuery.value.measureCategory, // 检校类别(字典code) traceDateStart: listQuery.value.traceDateStart, // 测试、校准或检定日期开始 traceDateEnd: listQuery.value.traceDateEnd, // 测试、校准或检定日期结束 conclusion: listQuery.value.conclusion, // 结论(所检项目合格/不合格/除*外其余所检项目合格,用户手选) measureValidDateStart: listQuery.value.measureValidDateStart, // 检定有效期开始 measureValidDateEnd: listQuery.value.measureValidDateEnd, // 检定有效期结束 labCode: listQuery.value.labCode, // 实验室代码(字典code) groupCode: listQuery.value.groupCode, // 组别代码(字典code) createUserName: listQuery.value.createUserName, // 检定员 formId: listQuery.value.formId, // 表单id printStatus: listQuery.value.printStatus, // 打印状态(未打印传1,其他状态不传) offset: 1, limit: 20, ids: checkoutList.value, } exportCertList(params).then((res) => { const blob = new Blob([res.data]) loading.close() exportFile(blob, '证书管理.xlsx') }) } else { loading.close() ElMessage.warning('无数据可导出数据') } } // 按钮切换 const changeCurrentButton = (val: string) => { active.value = val activeTitle.value = menu.value.find(item => item.id === val)!.name window.sessionStorage.setItem(buttonBoxActive, val) clearList() } // ----------------------------------------操作--------------------------------------------- // 打印 const bindLabel = (row: IList) => { // 判断状态第一次可以直接打印,之后的打印需要审批 if (row.printStatusName === '未打印') { ElMessageBox.confirm( '确定要打印吗?', '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning', }, ).then(() => { if (!row.certificateFile) { ElMessage.warning('本条数据没有证书'); return false } getPhotoUrl(row.certificateFile as string).then((res) => { const url = res.data changePrintStatus({ id: row.id }).then(() => { console.log('状态已经更改') fetchData(true) }) printPdf(url) }) }) } else { ElMessageBox.confirm( '打印前需申请 确定要打印吗?', '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning', dangerouslyUseHTMLString: true, }, ).then(() => { const params = { assignees: [], // 增加的下一节点审批人Id列表 formId: '', // formId id: '', // id processId: '', // 流程实例id } const loading = ElLoading.service({ lock: true, text: '加载中...', background: 'rgba(255, 255, 255, 0.6)', }) submitApproval({ id: row.id, formId: listQuery.value.formId }).then((res) => { loading.close() if (res.code === 200) { ElMessage.success('申请已发送') fetchData(true) } }) }) } } // 点击详情 const handleDetail = (row: IList) => { $router.push({ path: `/cert/detail/${row.id}`, query: { ...row, approvalStatusName: row.approvalStatusName, // 审批状态名称 printFileName: row.certificateFile, printStatusName: row.printStatusName, // 证书打印状态 processId: row.processId, // 流程实例 taskId: row.taskId, // 任务id,用于同意、驳回、拒绝审批 }, }) } // 点击批量打印 const handleBatchPrint = () => { if (!checkoutList.value.length) { ElMessage.warning('请选中') return false } if (checkoutList.value.length > 5) { ElMessage.warning('最多可进行5个证书的打印') return false } const loading = ElLoading.service({ lock: true, text: '加载中...', background: 'rgba(255, 255, 255, 0.6)', }) const params = checkoutList.value.map((item) => { return { id: item, } }) // batchPrint(params).then((res) => { // const pdfStream = new Blob([res.data]) // const blobUrl = URL.createObjectURL(pdfStream) // printPdf(blobUrl) // loading.close() // }).catch(() => { loading.close() }) } // ---------------------------------------钩子----------------------------------------------- watch(dateRange, (val) => { if (val) { listQuery.value.traceDateStart = `${val[0]}` listQuery.value.traceDateEnd = `${val[1]}` } else { listQuery.value.traceDateStart = '' listQuery.value.traceDateEnd = '' } }) watch(measureValidDateRange, (val) => { if (val) { listQuery.value.measureValidDateStart = `${val[0]}` listQuery.value.measureValidDateEnd = `${val[1]}` } else { listQuery.value.measureValidDateStart = '' listQuery.value.measureValidDateEnd = '' } }) onMounted(async () => { await getDict() fetchData() }) </script> <template> <app-container> <search-area :need-clear="true" @search="searchList" @clear="clearList" > <search-item> <el-input v-model.trim="listQuery.certificateReportNo" placeholder="证书编号" class="short-input" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.certificateReportName" placeholder="证书名称" class="short-input" clearable /> </search-item> <search-item> <el-input v-model.trim="listQuery.customerName" placeholder="委托方" clearable class="short-input" /> </search-item> <search-item> <el-input v-model.trim="listQuery.deptName" placeholder="使用部门" clearable class="short-input" /> </search-item> <search-item> <el-input v-model.trim="listQuery.sampleName" placeholder="智能模型名称" clearable class="short-input" /> </search-item> <search-item> <el-input v-model.trim="listQuery.model" placeholder="规格型号" clearable class="short-input" /> </search-item> <search-item> <el-input v-model.trim="listQuery.manufactureNo" placeholder="出厂编号" clearable class="short-input" /> </search-item> <search-item> <el-select v-model="listQuery.measureCategory" placeholder="检校类别" filterable clearable class="short-input" > <el-option v-for="item in measureCategoryList" :key="item.id" :label="item.name" :value="item.value" /> </el-select> </search-item> <search-item> <el-date-picker v-model="dateRange" type="daterange" range-separator="至" format="YYYY-MM-DD" value-format="YYYY-MM-DD" start-placeholder="检定日期(开始)" end-placeholder="检定日期(结束)" /> </search-item> <search-item> <el-select v-model="listQuery.conclusion" placeholder="检定结论" filterable class="short-input" clearable > <el-option v-for="item in conclusionList" :key="item.id" :label="item.name" :value="item.name" /> </el-select> </search-item> <search-item> <el-date-picker v-model="measureValidDateRange" class="short-input" type="daterange" range-separator="至" format="YYYY-MM-DD" value-format="YYYY-MM-DD" start-placeholder="检定有效期(开始)" end-placeholder="检定有效期(结束)" /> </search-item> <search-item> <el-select v-model="listQuery.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="listQuery.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.trim="listQuery.createUserName" placeholder="检定员" clearable class="short-input" /> </search-item> </search-area> <table-container> <template #btns-right> <icon-button v-if="activeTitle === '全部' || activeTitle === '未打印'" icon="icon-export" title="导出" type="primary" @click="exportAll" /> <!-- <icon-button icon="icon-batchPrint" title="批量打印" type="primary" @click="handleBatchPrint" /> --> </template> <normal-table :data="list" :total="total" :columns="columns" :query="listQuery" :list-loading="loadingTable" is-showmulti-select @change="changePage" @multi-select="handleSelectionChange" > <template #preColumns> <el-table-column label="序号" width="55" align="center"> <template #default="scope"> {{ (listQuery.offset - 1) * listQuery.limit + scope.$index + 1 }} </template> </el-table-column> </template> <template #columns> <el-table-column v-if="!['未打印', '全部'].includes(activeTitle)" label="审批状态" align="center" width="90px" prop="approvalStatusName" /> <el-table-column label="操作" align="center" fixed="right" width="120"> <template #default="{ row }"> <el-button size="small" link type="primary" @click="handleDetail(row)"> 查看 </el-button> <el-button v-if="activeTitle === '全部' || activeTitle === '未打印'" size="small" link type="primary" @click="bindLabel(row)"> 打印 </el-button> <el-button v-if="activeTitle === '待审批'" size="small" type="primary" link @click="handleDistribute(row, 'agree')"> 同意 </el-button> <el-button v-if="activeTitle === '待审批'" size="small" type="danger" link @click="handleDistribute(row, 'refuse')"> 拒绝 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> <!-- 右上角审批状态按钮集合 --> <button-box :active="active" :menu="menu" @change-current-button="changeCurrentButton" /> <!-- 审批弹窗 --> <approval-dialog ref="approvalDialog" @on-success="approvalSuccess" @refuse="refuse" /> </app-container> </template> <style lang="scss" scoped> .short-input { width: 160px; } </style>