<!-- 核查记录管理列表页 -->
<script lang="ts" setup name="CheckRecordDetail">
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import checkRecordBasic from './components/basic.vue'
import ApprovalDialog from '@/components/Approval/ApprovalDialog.vue'
import useUserStore from '@/store/modules/user'
import {
approvalDelete,
cancelApproval,
refuseApproval,
submit,
} from '@/api/equipment/standard/checkRecords'
import { downloadFileName } from '@/utils/download'
import { SCHEDULE } from '@/utils/scheduleDict'
const textMap: { [key: string]: string } = {
edit: '编辑',
add: '新建',
detail: '详情',
}// 页面类型字典
const user = useUserStore() // 用户信息
const pageType = ref('add') // 页面类型: add, edit, detail
const infoId = ref('') // id
const ruleFormRef = ref() // 表单ref
const $router = useRouter()
const approvalStatusName = ref('') // 审批状态名称
const processId = ref('') // 流程实例id
const taskId = ref('') // 任务id,用于同意、驳回、拒绝审批
const showApprovalButton = ref(true) // 是否展示审批按钮
const showSubmitButton = ref(true) // 是都显示提交按钮
const approvalDialog = ref() // 审批对话ref
const checkDateId = ref('') // 核查数据id
const isFromCheckRecordList = ref('true') // 是否来源于坚定审批列表页
// -------------------------------------标签--------------------------------------------------
const radioMenus = ref([ // 标签内容
{ name: '基本信息', value: 'checkRecord-basic' },
{ name: '审批详情', value: 'approval-record' },
])
const current = ref('checkRecord-basic') // 选择的tab 默认基本信息
// -----------------------------------------路由参数----------------------------------------
// 从路由中获取页面类型参数
const $route = useRoute()
if ($route.params && $route.params.type) {
pageType.value = $route.params.type as string
if ($route.params.id) {
infoId.value = $route.params.id as string
}
}
console.log('页面类型', pageType.value, 'infoId', infoId.value)
// --------------------------------------------按钮----------------------------------------------
// 点击提交
const submitForm = () => {
const loading = ElLoading.service({
lock: true,
text: '加载中...',
background: 'rgba(255, 255, 255, 0.6)',
})
submit({ id: infoId.value, formId: SCHEDULE.STANDARD_CHECK_RECORDS_APPROVAL, processId: processId.value }).then((res) => {
ElMessage.success('已提交')
showSubmitButton.value = false
loading.close()
})
}
// 点击关闭
const close = () => {
$router.back()
}
const checkRecordFile = ref('') // 核查记录模板
const reportData = (checkRecordFileParam = '') => {
checkRecordFile.value = checkRecordFileParam// 核查记录模板
}
// 点击核查记录下载
const downloadReport = () => {
downloadFileName(checkRecordFile.value)
}
// -------------------------------------------审批----------------------------------------
// 审批结束回调
const approvalSuccess = () => {
showApprovalButton.value = false
}
// 点击删除--已取消
const del = () => {
ElMessageBox.confirm(
'确认删除该审批吗?',
'提示',
{
confirmButtonText: '确认',
cancelButtonText: '取消',
type: 'warning',
},
)
.then(() => {
const loading = ElLoading.service({
lock: true,
text: '加载中...',
background: 'rgba(255, 255, 255, 0.6)',
})
approvalDelete({ id: infoId.value, taskId: taskId.value }).then(() => {
ElMessage.success('已删除')
loading.close()
close()
})
})
}
// 审批
const handleApprove = (val: string) => {
if (val === '取消') {
const params = {
processInstanceId: processId.value!,
comments: '',
id: infoId.value,
}
ElMessageBox.confirm(
'确认取消该审批吗?',
'提示',
{
confirmButtonText: '确认',
cancelButtonText: '取消',
type: 'warning',
},
)
.then(() => {
const loading = ElLoading.service({
lock: true,
text: '加载中...',
background: 'rgba(255, 255, 255, 0.6)',
})
cancelApproval(params).then((res) => {
ElMessage({
type: 'success',
message: '已取消',
})
showApprovalButton.value = false
loading.close()
})
})
}
else if (val === '同意') {
approvalDialog.value.initDialog('agree', taskId.value)
}
else if (val === '拒绝') {
approvalDialog.value.initDialog('refuse', taskId.value, infoId.value)
}
}
// 拒绝
const refuse = (comments: string, taskId: string, id: string) => {
const params = {
id,
taskId, // 任务id
comments, // 拒绝原因
}
const loading = ElLoading.service({
lock: true,
text: '加载中...',
background: 'rgba(255, 255, 255, 0.6)',
})
refuseApproval(params).then((res) => {
ElMessage({
type: 'success',
message: '已拒绝',
})
showApprovalButton.value = false
loading.close()
})
}
// -----------------------------------------------钩子-----------------------------
watch(() => approvalStatusName.value, (val) => {
if (val === '草稿箱' || pageType.value === 'add' || isFromCheckRecordList.value === 'false') { // 全部草稿箱把审批详情删了
if (radioMenus.value[radioMenus.value.length - 1].value === 'approval-record') {
radioMenus.value.pop()
}
console.log(radioMenus.value)
}
else { // 非全部和草稿箱把审批详情加上
if (radioMenus.value[radioMenus.value.length - 1].value !== 'approval-record') {
radioMenus.value.push({ name: '审批详情', value: 'approval-record' })
}
}
})
// ----------------------------------------------------------------------------------------------
onMounted(() => {
approvalStatusName.value = $route.query.approvalStatusName as string // 审批名称
processId.value = $route.query.processId as string // 流程实例id
taskId.value = $route.query.taskId as string // 任务id用于审批
checkDateId.value = $route.query.checkDateId as string // 核查数据id
isFromCheckRecordList.value = $route.query.isFromCheckRecordList as string // 是否来源于核查记录列表页
})
</script>
<template>
<app-container>
<detail-page :title="`核查记录管理(${textMap[pageType]})`">
<template #btns>
<el-button v-if="pageType === 'detail'" type="primary" @click="downloadReport">
核查记录下载
</el-button>
<el-button v-if="pageType === 'detail' && approvalStatusName === '待审批' && showApprovalButton" type="primary" @click="handleApprove('同意')">
同意
</el-button>
<el-button v-if="pageType === 'detail' && approvalStatusName === '待审批' && showApprovalButton" type="danger" @click="handleApprove('拒绝')">
拒绝
</el-button>
<el-button v-if="pageType === 'detail' && approvalStatusName === '审批中' && showApprovalButton" type="info" @click="handleApprove('取消')">
取消
</el-button>
<el-button v-if="pageType === 'detail' && approvalStatusName === '草稿箱' && showSubmitButton" type="primary" @click="submitForm">
提交
</el-button>
<el-button v-if="approvalStatusName === '已取消'" type="danger" @click="del">
删除
</el-button>
<el-button type="info" @click="close">
关闭
</el-button>
</template>
<el-radio-group v-model="current">
<el-radio-button v-for="item in radioMenus" :key="item.value" :label="item.value">
{{ item.name }}
</el-radio-button>
</el-radio-group>
</detail-page>
<!-- 基本信息 -->
<check-record-basic v-if="current === 'checkRecord-basic'" :page-type="pageType" :check-date-id="checkDateId" @report-data="reportData" />
<!-- 审批详情 -->
<approval-record-table v-if="current === 'approval-record'" :process-id="processId" />
<!-- 审批弹窗 -->
<approval-dialog ref="approvalDialog" @on-success="approvalSuccess" @refuse="refuse" />
</app-container>
</template>