<!-- 预防措施处理单编辑页面 --> <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 { getQualityNoReportFile } from '@/api/quality/supervise/analysis' import { getReviewFormFile } from '@/api/quality/internal/inspect' import { getNonReviewFormFile } from '@/api/quality/internal/dissatisfied' import { getReviewRepFile } from '@/api/quality/review/report' import { UploadFile, getPhotoUrl } from '@/api/file' import { exportFile } from '@/utils/exportUtils' import { addQualityPrevent, approvalDelete, cancelApproval, delteQualityPrevent, detailQualityPrevent, draftDelete, refuseApproval, rejectApproval, 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 decisionItem = ref('') // 用户信息仓库 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: '', managerId: '', internalAuditId: '', }) // 审批过程中上传的附件 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 fileRef = ref() // 文件上传input,获取input的引用 const onFileChange = (event: any) => { // 原生上传 if (event.target.files?.length !== 0) { const fd = new FormData() fd.append('multipartFile', event.target.files[0]) fileRef.value.value = '' UploadFile(fd).then((res1) => { if (res1.code === 200) { ElMessage.success('上传成功') getPhotoUrl(res1.data[0]).then((res) => { ruleForm.value.fileRelList = [{ fileName: res1.data[0], filePath: res.data, fileType: '6', // 其他类型 }] }) } }) } } // 上传报告 const uploadFile = () => { fileRef.value.click() } // -------------------------------------------------------------------------------------------------------- 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, }) // 页面初始化 const infoId = ref('') onMounted(() => { decisionItem.value = $route.query.decisionItem as string 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 }] } if ($route.query.data) { const data = JSON.parse($route.query.data as string) ruleForm.value.bizLabCode = data.bizLabCode console.log(data, 'data') if (data.workName.includes('管理')) { ruleForm.value.managerId = data.id } else if (data.workName.includes('内部')) { ruleForm.value.internalAuditId = data.id } } } else { rules.value.fileCode = [{ required: true, message: '处理单编号必填', trigger: ['blur', 'change'] }] fillData() detailQualityPrevent({ id: $route.params.id as string }).then((res) => { // 详情 // console.log(res.data, '详情') ruleForm.value = res.data infoId.value = res.data.id // 审批附件 fileList.value = [...res.data.correctiveActionFiles, ...res.data.rectificationSituationFiles] setTimeout(() => { watchFlag.value = false }, 500) nextTick(() => { ruleFormRef.value.clearValidate() }) }) } }) // ---------------------------------------------保存相关-------------------------------------- const createRow = () => { addQualityPrevent(ruleForm.value).then((res) => { ElMessage.success('操作成功') infoId.value = res.data }) } const updateRow = () => { updateQualityPrevent({ ...ruleForm.value, id: infoId.value }).then((res) => { ElMessage.success('操作成功') // infoId.value = res.data if (approvalStatusName === '已取消' || approvalStatusName === '未通过') { handleSubmit() } if (approvalStatusName === '全部') { close() } }) } const saveForm = async (formEl: FormInstance | undefined) => { if (!formEl) { return } await formEl.validate((valid, fields) => { if (valid) { if ($route.path.includes('create') && !infoId.value) { createRow() } else if ($route.path.includes('update') || infoId.value) { 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('reject', 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 reject = (comments: string, taskId: string, id: string) => { const param = { id, taskId, // 任务id comments, // 拒绝原因 } rejectApproval(param).then((res) => { if (res.code === 200) { ElMessage.success('已驳回') } else { ElMessage.error(`驳回失败:${res.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('prevent') } // 确认报告 const confirmConformance = (report: any) => { console.log(report, 'report') ruleForm.value.fileRelList = report if (Array.isArray(report) && report.length) { ruleForm.value.description = report[0].problem || report[0].nonDescription // 潜在不符合要求事实描述 } 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 const filePreview = (row: any) => { if (row.fileType === '1') { // 不符合要求情况分析表 getQualityNoReportFile({ id: row.id, pdf: true, }).then((res) => { if (res.data.type.includes('json')) { ElMessage.error('文件获取失败') return } exportFile(res.data, `${row.fileName}.pdf`) }) } else if (row.fileType === '2') { // 内部审核检查表 getReviewFormFile({ id: row.id, pdf: true, }).then((res) => { if (res.data.type.includes('json')) { ElMessage.error('文件获取失败') return } exportFile(res.data, `${row.fileName}.pdf`) }) } else if (row.fileType === '3') { // 内部审核不符合项报告 getNonReviewFormFile({ id: row.id, pdf: true, }).then((res) => { if (res.data.type.includes('json')) { ElMessage.error('文件获取失败') return } exportFile(res.data, `${row.fileName}.pdf`) }) } else if (row.fileType === '5') { // 管理评审报告 getReviewRepFile({ id: row.id, pdf: true, }).then((res) => { if (res.data.type.includes('json')) { ElMessage.error('文件获取失败') return } exportFile(res.data, `${row.fileName}.pdf`) }) } } </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" :form-id="SCHEDULE.PREVENT_MEASURE_PROCESS_SHEET_APPROVAL" :show-next-text="true" @on-success="approvalSuccess" @refuse="refuse" @reject="reject" /> <!-- 选择审批人 --> <select-user ref="userRef" :form-id="SCHEDULE.PREVENT_MEASURE_PROCESS_SHEET_APPROVAL" :show-next-text="true" @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="(`${decisionItem}` === '1' || `${decisionItem}` === '2') && $route.path.includes('detail') && approvalStatusName === '待审批' && showApprovalButton" type="warning" @click="handleApprove('驳回')"> 驳回 </el-button> <el-button v-if="(`${decisionItem}` === '1' || `${decisionItem}` === '3') && $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 !== '已取消' && 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="$route.path.includes('create') ? '系统自动生成' : ''" /> </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 && $route.path.includes('detail')" type="primary" style="margin-right: 10px;" @click="filePreview(ruleForm.fileRelList.length ? ruleForm.fileRelList[0] : {})" > <!-- {{ ruleForm.fileRelList.length ? `${ruleForm.fileRelList[0].fileCode}-${ruleForm.fileRelList[0].fileName}` : '' }} --> {{ ruleForm.fileRelList.length ? `${ruleForm.fileRelList[0]?.fileName}` : '' }} </el-link> <el-button v-else type="primary" link @click="filePreview(ruleForm.fileRelList.length ? ruleForm.fileRelList[0] : {})"> {{ ruleForm.fileRelList.length ? `${ruleForm.fileRelList[0]?.fileName}` : '' }} </el-button> <el-button v-if="!$route.path.includes('detail')" type="primary" @click="selectConformance"> 选择 </el-button> <el-button v-if="!$route.path.includes('detail')" type="primary" @click="uploadFile"> 上传 </el-button> <input ref="fileRef" style="display: none;" type="file" accept=".doc,.docx,.pdf,.xls,.xlsx" @change="onFileChange"> </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="ruleForm.description" placeholder="潜在不符合要求事实描述" :rows="5" 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>