<!-- 管理评审报告编辑页面 -->
<script name="ReviewReportManagetHandler" lang="ts" setup>
import type { FormInstance, FormRules, UploadUserFile } from 'element-plus'
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import dayjs from 'dayjs'
import rectificationContent from './rectificationContent.vue'
import { getDictByCode } from '@/api/system/dict'
import useUserStore from '@/store/modules/user'
import { AGREE, TASKNAME } from '@/views/quality/agree'
import { SCHEDULE } from '@/utils/scheduleDict'
import { UploadFile, getPhotoUrl } from '@/api/file'
import ApprovalDialog from '@/components/ApprovalCustom/ApprovalDialog.vue'
import { getReviewWorkList } from '@/api/quality/review/work'
import selectUser from '@/views/quality/components/selectUser.vue'
import { valiateWork } from '@/utils/valiateWork'
import { addQualityReport, approvalDelete, cancelApproval, delteQualityReport, detailQualityReport, draftDelete, refuseApproval, submitQualityReport, updateQualityReport } from '@/api/quality/review/report'
const $route = useRoute()
const $router = useRouter()
const userStore = useUserStore()
const ruleFormRef = ref<FormInstance>() // from组件
const approvalStatusName = $route.query.approvalStatusName as string
const ruleForm = ref({
id: '',
taskId: '',
yearTime: '',
yearNum: '',
bizLabCode: '',
commanderName: '',
commanderId: '',
creatorName: '',
creator: '',
createTime: '',
fileCode: '',
fileName: '',
reviewTime: '',
content: '',
meetingSituation: '',
reviewDecision: '',
trackingSituation: '',
repItems: [] as any[],
reviewFileName: '',
reviewFilePath: '',
}) // 表单
watch(
[() => ruleForm.value.yearTime, () => ruleForm.value.yearNum],
(newVal, oldVal) => {
if (newVal[0] && newVal[1]) {
console.log(newVal, 'newVal')
// 获取对应的管理评审工作
getReviewWorkList({ limit: 999, offset: 1 }).then((res) => {
const data = res.data.rows.filter((item: any) => item.workName.includes(`${ruleForm.value.yearTime}年第${ruleForm.value.yearNum}`))
if (data.length) {
// 填充数据
ruleForm.value.commanderName = data[0].commanderName
ruleForm.value.commanderId = data[0].commanderId
ruleForm.value.bizLabCode = data[0].bizLabCode
}
})
}
}
, {
deep: true,
},
)
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'] }],
}) // 表单验证规则
const infoId = ref('')
onMounted(() => {
if ($route.path.includes('create')) {
ruleForm.value.createTime = dayjs().format('YYYY-MM-DD') // 记录时间
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.bizLabCode = data.bizLabCode
ruleForm.value.yearNum = data.yearNum
ruleForm.value.yearTime = data.yearTime
}
}
else {
rules.value.fileCode = [{ required: true, message: '文件编号必填', trigger: ['blur', 'change'] }]
detailQualityReport({ id: $route.query.id }).then((res) => {
ruleForm.value = res.data
infoId.value = res.data
nextTick(() => {
ruleFormRef.value?.clearValidate()
})
})
}
})
// ---------------------------------------------保存相关--------------------------------------
const createRow = (data: any) => {
addQualityReport(data).then((res) => {
ElMessage.success('操作成功')
infoId.value = res.data
})
}
const updateRow = (data: any) => {
updateQualityReport(data).then((res) => {
ElMessage.success('操作成功')
// infoId.value = res.data
if (approvalStatusName === '已取消' || approvalStatusName === '未通过') {
handleSubmit()
}
if (approvalStatusName === '全部') {
close()
}
})
}
const contentRef = ref()
const saveForm = async (formEl: FormInstance | undefined) => {
if (!formEl) { return }
await formEl.validate(async (valid, fields) => {
if (valid) {
const ress = await valiateWork(ruleForm.value.yearTime, ruleForm.value.yearNum, ruleForm.value.bizLabCode, '管理评审')
if (!ress) { return }
const data = {
...ruleForm.value,
fileName: `${ruleForm.value.yearTime}年第${ruleForm.value.yearNum}次管理评审报告`,
repItems: contentRef.value.list,
}
if ($route.path.includes('create') && !infoId.value) {
createRow(data)
}
else if ($route.path.includes('update') || infoId.value) {
updateRow({ ...data, id: infoId.value })
}
}
})
}
// ---------------------------------------------审批--------------------------------------
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
submitQualityReport({
formId: SCHEDULE.MANAGE_AUDIT_REPORT_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) {
// submitQualityReport({
// formId: SCHEDULE.MANAGE_AUDIT_REPORT_APPROVAL,
// // processId: infoId.value,
// id: infoId.value || ruleForm.value.id,
// }).then(() => {
// ElMessage.success('提交成功')
// close()
// })
// }
// else {
// ElMessage.warning('请先保存')
// }
// }
// 点击编辑
const handleEdit = () => {
$router.push({
path: `/qreviewreport/update/${ruleForm.value.id}`,
query: { ...$route.query },
})
}
const del = () => {
if (approvalStatusName === '草稿箱') {
draftDelete({ id: ruleForm.value.id }).then(() => {
ElMessage.success('已删除')
// $router.go(-1)
close()
})
}
else if (approvalStatusName === '已取消') {
approvalDelete({ id: ruleForm.value.id, taskId: ruleForm.value.taskId }).then(() => {
ElMessage.success('已删除')
// $router.go(-1)
close()
})
}
else if (approvalStatusName === '全部') { // 全部的删除
delteQualityReport({ id: ruleForm.value.id }).then(() => {
ElMessage.success('已删除')
// $router.go(-1)
close()
})
}
}
// 关闭页面
function close() {
if ($route.query.data) {
$router.go(-1)
}
else {
$router.push({
path: '/qreview/qreviewreport',
})
}
}
const showMenu = ref('基本信息')
defineExpose({
ruleForm, showMenu,
})
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 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),
})
}
}
fetchDict()
// 上传附件
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])
UploadFile(fd).then((res1) => {
if (res1.code === 200) {
ElMessage.success('上传成功')
getPhotoUrl(res1.data[0]).then((res) => {
ruleForm.value.reviewFilePath = res.data
// ruleForm.value.reviewFileName = event.currentTarget.files[0].name
const data = res.data.split('/')
ruleForm.value.reviewFileName = data[data.length - 1]
// dataFormRef.value?.clearValidate('filePath')
fileRef.value.value = ''
console.log(ruleForm.value, 'ruleForm.value11111')
}).catch(() => {
fileRef.value.value = ''
})
}
}).catch(() => {
fileRef.value.value = ''
})
}
}
// 导入
const importList = () => {
fileRef.value.click()
}
// 删除
const deleteFile = () => {
ruleForm.value.reviewFilePath = ''
ruleForm.value.reviewFileName = ''
}
const { proxy } = getCurrentInstance() as any
</script>
<template>
<app-container style="overflow: hidden;">
<!-- 审批弹窗 -->
<approval-dialog ref="approvalDialog" :agree="AGREE.MANAGE_AUDIT_REPORT_APPROVAL" :last-name="TASKNAME.MANAGE_AUDIT_REPORT_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/review/report/agree')" type="primary" @click="handleApprove('同意')">
同意
</el-button>
<el-button v-if="$route.path.includes('detail') && approvalStatusName === '待审批' && showApprovalButton && proxy.hasPerm('/quality/review/report/reject')" type="danger" @click="handleApprove('拒绝')">
拒绝
</el-button>
<el-button v-if="$route.path.includes('detail') && approvalStatusName === '审批中' && showApprovalButton && proxy.hasPerm('/quality/review/report/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/review/report/submit')"
type="primary"
@click="handleSubmit"
>
提交
</el-button>
<el-button v-if="approvalStatusName !== '已审批' && $route.path.includes('detail') && approvalStatusName === '未通过' && proxy.hasPerm('/quality/review/report/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="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="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-row>
<el-row :gutter="24" class="marg">
<el-col :span="6">
<el-form-item label="质量负责人" prop="commanderName">
<el-input v-model.trim="ruleForm.commanderName" disabled placeholder="质量负责人" />
</el-form-item>
</el-col>
<el-col :span="1" />
<el-col :span="6">
<el-form-item label="创建人" prop="creatorName">
<el-input v-model.trim="ruleForm.creatorName" disabled placeholder="创建人" />
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item label="创建时间" prop="createTime">
<el-date-picker
v-model="ruleForm.createTime"
type="datetime"
placeholder="创建时间"
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="reviewTime">
<el-date-picker
v-model="ruleForm.reviewTime"
type="date"
placeholder="评审时间"
style="width: 100%;"
format="YYYY-MM-DD"
value-format="YYYY-MM-DD"
/>
</el-form-item>
</el-col>
<el-col :span="18">
<el-form-item label="附件" prop="reviewFileName">
<a class="link" :href="ruleForm.reviewFilePath" type="primary" style="margin-right: 10px;" target="_blank">
{{ ruleForm.reviewFileName }}
<span v-if="!$route.path.includes('detail') && ruleForm.reviewFileName" class="close" @click.stop.capture.prevent="deleteFile">x</span>
</a>
<el-button v-if="!$route.path.includes('detail')" type="primary" @click="importList">
上传
</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>
<el-row :gutter="24" class="marg">
<el-col :span="24">
<el-form-item label="评审内容" prop="content">
<el-input v-model="ruleForm.content" placeholder="评审内容" type="textarea" :rows="4" />
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="24" class="marg">
<el-col :span="24">
<el-form-item label="评审会议情况综述" prop="meetingSituation">
<el-input v-model="ruleForm.meetingSituation" placeholder="评审会议情况综述" type="textarea" :rows="4" />
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="24" class="marg">
<el-col :span="24">
<el-form-item label="管理评审的决策" prop="reviewDecision">
<el-input v-model="ruleForm.reviewDecision" placeholder="管理评审的决策" type="textarea" :rows="4" />
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="24" class="marg">
<el-col :span="24">
<el-form-item label="跟踪验证情况" prop="trackingSituation">
<el-input v-model="ruleForm.trackingSituation" placeholder="跟踪验证情况" type="textarea" :rows="4" />
</el-form-item>
</el-col>
</el-row>
</detail-block>
<rectification-content ref="contentRef" :data="ruleForm.repItems" />
</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;
}
}
.link {
position: relative;
color: #5d93ff;
// display: inline-block;
font-size: 16px;
text-decoration: none;
// margin-right: 10px;
padding-right: 10px;
// height: 33px;
line-height: 33px;
&:hover {
text-decoration: underline;
.close {
display: block;
}
}
.close {
position: absolute;
top: -20px;
right: -10px;
display: none;
z-index: 99;
height: 40px;
width: 40px;
color: rgb(121 118 115);
// background-color: #ccc;
text-align: center;
}
// &::before {
// content: "x";
// width: 15px;
// height: 15px;
// position: absolute;
// right: -4px;
// top: -16px;
// color: #817d7d;
// font-size: 16px;
// // background-color: #ccc;
// // border-radius: 50%;
// display: none;
// }
// &:hover {
// &::before {
// display: block;
// }
// }
}
</style>