<!-- 预防措施处理单编辑页面 --> <script name="QualityPreventHandler" lang="ts" setup> import type { FormInstance, FormRules, UploadUserFile } from 'element-plus' import { ElLoading, ElMessage, ElMessageBox } from 'element-plus' import dayjs from 'dayjs' import NonConformanceRep from './NonConformanceRep.vue' import { addQualityPrevent, approvalDelete, cancelApproval, delteQualityPrevent, detailQualityPrevent, draftDelete, refuseApproval, submitQualityPrevent, updateQualityPrevent } from '@/api/quality/prevent/index' import { getDictByCode } from '@/api/system/dict' import useUserStore from '@/store/modules/user' import { getSearchDept } from '@/api/quality/supervise/record' import { AGREE, DETAILURL, TASKNAME } from '@/views/quality/agree' import { SCHEDULE } from '@/utils/scheduleDict' import ApprovalDialog from '@/views/quality/correct/handle/components/ApprovalDialog.vue' import ApprovalOpinion from '@/views/quality/correct/handle/components/approvalOpinion.vue' import selectUser from '@/views/quality/components/selectUser.vue' const $props = defineProps({ showBase: { type: Boolean, default: true, }, }) // 路由相关 const $route = useRoute() const $router = useRouter() // 用户信息仓库 const userStore = useUserStore() const ruleFormRef = ref<FormInstance>() // from组件 // 当前审批状态名字 const approvalStatusName = $route.query.approvalStatusName as string // 表单 const ruleForm = ref({ fileName: '预防措施处理单', bizLabCode: '', supDeptId: '', fileCode: '', creator: '', creatorName: '', logTime: '', id: '', fileRelList: [] as any[], description: '', taskId: '', }) // 审批过程中上传的附件 const fileList = ref<any[]>([]) // 表单验证规则 const rules = ref<FormRules>({ bizLabCode: [{ required: true, message: '实验室必选', trigger: ['blur', 'change'] }], fileRelList: [{ required: true, message: '关联不符合要求情况分析报告必选', trigger: ['blur', 'change'] }], supDeptId: [{ required: true, message: '部门必选', trigger: ['blur', 'change'] }], }) // 填充数据 const fillData = () => { if (sessionStorage.getItem('QualityPreventHandler-info-flag')) { ruleForm.value = JSON.parse(sessionStorage.getItem('QualityPreventHandler-info') as string) // 清空存储 sessionStorage.removeItem('QualityPreventHandler-info-flag') sessionStorage.removeItem('QualityPreventHandler-info') return false } } const labelList = ref<{ id: string; value: string; name: string }[]>()// 实验室代码 const deptList = ref<any[]>()// 部门 // 获取字典值 const fetchDict = () => { // 获取实验室代码字典 getDictByCode('bizLabCode').then((res) => { labelList.value = res.data }) // 部门 getSearchDept({ labCode: '' }).then((res) => { deptList.value = res.data }) } fetchDict() // 监听实验室变化修改部门 const watchFlag = ref(true) watch(() => ruleForm.value.bizLabCode, (newVal) => { if (newVal) { if ($route.path.includes('detail') || watchFlag.value) { return } ruleForm.value.supDeptId = '' getSearchDept({ labCode: newVal }).then((res) => { deptList.value = res.data }) } else { getSearchDept({ }).then((res) => { deptList.value = res.data }) } }, { deep: true, }) // 页面初始化 onMounted(() => { if ($route.path.includes('create')) { watchFlag.value = false // 默认填充信息 fillData() ruleForm.value.creator = userStore.id ruleForm.value.creatorName = userStore.name ruleForm.value.logTime = dayjs().format('YYYY-MM-DD HH:mm') // 自动关联不符合报告(启动预防措施管理) if ($route.query.fileType) { ruleForm.value.fileRelList = [{ ...JSON.parse($route.query.row as string), fileType: $route.query.fileType }] } } else { fillData() detailQualityPrevent({ id: $route.params.id as string }).then((res) => { // 详情 // console.log(res.data, '详情') ruleForm.value = res.data // 审批附件 fileList.value = [...res.data.correctiveActionFiles, ...res.data.rectificationSituationFiles] setTimeout(() => { watchFlag.value = false }, 500) }) } }) // ---------------------------------------------保存相关-------------------------------------- const infoId = ref('') const createRow = () => { addQualityPrevent(ruleForm.value).then((res) => { ElMessage.success('操作成功') infoId.value = res.data }) } const updateRow = () => { updateQualityPrevent(ruleForm.value).then((res) => { ElMessage.success('操作成功') infoId.value = res.data if (approvalStatusName === '已取消' || approvalStatusName === '未通过') { handleSubmit() } }) } const saveForm = async (formEl: FormInstance | undefined) => { if (!formEl) { return } await formEl.validate((valid, fields) => { if (valid) { if ($route.path.includes('create')) { createRow() } else if ($route.path.includes('update')) { updateRow() } } }) } // ---------------------------------------------审批-------------------------------------- const taskId = ref($route.query.taskId as string || '') // 任务id,用于同意、驳回、拒绝审批 const processId = ref($route.query.processId as string || '') // 流程实例id const approvalDialog = ref() // 审批组件ref const showApprovalButton = ref(true) // 是否展示审批按钮 // 审批结束回调 const approvalSuccess = () => { showApprovalButton.value = false } // 审批 const handleApprove = (val: string) => { if (val === '取消') { const params = { processInstanceId: processId.value!, comments: '', id: ruleForm.value.id, } ElMessageBox.confirm( '确认取消该审批吗?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ) .then(() => { cancelApproval(params).then((res) => { ElMessage({ type: 'success', message: '已取消', }) showApprovalButton.value = false }) }) } else if (val === '同意') { approvalDialog.value.initDialog('agree', taskId.value, ruleForm.value.id, processId.value) } else if (val === '拒绝') { approvalDialog.value.initDialog('refuse', taskId.value, ruleForm.value.id, processId.value) } } // 拒绝 const refuse = (comments: string, taskId: string, id: string) => { const params = { id, taskId, // 任务id comments, // 拒绝原因 } refuseApproval(params).then((res) => { ElMessage({ type: 'success', message: '已拒绝', }) showApprovalButton.value = false }) } // 选择审批人 const userRef = ref() // 点击提交 function handleSubmit() { if (infoId.value || ruleForm.value.id) { // 选择审批人 userRef.value.initDialog() } else { ElMessage.warning('请先保存') } } // 确认审批人 const confirmUser = (data: any) => { // ruleForm.value.assignees = data submitQualityPrevent({ formId: SCHEDULE.PREVENT_MEASURE_PROCESS_SHEET_APPROVAL, // processId: infoId.value, id: infoId.value || ruleForm.value.id, assignees: data, }).then(() => { ElMessage.success('提交成功') // $router.go(-1) close() }) } // // 点击提交 // function handleSubmit() { // if (infoId.value || ruleForm.value.id) { // submitQualityPrevent({ // formId: SCHEDULE.PREVENT_MEASURE_PROCESS_SHEET_APPROVAL, // // processId: infoId.value, // id: infoId.value || ruleForm.value.id, // }).then(() => { // ElMessage.success('提交成功') // close() // }) // } // else { // ElMessage.warning('请先保存') // } // } // 点击编辑 const handleEdit = () => { $router.push({ path: `/preventhandle/update/${ruleForm.value.id}`, query: { ...$route.query }, }) } const del = () => { if (approvalStatusName === '草稿箱') { draftDelete({ id: ruleForm.value.id }).then(() => { ElMessage.success('已删除') close() }) } else if (approvalStatusName === '已取消') { approvalDelete({ id: ruleForm.value.id, taskId: ruleForm.value.taskId }).then(() => { ElMessage.success('已删除') close() }) } else if (approvalStatusName === '全部') { // 全部的删除 delteQualityPrevent({ id: ruleForm.value.id }).then(() => { ElMessage.success('已删除') close() }) } } // 关闭页面 function close() { if ($route.query.data) { $router.go(-1) } else { $router.push({ path: '/prevent/preventhandle', }) } } const showMenu = ref('基本信息') defineExpose({ ruleForm, showMenu, }) // 不符合要求情况分析报告弹窗 const conformanceRef = ref() // 打开弹窗 const selectConformance = () => { conformanceRef.value.initDialog() } // 确认报告 const confirmConformance = (report: any) => { console.log(report, 'report') ruleForm.value.fileRelList = report ruleFormRef.value?.clearValidate('fileRelList') } // 报告详情 const goDetail = () => { const data = ruleForm.value.fileRelList[0] sessionStorage.setItem('QualityPreventHandler-info', JSON.stringify(ruleForm.value)) $router.push({ path: `${DETAILURL[`${data.fileType}`]}/${data.id}`, query: { approvalStatusName: '全部', // 审批状态名称 processId: data.processId, // 流程实例id taskId: data.taskId, // 任务id id: data.id, }, }) } const { proxy } = getCurrentInstance() as any </script> <template> <app-container style="overflow: hidden;"> <!-- 不符合要求情况分析报告弹窗 --> <non-conformance-rep ref="conformanceRef" @add="confirmConformance" /> <!-- 审批弹窗 --> <approval-dialog ref="approvalDialog" :agree="AGREE.PREVENT_MEASURE_PROCESS_SHEET_APPROVAL" :last-name="TASKNAME.PREVENT_MEASURE_PROCESS_SHEET_APPROVAL" type="correctApproval" @on-success="approvalSuccess" @refuse="refuse" /> <!-- 选择审批人 --> <select-user ref="userRef" @confirm="confirmUser" /> <detail-page title="预防措施处理单" class="info-header"> <template #btns> <el-button v-if="$route.path.includes('detail') && approvalStatusName === '待审批' && showApprovalButton && proxy.hasPerm('/quality/prevent/handle/agree')" type="primary" @click="handleApprove('同意')"> 同意 </el-button> <el-button v-if="$route.path.includes('detail') && approvalStatusName === '待审批' && showApprovalButton && proxy.hasPerm('/quality/prevent/handle/reject')" type="danger" @click="handleApprove('拒绝')"> 拒绝 </el-button> <el-button v-if="$route.path.includes('detail') && approvalStatusName === '审批中' && showApprovalButton && proxy.hasPerm('/quality/prevent/handle/cancel')" type="info" @click="handleApprove('取消')"> 取消 </el-button> <!-- :disabled="!infoId" --> <el-button v-if="($route.path.includes('create') || ($route.path.includes('update') && approvalStatusName !== '未通过' && approvalStatusName !== '已取消')) && proxy.hasPerm('/quality/prevent/handle/cancel')" type="primary" @click="handleSubmit" > 提交 </el-button> <el-button v-if="approvalStatusName !== '已审批' && $route.path.includes('detail') && approvalStatusName === '未通过' && proxy.hasPerm('/quality/prevent/handle/update')" type="primary" @click="handleEdit"> 编辑 </el-button> <el-button v-if="!$route.path.includes('detail')" type="primary" @click="saveForm(ruleFormRef)"> 保存 </el-button> <el-button v-if="approvalStatusName === '已取消'" type="danger" @click="del"> 删除 </el-button> <el-button type="info" @click="close"> 关闭 </el-button> </template> </detail-page> <detail-block v-if="approvalStatusName !== '草稿箱' && !$route.path.includes('create')" class="info-radio" title="0"> <el-radio-group v-model="showMenu"> <el-radio-button label="基本信息" /> <el-radio-button label="审批详情" /> </el-radio-group> </detail-block> <!-- 基本信息 --> <el-form v-show="showMenu === '基本信息' && $props.showBase" ref="ruleFormRef" :model="ruleForm" :class="$route.path.includes('detail') ? 'isDetail' : ''" :rules="rules" label-position="right" label-width="120px" class="form" :disabled="$route.path.includes('detail')"> <detail-block title=""> <el-row :gutter="24" class="marg"> <el-col :span="6"> <el-form-item label="实验室代码" prop="bizLabCode"> <el-select v-model="ruleForm.bizLabCode" placeholder="实验室代码" class="short-input" filterable style="width: 100%;" > <el-option v-for="item in labelList" :key="item.id" :label="item.name" :value="item.value" /> </el-select> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="部门" prop="supDeptId"> <el-select v-model="ruleForm.supDeptId" placeholder="部门" class="short-input" filterable style="width: 100%;" > <el-option v-for="item in deptList" :key="item.id" :label="item.deptName" :value="item.deptId" /> </el-select> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="处理单编号" prop="fileCode"> <el-input v-model.trim="ruleForm.fileCode" placeholder="系统自动生成" disabled /> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="处理单名称" prop="fileName"> <el-input v-model.trim="ruleForm.fileName" disabled /> </el-form-item> </el-col> </el-row> <el-row :gutter="24" class="marg"> <el-col :span="6"> <el-form-item label="提出人" prop="creatorName"> <el-input v-model.trim="ruleForm.creatorName" disabled /> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="记录时间" prop="logTime"> <!-- <el-input v-model.trim="ruleForm.logTime" disabled /> --> <el-date-picker v-model="ruleForm.logTime" type="datetime" style="width: 100%;" format="YYYY-MM-DD HH:mm" value-format="YYYY-MM-DD HH:mm" /> </el-form-item> </el-col> <el-col :span="12"> <el-form-item label-width="220px" label="关联不符合要求情况分析报告" prop="fileRelList"> <!-- <el-input v-model.trim="ruleForm.time" disabled /> --> <el-link v-if="ruleForm.fileRelList.length" type="primary" style="margin-right: 10px;" @click="goDetail" > <!-- {{ ruleForm.fileRelList.length ? `${ruleForm.fileRelList[0].fileCode}-${ruleForm.fileRelList[0].fileName}` : '' }} --> {{ ruleForm.fileRelList.length ? `${ruleForm.fileRelList[0].fileName}` : '' }} </el-link> <el-button v-if="!$route.path.includes('detail')" type="primary" @click="selectConformance"> 选择 </el-button> </el-form-item> </el-col> </el-row> </detail-block> <detail-block title=""> <el-row :gutter="24" class="marg"> <el-col :span="22"> <el-form-item label-width="200px" label="潜在不符合要求事实描述" prop="description"> <el-input v-model.trim="ruleForm.description" placeholder="潜在不符合要求事实描述" :rows="3" type="textarea" /> </el-form-item> </el-col> </el-row> </detail-block> </el-form> <approval-opinion v-show="showMenu === '基本信息' && approvalStatusName !== '草稿箱' && approvalStatusName !== '全部' && $route.path.includes('detail')" :file-list="fileList" type="correctApproval" /> <!-- 审批详情 --> <approval-record-table-custom v-if="showMenu === '审批详情'" :process-id="processId" /> </app-container> </template> <style lang="scss" scoped> // 详情页面隐藏小红点 .isDetail { ::v-deep { .el-form-item.is-required:not(.is-no-asterisk) .el-form-item__label-wrap > .el-form-item__label::before, .el-form-item.is-required:not(.is-no-asterisk) > .el-form-item__label::before { content: ""; display: none; } } } .info-radio { ::v-deep(.header) { display: none !important; } } </style>