<!-- 内部审核检查表编辑页面 --> <script name="QualityInternalCheckHandler" lang="ts" setup> import type { FormInstance, FormRules, UploadUserFile } from 'element-plus' import { ElLoading, ElMessage, ElMessageBox } from 'element-plus' import dayjs from 'dayjs' import checkContent from './checkContent.vue' import { getTemplateAllList, getTemplateContent } from '@/api/quality/template/template' import { getSearchDept } from '@/api/quality/supervise/record' import { getDictByCode } from '@/api/system/dict' import useUserStore from '@/store/modules/user' import { SCHEDULE } from '@/utils/scheduleDict' import ApprovalDialog from '@/components/ApprovalCustom/ApprovalDialog.vue' import { AGREE, TASKNAME } from '@/views/quality/agree' import { addQualityInspect, approvalDelete, cancelApproval, delteQualityInspect, detailQualityInspect, draftDelete, getInspectList, refuseApproval, submitQualityInspect, updateQualityInspect } from '@/api/quality/internal/inspect' import selectUser from '@/views/quality/components/selectUser.vue' const $route = useRoute() const $router = useRouter() const userStore = useUserStore() const watchFlag = ref(true) const ruleFormRef = ref<FormInstance>() // from组件 const checkRef = ref() // 检查内容 // 当前审批状态名字 const approvalStatusName = $route.query.approvalStatusName as string const ruleForm = ref({ yearTime: '', yearNum: '', bizLabCode: '', createTime: '', fileCode: '', creatorName: '', creator: '', deptId: '', itemList: [] as any[], taskId: '', id: '', }) // 表单 const rules = ref<FormRules>({ yearTime: [{ required: true, message: '年份必选', trigger: ['blur', 'change'] }], yearNum: [{ required: true, message: '月份必选', trigger: ['blur', 'change'] }], bizLabCode: [{ required: true, message: '实验室必选', trigger: ['blur', 'change'] }], deptId: [{ required: true, message: '审核部门必选', trigger: ['blur', 'change'] }], }) // 表单验证规则 onMounted(() => { if ($route.path.includes('create')) { watchFlag.value = false ruleForm.value.createTime = dayjs().format('YYYY-MM-DD HH:mm') // 记录时间 ruleForm.value.creator = userStore.id ruleForm.value.creatorName = userStore.name // 自动填充数据 if ($route.query.data) { const data = JSON.parse($route.query.data as string) console.log(data, 'data') ruleForm.value.yearNum = data.yearNum ruleForm.value.yearTime = data.yearTime ruleForm.value.bizLabCode = data.bizLabCode } } else { rules.value.fileCode = [{ required: true, message: '文件编号必填', trigger: ['blur', 'change'] }] detailQualityInspect({ id: $route.query.id as string }).then((res) => { // console.log(res.data, '详情') ruleForm.value = res.data setTimeout(() => { watchFlag.value = false }, 500) nextTick(() => { ruleFormRef?.value?.clearValidate() }) }) } }) const labelList = ref<{ id: string; value: string; name: string }[]>()// 实验室代码+ const yearList = ref<{ id: string; value: string; name: string }[]>([])// 年度 const monthList = ref<{ id: string; value: string; name: string }[]>([])// 月份 const deptList = ref<{ deptName: string; deptId: string }[]>([]) // 部门列表 const templateList = ref<any[]>([]) // 获取字典值 const fetchDict = () => { // 获取实验室代码字典 getDictByCode('bizLabCode').then((res) => { labelList.value = res.data }) // 循环出最近十年的year // 获取当前年份 const year = new Date().getFullYear() + 5 for (let i = year; i > year - 10; i--) { yearList.value?.push({ name: String(i), value: String(i), id: String(i), }) } yearList.value?.reverse() // 月份 for (let i = 1; i < 13; i++) { monthList.value?.push({ name: String(i), value: String(i), id: String(i), }) } getSearchDept({ labCode: '' }).then((res) => { deptList.value = res.data }) getTemplateAllList({}).then((res) => { templateList.value = res.data }) } fetchDict() // 根据实验室修改部门 watch(() => ruleForm.value.bizLabCode, (newVal) => { if ($route.path.includes('detail') || watchFlag.value) { return } if (newVal) { ruleForm.value.deptId = '' getSearchDept({ labCode: newVal }).then((res) => { deptList.value = res.data }) } else { getSearchDept({ }).then((res) => { deptList.value = res.data }) } }, { deep: true, }) // 根据部门修改检查内容 watch(() => ruleForm.value.deptId, (newVal) => { if ($route.path.includes('detail') || watchFlag.value) { return } console.log(newVal, 'newValnewValnewVal') if (newVal) { const dept = deptList.value.find((item: any) => item.deptId === newVal) as any console.log(dept, 'dept') const professionalGroup = ['电学电源组', '热工力学组', '无线电脉冲组'] as string[] // 专业组 const manageGroup = ['综合管理组'] as string[] // 管理组 if (professionalGroup.some(item => dept.deptName.includes(item))) { // 专业组 getTemplateContent({ id: templateList.value.find((item: any) => item.temName.includes('专业组')).id }).then((res) => { ruleForm.value.itemList = res.data.items }) } else if (manageGroup.some(item => dept.deptName.includes(item))) { // 管理组 getTemplateContent({ id: templateList.value.find((item: any) => item.temName.includes('管理组')).id }).then((res) => { ruleForm.value.itemList = res.data.items }) } } else { ruleForm.value.itemList = [] } }, { deep: true, }) // ---------------------------------------------保存相关-------------------------------------- const infoId = ref('') const createRow = (data: any) => { addQualityInspect(data).then((res) => { ElMessage.success('操作成功') infoId.value = res.data }) } const updateRow = (data: any) => { updateQualityInspect(data).then((res) => { ElMessage.success('操作成功') infoId.value = res.data if (approvalStatusName === '已取消' || approvalStatusName === '未通过') { handleSubmit() } }) } const scheduleRef = ref() const saveForm = async (formEl: FormInstance | undefined) => { if (!formEl) { return } await formEl.validate((valid, fields) => { if (valid) { if (!checkRef.value.checkCertificateList()) { return } const data = { ...ruleForm.value, itemList: checkRef.value.list, fileName: `${ruleForm.value.yearTime}年第${ruleForm.value.yearNum}次内部审核检查表`, } if ($route.path.includes('create')) { createRow(data) } else if ($route.path.includes('update')) { updateRow(data) } } }) } // ---------------------------------------------审批-------------------------------------- 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 submitQualityInspect({ formId: SCHEDULE.INTERNAL_AUDIT_CHECKLIST_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) { // submitQualityInspect({ // formId: SCHEDULE.INTERNAL_AUDIT_CHECKLIST_APPROVAL, // // processId: infoId.value, // id: infoId.value || ruleForm.value.id, // }).then(() => { // ElMessage.success('提交成功') // close() // }) // } // else { // ElMessage.warning('请先保存') // } // } // 点击编辑 const handleEdit = () => { $router.push({ path: `/internalinspect/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 === '全部') { // 全部的删除 delteQualityInspect({ id: ruleForm.value.id }).then(() => { ElMessage.success('已删除') close() }) } } // 关闭页面 function close() { if ($route.query.data) { $router.go(-1) } else { $router.push({ path: '/internal/internalinspect', }) } } const showMenu = ref('基本信息') defineExpose({ ruleForm, showMenu, }) const { proxy } = getCurrentInstance() as any </script> <template> <app-container style="overflow: hidden;"> <!-- 审批弹窗 --> <approval-dialog ref="approvalDialog" :agree="AGREE.INTERNAL_AUDIT_CHECKLIST_APPROVAL" :last-name="TASKNAME.INTERNAL_AUDIT_CHECKLIST_APPROVAL" @on-success="approvalSuccess" @refuse="refuse" /> <!-- 选择审批人 --> <select-user ref="userRef" @confirm="confirmUser" /> <detail-page title="内部审核检查表"> <template #btns> <el-button v-if="$route.path.includes('detail') && approvalStatusName === '待审批' && showApprovalButton && proxy.hasPerm('/quality/internal/inspect/agree')" type="primary" @click="handleApprove('同意')"> 同意 </el-button> <el-button v-if="$route.path.includes('detail') && approvalStatusName === '待审批' && showApprovalButton && proxy.hasPerm('/quality/internal/inspect/reject')" type="danger" @click="handleApprove('拒绝')"> 拒绝 </el-button> <el-button v-if="$route.path.includes('detail') && approvalStatusName === '审批中' && showApprovalButton && proxy.hasPerm('/quality/internal/inspect/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/internal/inspect/submit')" type="primary" @click="handleSubmit" > 提交 </el-button> <el-button v-if="approvalStatusName !== '已审批' && $route.path.includes('detail') && approvalStatusName === '未通过' && proxy.hasPerm('/quality/internal/inspect/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-page v-if="approvalStatusName !== '草稿箱' && !$route.path.includes('create')" title="" class="info-radio"> <el-radio-group v-model="showMenu"> <el-radio-button label="基本信息" /> <el-radio-button label="审批详情" /> </el-radio-group> </detail-page> <el-form v-show="showMenu === '基本信息'" 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="7"> <el-form-item label="工作名称" style="display: flex;"> <el-form-item label="" label-width="0px" prop="yearTime"> <el-select v-model="ruleForm.yearTime" placeholder="年份" class="short-input" filterable style="width: 80px;" > <el-option v-for="item in yearList" :key="item.id" :label="item.name" :value="item.value" /> </el-select> 年第 </el-form-item> <el-form-item label="" label-width="0px" prop="yearNum"> <el-select v-model="ruleForm.yearNum" placeholder="次数" class="short-input" filterable style="width: 80px;" > <el-option v-for="item in monthList" :key="item.id" :label="item.name" :value="item.value" /> </el-select> 次内部审核检查表 </el-form-item> </el-form-item> </el-col> <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="fileCode"> <el-input v-model.trim="ruleForm.fileCode" :placeholder="$route.path.includes('create') ? '系统自动生成' : ''" /> </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" placeholder="创建人" disabled /> </el-form-item> </el-col> <el-col :span="1" /> <el-col :span="6"> <el-form-item label="创建时间" prop="createTime"> <el-date-picker v-model="ruleForm.createTime" type="datetime" placeholder="创建时间" value-format="YYYY-MM-DD HH:mm" format="YYYY-MM-DD HH:mm" style="width: 100%;" disabled /> </el-form-item> </el-col> </el-row> </detail-block> <detail-block title=""> <el-row :gutter="24" class="marg"> <el-col :span="6"> <el-form-item label="受审核部门" prop="deptId"> <el-select v-model="ruleForm.deptId" placeholder="部门" class="short-input" filterable style="width: 100%;" > <el-option v-for="item in deptList" :key="item.deptId" :label="item.deptName" :value="item.deptId" /> </el-select> </el-form-item> </el-col> </el-row> <el-row :gutter="24" class="marg"> <el-col :span="24"> <el-form-item label="检查内容"> <check-content ref="checkRef" :data="ruleForm.itemList" /> </el-form-item> </el-col> </el-row> </detail-block> </el-form> <!-- 审批详情 --> <approval-record-table-custom v-if="showMenu === '审批详情'" :process-id="processId" /> </app-container> </template> <style lang="scss" scoped> .user-container { width: 100%; height: 120px; overflow-y: scroll; border: 1px solid #dcdfe6; border-radius: 5px; } .mx-1 { margin-top: 5px; margin-right: 5px; margin-left: 5px; } .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>