<!-- 合同执行变更登记表 --> <script name="ResourceCustomerContractEdit" lang="ts" setup> import { ElLoading, ElMessage, ElMessageBox } from 'element-plus' import { ref } from 'vue' import contractBasic from './components/basic.vue' import { approvalDelete, cancelApproval, refuseApproval, rejectApproval } from '@/api/resource/contract' import ApprovalDialog from '@/components/Approval/ApprovalDialog.vue' const { proxy } = getCurrentInstance() as any const $router = useRouter() // 关闭页面使用 const approvalStatusName = ref('') // 审批状态名称 const processId = ref('') // 流程实例id const taskId = ref('') // 任务id,用于同意、驳回、拒绝审批 const decisionItem = ref('') const textMap: { [key: string]: string } = { edit: '编辑', add: '新建', detail: '详情', }// 字典 const pageType = ref('add') // 页面类型: add, edit, detail const infoId = ref('') // 列表id const $route = useRoute() // 路由参数 const approvalDialog = ref() // 审批对话ref const showApprovalButton = ref(true) // 是否展示审批按钮 const showRefuseEditButton = ref(true) // 是否展示未通过编辑按钮 const showSubmitButton = ref(false) // 提交按钮是否禁用 const contractBasicRef = ref() // 基本信息组件ref // -----------------------------------------------路由参数--------------------------------- if ($route.params && $route.params.type) { pageType.value = $route.params.type as string if ($route.params.id) { infoId.value = $route.params.id as string } } // -------------------------------------标签-------------------------------------------------- const radioMenus = ref([ // 标签内容 { name: '基本信息', value: 'contract-basic' }, { name: '审批详情', value: 'contract-approval-record' }, ]) const current = ref('contract-basic') // 选择的tab 默认基本信息 // -----------------------------------------按钮-------------------------------------------------- // 关闭新增页面的回调 const close = () => { $router.back() } // 点击提交 const handleSubmit = () => { contractBasicRef.value.submitForm(processId.value, infoId.value) } // 点击保存 const saveForm = () => { contractBasicRef.value.saveForm() } // 新建保存成功 const addSuccess = (id: string) => { infoId.value = id showSubmitButton.value = true // 保存成功显示提交按钮 } // 提交成功 const submitSuccess = () => { pageType.value = 'detail' // 详情模式-不可编辑 showRefuseEditButton.value = false // 隐藏提交按钮 } // 点击删除--已取消 const del = () => { const loading = ElLoading.service({ lock: true, text: '加载中...', background: 'rgba(255, 255, 255, 0.6)', }) approvalDelete({ id: infoId.value, taskId: taskId.value }).then(() => { loading.close() ElMessage.success('已删除') close() }) } // 点击编辑 const handleEdit = () => { pageType.value = 'edit' // 编辑模式 } // -------------------------------------------审批---------------------------------------- // 审批结束回调 const approvalSuccess = () => { showApprovalButton.value = false } // 审批 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('reject', taskId.value, infoId.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() }) } // 驳回 const reject = (comments: string, taskId: string, id: string) => { const param = { id, taskId, // 任务id comments, // 拒绝原因 } rejectApproval(param).then((res) => { if (res.code === 200) { ElMessage.success('已驳回') showApprovalButton.value = false } else { ElMessage.error(`驳回失败:${res.message}`) } }) } // -----------------------------------------------钩子------------------------------------------ watch(() => approvalStatusName.value, (val) => { if (val === '全部' || val === '草稿箱' || pageType.value === 'add') { // 全部草稿箱把审批详情删了 if (radioMenus.value[radioMenus.value.length - 1].value === 'contract-approval-record') { radioMenus.value.pop() } } else { // 非全部和草稿箱把审批详情加上 if (radioMenus.value[radioMenus.value.length - 1].value !== 'contract-approval-record') { radioMenus.value.push({ name: '审批详情', value: 'contract-approval-record' }) } } }) onMounted(async () => { approvalStatusName.value = $route.query.approvalStatusName as string // 审批状态名字 processId.value = $route.query.processId as string // 流程实例id taskId.value = $route.query.taskId as string // 任务id用于审批 decisionItem.value = $route.query.decisionItem as string }) </script> <template> <app-container> <detail-page :title="`合同执行变更登记表 (${textMap[pageType]})`"> <template #btns> <el-button v-if="pageType === 'detail' && approvalStatusName === '待审批' && showApprovalButton" type="primary" @click="handleApprove('同意')"> 同意 </el-button> <el-button v-if="(`${decisionItem}` === '1' || `${decisionItem}` === '2') && pageType === 'detail' && approvalStatusName === '待审批' && showApprovalButton" type="warning" @click="handleApprove('驳回')"> 驳回 </el-button> <el-button v-if="(`${decisionItem}` === '1' || `${decisionItem}` === '3') && 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 === 'add' || (pageType === 'edit' && approvalStatusName !== '未通过' && approvalStatusName !== '已取消' && approvalStatusName !== '全部')" type="primary" :disabled="!infoId" @click="handleSubmit" > 提交 </el-button> <el-button v-if="approvalStatusName !== '已审批' && pageType === 'detail' && approvalStatusName === '未通过' && showRefuseEditButton" type="primary" @click="handleEdit"> 编辑 </el-button> <el-button v-if="pageType !== 'detail'" type="primary" @click="saveForm"> 保存 </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" :disabled="!infoId" > {{ item.name }} </el-radio-button> </el-radio-group> </detail-page> <!-- 基本信息 --> <contract-basic v-if="current === 'contract-basic'" :id="infoId" ref="contractBasicRef" :page-type="pageType" :approval-status-name="approvalStatusName" :process-id="processId" @add-success="addSuccess" @submit-success="submitSuccess" /> <!-- 审批详情 --> <approval-record-table v-if="current === 'contract-approval-record'" :process-id="processId" /> </app-container> <!-- 审批弹窗 --> <approval-dialog ref="approvalDialog" @on-success="approvalSuccess" @refuse="refuse" @reject="reject" /> </template>