<!-- 上传分包方签字版 --> <script lang="ts" setup name="UploadFileDialog"> import type { FormInstance, FormRules } from 'element-plus' import { ElLoading, ElMessage } from 'element-plus' import useUserStore from '@/store/modules/user' import { UploadFile } from '@/api/file' import { uploadSignFile } from '@/api/business/subpackage/agreement' const emit = defineEmits(['onSuccess', 'refuse']) // 弹窗显示状态 const dialogVisible = ref(false) // 默认表单 const form = ref({ id: '', accessOtherFile: '', }) // 保存按钮加载状态 const btnLoading = ref(false) const userInfo = useUserStore() // ---------------表单提交-------------------------------- // 表单对象 const dataFormRef = ref<FormInstance>() // 校验规则 const rules: FormRules = reactive({ accessOtherFile: [{ required: true, message: '测试、校准或检定工作分包协议书必填', trigger: ['blur', 'change'] }], }) /** * 初始化弹窗 */ function initDialog(id: string, accessFile: string) { form.value.id = id form.value.accessOtherFile = accessFile dialogVisible.value = true } // 提交表单 function submitForm() { if (dataFormRef) { dataFormRef.value?.validate((valid: boolean) => { if (valid) { btnLoading.value = true uploadSignFile({ ...form.value, }).then(() => { ElMessage.success('上传成功') btnLoading.value = false handleClose() }) } }) } } // 关闭弹窗 function handleClose() { dataFormRef.value?.resetFields() dialogVisible.value = false } // -------------------------------------------文件上传-------------------------------------- const fileRef = ref() // 文件上传input const onFileChange = (event: any) => { if (event.target.files?.length !== 0) { if (event.target.files[0].type !== 'application/pdf') { ElMessage.warning('请上传pdf') return false } // 创建formdata对象 const fd = new FormData() fd.append('multipartFile', event.target.files[0]) btnLoading.value = true UploadFile(fd).then((res) => { if (res.code === 200) { form.value.accessOtherFile = res.data[0] event.target.value = null // 重置当前验证 // ElMessage.success('文件上传成功') btnLoading.value = false } else { ElMessage.error(res.message) btnLoading.value = false } }) } } const upload = () => { fileRef.value.click() } // ----------------------- 以下是暴露的方法内容 ---------------------------- defineExpose({ initDialog }) </script> <template> <div class="approval-dialog"> <el-dialog v-model="dialogVisible" title="上传分包方签字版" width="900px" :before-close="handleClose" > <el-form ref="dataFormRef" v-loading="btnLoading" label-position="left" label-width="80px" :model="form" :rules="rules" > <el-row :gutter="24" class="marg"> <el-col :span="24"> <el-form-item label="测试、校准或检定工作分包协议书(分包方签字版):" label-width="360px" prop="accessOtherFile"> <show-photo v-if="form.accessOtherFile" :minio-file-name="form.accessOtherFile" /> <span v-else-if="pageType === 'detail'">无</span> <input v-show="pageType === ''" ref="fileRef" type="file" @change="onFileChange"> <el-button v-if="pageType !== 'detail'" id="file" type="primary" :disabled="pageType === 'detail'" :style="{ 'margin-left': form.accessOtherFile === '' ? '0px' : '20px' }" @click="upload"> {{ form.accessOtherFile === '' ? '上传' : '更换附件' }} </el-button> </el-form-item> </el-col> </el-row> </el-form> <template #footer> <el-button type="primary" :loading="btnLoading" @click="submitForm"> 确定 </el-button> <el-button type="info" @click="handleClose"> 取消 </el-button> </template> </el-dialog> </div> </template> <style lang="scss"> .approval-dialog { .el-radio__label { display: block !important; } } </style>