<!-- 在用软件详情 --> <script name="SoftwareInfoDetail" lang="ts" setup> import type { UploadProps } from 'element-plus' import { ElLoading, ElMessage, ElMessageBox, dayjs } from 'element-plus' import type { ISoftwareInfo } from './software-info' import { UploadFile } from '@/api/file' import { detailSoftware, getSoftwareChangeLog } from '@/api/resource/software' // 从路由中传过来的参数 const type = ref<string>('') const id = ref<string>('') const route = useRoute() const router = useRouter() const title = ref('') const radioItems = ref([ { name: '基本信息', value: 'software-basic' }, { name: '变更记录', value: 'software-changeLog' }, ]) const current = ref('') const currentLabel = ref('') const basicFormRef = ref() const softwareInfo = ref<ISoftwareInfo>({ id: '', reportNo: '', softwareName: '', softwareVersion: '', softwareDocument: '', functionDocument: '', sourceCode: '', dataValidationRecord: '', remark: '', createTime: '', createUserName: '', }) const sealInfoRules = ref({ sealNo: [{ required: true, message: '印章编号不能为空', trigger: 'blur' }], sealName: [{ required: true, message: '印章名称不能为空', trigger: 'blur' }], sealType: [{ required: true, message: '印章类型不能为空,请选择', trigger: ['blur', 'change'] }], approverId: [{ required: true, message: '批准人不能为空', trigger: ['blur', 'change'] }], applyTime: [{ required: true, message: '申请时间不能为空,请选择', trigger: 'blur' }], ratifyTime: [{ required: true, message: '批准时间不能为空,请选择', trigger: 'blur' }], status: [{ required: true, message: '在用状态不能为空,请选择', trigger: ['blur', 'change'] }], minioFileName: [{ required: true, message: '图形不能为空,请选择一个文件上传', trigger: 'blur' }], }) // 表单验证规则 // 逻辑 // 详情页的各个tab切换操作 const radioChangeHandler = (newVal: string | number | boolean) => { const radioTarget = radioItems.value.filter(item => item.name === newVal) if (radioTarget.length > 0) { currentLabel.value = radioTarget[0].name current.value = radioTarget[0].value } else { currentLabel.value = radioItems.value[0].name current.value = radioItems.value[0].value } } const resetForm = () => { sessionStorage.removeItem('sealInfo') // 返回列表时 将缓存中的数据删除 router.go(-1) } // 添加 const saveSealInfoForm = () => { // 将创建时间改为提交的时间 softwareInfo.value.createTime = dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss') addSealInfo(softwareInfo.value).then((res) => { if (res.code === 200) { // 提示保存成功 ElMessage.success('保存成功') type.value = 'detail' title.value = '印章管理登记(详情)' } else { // 提示失败信息 ElMessage.error(`保存失败:${res.message}`) } }) } // 编辑 const updateSealInfoById = () => { updateSealInfo(softwareInfo.value).then((res) => { if (res.code === 200) { // 提示保存成功 ElMessage.success('保存成功') type.value = 'detail' title.value = '印章管理登记(详情)' } else { // 提示失败信息 ElMessage.error(`保存失败:${res.message}`) } }) } // 查询详情 const detail = (softwareId: string) => { detailSoftware({ id: softwareId }).then((res) => { if (res.code === 200) { softwareInfo.value = res.data } }) } // 查询变更记录 const getChangeLogs = (softwareId: string) => { getSoftwareChangeLog({ id: softwareId }).then((res) => { if (res.code === 200) { softwareInfo.value = res.data } }) } // 保存 const saveForm = async () => { if (!basicFormRef) { return } await basicFormRef.value.validate((valid: boolean, fields: any) => { if (valid === true) { ElMessageBox.confirm( '确认保存吗?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning', }, ).then(() => { if (type.value === 'create') { saveSealInfoForm() } else if (type.value === 'update') { updateSealInfoById() } }) } }) } // 上传请求 const uploadQuarterlyEvaluateFile: any = (file: any) => { const fd = new FormData() fd.append('multipartFile', file.file) const loading = ElLoading.service({ lock: true, background: 'rgba(255, 255, 255, 0.8)', }) UploadFile(fd).then((res) => { if (res.code === 200) { ElMessage.success('上传成功') softwareInfo.value.minioFileName = res.data[0] loading.close() basicFormRef.value.validateField('minioFileName', () => {}) } }).catch(() => { loading.close() ElMessage.error('上传失败') }) } // 上传之前的验证 const beforeAvatarUpload: UploadProps['beforeUpload'] = (rawFile) => { if (rawFile.type !== 'image/jpeg' && rawFile.type !== 'image/png' && rawFile.type !== 'image/jpg') { ElMessage.error('只能上传png/jpeg/jpg格式的图片') return false } else if (rawFile.size / 1024 / 1024 > 2) { ElMessage.error('图片不能大于2MB') return false } return true } // 预览文件 const previewSealImage = (url: string) => { console.log(url) } const initDialog = (params: any) => { // 从路由中获取参数 type.value = params.type id.value = params.id !== undefined ? params.id : '' // 默认显示第一个tab内容 current.value = radioItems.value[0].value currentLabel.value = radioItems.value[0].name switch (params.type) { case 'update': title.value = '在用软件详情(编辑)' id.value = params.id softwareInfo.value = JSON.parse(sessionStorage.getItem('sealInfo')!) break case 'detail': title.value = '在用软件详情' id.value = params.id detail(id.value) break default: title.value = '' break } } onMounted(async () => { initDialog(route.query) }) </script> <template> <app-container> <detail-page :title="`${title}`"> <template #btns> <el-button v-if="type !== 'detail'" type="primary" @click="saveForm()"> 保存 </el-button> <el-button type="info" @click="resetForm()"> 关闭 </el-button> </template> <el-radio-group v-model="currentLabel" style="margin-bottom: 20px;" @change="radioChangeHandler"> <el-radio-button v-for="item in radioItems" :key="item.value" :label="item.name" :disabled="id === ''" /> </el-radio-group> <el-form ref="basicFormRef" :model="softwareInfo" :rules="sealInfoRules" label-position="right" label-width="110px" border stripe> <el-row :gutter="24"> <!-- 第一行 第一列 --> <el-col :span="6"> <el-form-item label="软件评审报告"> <el-input v-model="softwareInfo.reportNo" :disabled="true" /> </el-form-item> </el-col> <!-- 第一行 第二列 --> <el-col :span="6"> <el-form-item label="软件名称"> <el-input v-model="softwareInfo.softwareName" :disabled="true" /> </el-form-item> </el-col> <!-- 第一行 第三列 --> <el-col :span="6"> <el-form-item label="版本号"> <el-input v-model="softwareInfo.softwareVersion" :disabled="true" /> </el-form-item> </el-col> <!-- 第一行 第四列 --> <el-col :span="6"> <el-form-item label="创建人"> <el-input v-model="softwareInfo.createUserName" :disabled="true" /> </el-form-item> </el-col> </el-row> </el-form> </detail-page> <template v-if="current === 'software-changeLog' && type === 'detail'"> <approval-record-table :process-id="softwareInfo.id" /> </template> </app-container> </template>