<!-- 证书管理列表 -->
<script name="BusinessCertManageList" lang="ts" setup>
import { getCurrentInstance, ref } from 'vue'
import { ElLoading, ElMessage, ElMessageBox } 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 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 listQuery = ref<IListQuery>({
approvalStatus: active.value, // 审批状态类型code
certificateReportName: '', // 证书报告名称
certificateReportNo: '', // 证书报告编号
createTimeEnd: '', // 创建结束时间
createTimeStart: '', // 创建开始时间
customerName: '', // 委托方名字
formId: SCHEDULE.CERTIFICATE_PRINT_APPROVAL, // formId
printStatus: '', // 打印状态(未打印传1,其他状态不传)
sampleName: '', // 受检设备名称
sampleNo: '', // 样品编号
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: 'sampleNo', align: 'center', width: '160' },
{ text: '被检设备名称', value: 'sampleName', align: 'center' },
{ text: '创建时间', value: 'createTime', width: '180', 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[]>([])
// --------------------------------------字典---------------------------------------------
function getDict() {
loadingTable.value = true
// 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
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
certificateReportName: '', // 证书报告名称
certificateReportNo: '', // 证书报告编号
createTimeEnd: '', // 创建结束时间
createTimeStart: '', // 创建开始时间
customerName: '', // 委托方名字
formId: SCHEDULE.CERTIFICATE_PRINT_APPROVAL, // formId
printStatus: '', // 打印状态(未打印传1,其他状态不传)
sampleName: '', // 受检设备名称
sampleNo: '', // 样品编号
offset: 1,
limit: 20,
}
dateRange.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
certificateReportName: listQuery.value.certificateReportName, // 证书报告名称
certificateReportNo: listQuery.value.certificateReportNo, // 证书报告编号
createTimeEnd: listQuery.value.createTimeEnd, // 创建结束时间
createTimeStart: listQuery.value.createTimeStart, // 创建开始时间
customerName: listQuery.value.customerName, // 委托方名字
formId: listQuery.value.formId, // formId
printStatus: listQuery.value.printStatus, // 打印状态(未打印传1,其他状态不传)
sampleName: listQuery.value.sampleName, // 受检设备名称
sampleNo: listQuery.value.sampleNo, // 样品编号
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(() => {
// row.printFileName = 'temp交流电压表、交流电流表、直流电压表、直流电流表、75mV电流表_1698395538153_1698807760300.pdf'
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) => {
// const printFileName1 = 'temp交流电压表、交流电流表、直流电压表、直流电流表、75mV电流表_1698395538153_1698807760300.pdf'
$router.push({
path: `/cert/detail/${row.id}`,
query: {
approvalStatusName: row.approvalStatusName, // 审批状态名称
printFileName: row.certificateFile,
printStatusName: row.printStatusName, // 证书打印状态
processId: row.processId, // 流程实例
taskId: row.taskId, // 任务id,用于同意、驳回、拒绝审批
},
})
}
// ---------------------------------------钩子-----------------------------------------------
watch(dateRange, (val) => {
if (val) {
listQuery.value.createTimeStart = `${val[0]}`
listQuery.value.createTimeEnd = `${val[1]}`
}
else {
listQuery.value.createTimeStart = ''
listQuery.value.createTimeEnd = ''
}
})
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.sampleNo"
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-date-picker
v-model="dateRange"
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="activeTitle === '全部' || activeTitle === '未打印'" icon="icon-export" title="导出" type="primary" @click="exportAll" />
</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>