<template>
|
<div class="notice">
|
<el-dialog
|
v-model="dialogVisible"
|
:title="title"
|
width="900px"
|
:before-close="handleClose"
|
:close-on-press-escape="false"
|
:close-on-click-modal="false"
|
>
|
<el-form :model="state.form" size="default" ref="busRef" :rules="state.rules" label-width="130px" >
|
<el-row :gutter="24">
|
<el-col :span="24">
|
<el-form-item label="单位名称:" prop="companyId" v-if="state.isAdmin">
|
<el-select v-model="state.form.companyId" placeholder="请选择" filterable clearable style="width: 100%" :disabled="title == '查看' || title == '编辑' || !state.isAdmin" @change="selectValueCom">
|
<el-option
|
v-for="item in state.companyList"
|
:key="item.id"
|
:label="item.name"
|
:value="item.id">
|
</el-option>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="24">
|
<el-col :span="8">
|
<el-form-item label="申请人:" prop="applyUserName">
|
<el-input disabled v-model="state.form.applyUserName" style="width: 100%"></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="8">
|
<el-form-item label="部门:" prop="applyDeptName">
|
<el-input disabled v-model="state.form.applyDeptName" style="width: 100%"></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="8">
|
<el-form-item label="申请日期:" prop="applyTime">
|
<el-date-picker
|
disabled
|
v-model="state.form.applyTime"
|
type="date"
|
value-format="YYYY-MM-DD"
|
/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="24">
|
<el-col :span="8">
|
<el-form-item label="印章类型:" prop="sealId">
|
<el-select v-model="state.form.sealId" placeholder="请选择" :disabled="title == '查看' ">
|
<el-option
|
v-for="item in state.sealTypeList"
|
:key="item.id"
|
:label="item.sealName"
|
:value="item.id"
|
/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="8">
|
<el-form-item label="盖章份数:" prop="amount">
|
<el-input :disabled="title == '查看' " v-model="state.form.amount" @input="state.form.amount = state.form.amount.replace(/[^0-9]/g,'')" placeholder="盖章份数"></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="8">
|
<el-form-item label="用章日期:" prop="useSealTime">
|
<el-date-picker
|
:disabled="title == '查看' "
|
v-model="state.form.useSealTime"
|
type="date"
|
value-format="YYYY-MM-DD"
|
/>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="24">
|
<el-col :span="15">
|
<el-form-item label="用章事由:" prop="useSealCause">
|
<el-input :disabled="title == '查看' " v-model="state.form.useSealCause" type="textarea" :rows="3" placeholder="用章事由"></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="9">
|
<el-form-item label="是否为红头文件:" prop="isRed">
|
<el-select v-model="state.form.isRed" placeholder="请选择" :disabled="title == '查看' ">
|
<el-option
|
v-for="item in state.redList"
|
:key="item.id"
|
:label="item.name"
|
:value="item.id"
|
/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="24">
|
<el-col :span="12">
|
<el-form-item label="附件" prop="files">
|
<el-upload :disabled="title == '查看' " accept=".jpg,.jpeg,.png,.doc,.docx,.pdf,.xls,.xlsx,.ppt,.pptx" style="width: 100%" :action="state.uploadUrl" :headers="state.header" method="post" :on-success="(res, uploadFile)=>handleAvatarSuccess(res, uploadFile)" :on-exceed="showTip" v-model:file-list="state.fileList" :before-upload="picSize" :on-remove="(file, uploadFiles)=>handleRemove(file, uploadFiles)" :on-preview="openFile">
|
<el-button type="primary">点击上传</el-button>
|
</el-upload>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="24" v-if="title == '查看'">
|
<el-col :span="24" style="margin-left: 50px">
|
<span style="font-size: 19px;font-weight: 600;">签字意见</span>
|
<el-table :data="state.form.flows" :border="true" style="width: 90%;margin-top: 10px">
|
<el-table-column label="流程名称" prop="flowName" width="220" align="center"></el-table-column>
|
<el-table-column label="内容" align="center">
|
<template #default="scope">
|
<span>{{scope.row.approveDeptName}}/{{scope.row.approveUserName}} {{scope.row.approveTime}} {{scope.row.approveContent}} {{scope.row.approveMess}}</span>
|
</template>
|
</el-table-column>
|
</el-table>
|
</el-col>
|
</el-row>
|
</el-form>
|
<template #footer v-if="title !== '查看'">
|
<span class="dialog-footer">
|
<el-button @click="handleClose" size="default">取 消</el-button>
|
<el-button type="primary" @click="onSubmit" size="default" v-preReClick>确认</el-button>
|
</span>
|
</template>
|
</el-dialog>
|
</div>
|
</template>
|
<script setup>
|
import {onMounted, reactive, ref, toRefs} from 'vue'
|
import Cookies from "js-cookie";
|
import {getCompany} from "@/api/onlineEducation/company";
|
import {ElMessage, ElMessageBox} from "element-plus";
|
import {getUser} from "@/api/onlineEducation/user";
|
import {addObjective, editObject, getDept} from "@/api/qualityObjectives/object";
|
import {listUser} from "@/api/system/user";
|
import moment from "moment";
|
import {getToken} from "@/utils/auth";
|
import {getDepartById, getDeptInfo} from "@/api/orgStructure/depart";
|
import {getSealType} from "@/api/sealManage/type";
|
import {addSealApply, editSealApply} from "@/api/sealManage/apply";
|
import {getSealFlow} from "@/api/sealManage/process";
|
import {renderAsync} from "docx-preview";
|
|
const dialogVisible = ref(false);
|
const title = ref("");
|
const busRef = ref();
|
const length = ref()
|
const emit = defineEmits(["getList"]);
|
const dataRef = ref();
|
const state = reactive({
|
form: {
|
id: '',
|
companyId: null,
|
applyUserId: null,
|
applyDeptId: null,
|
applyTime: "",
|
sealId: null,
|
amount: null,
|
useSealTime: "",
|
useSealCause: "",
|
isRed: "",
|
nextCheck: "",
|
flows:[],
|
files:[],
|
applyUserName:'',
|
applyDeptName:''
|
},
|
sealTypeList:[],
|
redList:[
|
{
|
id: 0,
|
name: '否'
|
},
|
{
|
id: 1,
|
name: '是'
|
},
|
],
|
uploadUrl: import.meta.env.VITE_APP_BASE_API + '/system/common/uploadFile',
|
header: {
|
Authorization: getToken()
|
},
|
rules: {
|
companyId: [{ required: true, message: '请选择企业', trigger: 'blur' }],
|
sealId: [{ required: true, message: '请选择用章类型', trigger: 'blur' }],
|
amount: [{ required: true, message: '请输入盖章份数', trigger: 'blur' }],
|
useSealTime: [{ required: true, message: '请选择用章日期', trigger: 'blur' }],
|
useSealCause:[{ required: true, message: '请输入用章事由', trigger: 'blur' }],
|
files:[{ required: true, message: '请上传附件', trigger: 'blur' }],
|
// nextCheck: "",
|
// flows:[],
|
},
|
isAdmin: false,
|
companyList: [],
|
deptList: [],
|
fileList: [],
|
})
|
|
const openDialog = async (type, value,companyList) => {
|
title.value = type === 'add' ? '新增' : type ==='edit' ? '编辑' : '查看' ;
|
const userInfo = JSON.parse(Cookies.get('userInfo'))
|
state.isAdmin = userInfo.userType === 0;
|
state.form.companyName = userInfo.companyName
|
state.form.companyId = userInfo.companyId
|
if(type=='add'){
|
//申请人信息
|
state.form.applyUserId = userInfo.id
|
state.form.applyUserName = userInfo.name
|
state.form.applyDeptId = userInfo.deptId
|
state.form.applyDeptName = userInfo.deptName
|
const nowDate = new Date()
|
state.form.applyTime = moment(nowDate).format('YYYY-MM-DD')
|
const obj = {
|
flowName: '申请人',
|
approveUserId: state.form.applyUserId,
|
approveDeptId: state.form.applyDeptId,
|
approveUserName: state.form.applyUserName,
|
approveDeptName: state.form.applyDeptName,
|
approveContent: "提交",
|
approveTime: state.form.applyTime,
|
approveStatus: 1,
|
status: null
|
}
|
state.form.flows[0]=obj
|
if(!state.form.applyDeptId){
|
ElMessage.warning('该用户无所属部门!')
|
return
|
|
}
|
//部门负责人信息
|
await getLeaderInfo()
|
await getFlowList()
|
}
|
if(state.isAdmin){
|
state.companyList = companyList
|
state.form.companyId = null
|
}
|
|
if(type === 'edit' || type === 'review') {
|
state.form = JSON.parse(JSON.stringify(value));
|
state.form.compilationBy = state.form.compilationId
|
state.form.leadBy = state.form.leadId
|
state.form.qualityBy = state.form.qualityId
|
if(state.isAdmin){
|
state.form.companyId = value.companyId
|
state.form.companyName = value.companyName
|
}
|
state.fileList = value.files.map(i => {
|
return {
|
name: i.fileName,
|
path: i.filePath
|
}
|
})
|
}
|
await getSealTypeList()
|
|
dialogVisible.value = true;
|
}
|
const getLeaderInfo = async ()=> {
|
const res = await getDeptInfo(state.form.applyDeptId)
|
if(res.code === 200){
|
|
const obj = {
|
flowName: '部门负责人',
|
approveUserId: res.data.leaderUserId,
|
approveDeptId: res.data.deptId,
|
approveUserName: res.data.leaderName,
|
approveDeptName: res.data.deptName,
|
approveContent: '',
|
approveMess:'',
|
approveTime: null,
|
approveStatus: null,
|
status: null
|
}
|
state.form.flows[1]=obj
|
state.form.nextCheck = res.data.leaderUserId
|
}else{
|
ElMessage.warning(res.message)
|
}
|
}
|
|
const addObject = () => {
|
state.form.qualityTargets.push({})
|
}
|
const getSealTypeList = async () => {
|
const param = {
|
pageNum: 1,
|
pageSize: 999,
|
companyId: state.form.companyId
|
}
|
const res = await getSealType(param)
|
if(res.code === 200){
|
state.sealTypeList = res.data.list
|
}else {
|
ElMessage.warning(res.message)
|
}
|
}
|
const getFlowList = async () => {
|
const param = {
|
pageNum: 1,
|
pageSize: 999,
|
companyId: state.form.companyId
|
}
|
|
const res = await getSealFlow(param)
|
if(res.code === 200){
|
res.data.forEach(item => {
|
item.approveDeptName = item.deptName
|
item.approveDeptId = item.deptId
|
})
|
if(title.value == '新增'){
|
state.form.flows = state.form.flows.concat(res.data)
|
}
|
|
|
}else {
|
ElMessage.warning(res.message)
|
}
|
}
|
const onSubmit = async () => {
|
const valid = await busRef.value.validate();
|
if(valid){
|
if(title.value === '新增'){
|
console.log('sta',state.form)
|
state.form.flows[0].approveTime = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
|
const {id, ...data} = JSON.parse(JSON.stringify(state.form))
|
const res = await addSealApply(data)
|
if(res.code === 200){
|
ElMessage({
|
type: 'success',
|
message: '新增成功'
|
});
|
}else{
|
ElMessage.warning(res.message)
|
}
|
emit("getList")
|
busRef.value.clearValidate();
|
reset();
|
dialogVisible.value = false;
|
}else if(title.value === '编辑'){
|
const {...data} = JSON.parse(JSON.stringify(state.form))
|
const res = await editSealApply(data)
|
if(res.code === 200){
|
ElMessage({
|
type: 'success',
|
message: '编辑成功'
|
});
|
}else{
|
ElMessage.warning(res.message)
|
}
|
emit("getList")
|
busRef.value.clearValidate();
|
reset();
|
dialogVisible.value = false;
|
}
|
}
|
}
|
|
const handleClose = () => {
|
busRef.value.clearValidate();
|
reset();
|
dialogVisible.value = false;
|
emit("getList")
|
|
}
|
const reset = () => {
|
state.form = {
|
id: '',
|
companyId: null,
|
applyUserId: null,
|
applyDeptId: null,
|
applyTime: "",
|
sealId: null,
|
amount: null,
|
useSealTime: "",
|
useSealCause: "",
|
isRed: "",
|
nextCheck: "",
|
flows:[],
|
files:[],
|
applyUserName:'',
|
applyDeptName:''
|
}
|
state.peopleList = []
|
state.companyList = []
|
state.fileList = []
|
|
}
|
const handleDelete = (val) => {
|
state.form.qualityTargets = state.form.qualityTargets.filter(item=> item != val)
|
}
|
|
const handleAvatarSuccess = (response,uploadFile) => {
|
if(response.code == 200){
|
state.form.files = state.fileList.map(item => {
|
return {
|
fileName: item.response ? item.response?.data.originName: item.name,
|
filePath: item.response ? item.response?.data.path: item.path
|
}
|
})
|
}else{
|
// state.fileList = []
|
// state.form.files = []
|
ElMessage({
|
type: 'warning',
|
message: response.message
|
})
|
}
|
}
|
|
const showTip =()=>{
|
ElMessage({
|
type: 'warning',
|
message: '超出文件上传数量'
|
});
|
}
|
const picSize = async (rawFile) => {
|
if(rawFile.size / 1024 / 1024 > 5){
|
ElMessage({
|
type: 'warning',
|
message: '文件大小不能超过5M'
|
});
|
return false
|
}
|
};
|
const handleRemove = async (file, uploadFiles) => {
|
state.form.files = state.fileList.map(item => {
|
return {
|
fileName: item.response ? item.response?.data.originName: item.name,
|
filePath: item.response ? item.response?.data.path: item.path
|
}
|
})
|
}
|
const selectValue = (val) => {
|
state.peopleList.forEach(item => {
|
if(item.name === val){
|
state.form.compilationBy = item.id
|
}
|
})
|
}
|
|
const selectValueCom = (val) => {
|
state.form.sealId = null
|
state.companyList.forEach(item => {
|
if(item.id === val){
|
state.form.companyName = item.name
|
}
|
})
|
getSealTypeList()
|
getFlowList()
|
}
|
|
const openFile = async(file)=>{
|
const path = file.path
|
const ext = path.split('.').pop().toLowerCase();
|
if (ext === 'doc' || ext === 'xls' || ext === 'xlsx'|| ext === 'ppt'|| ext === 'pptx') {
|
ElMessageBox.confirm('暂不支持线上预览.doc文件,是否下载查看?', '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning' }).then(() => {
|
window.open(`${import.meta.env.VITE_APP_BASE_API}/${path}`, '_blank');
|
}).catch(() => {
|
console.log('取消预览')
|
});
|
return
|
}else if(ext === 'docx'){
|
try {
|
// 1. 获取文件
|
const response = await fetch(import.meta.env.VITE_APP_BASE_API + '/' + path);
|
const arrayBuffer = await response.arrayBuffer();
|
// 2. 创建新窗口
|
const win = window.open('', '_blank')
|
win.document.write(`
|
<!DOCTYPE html>
|
<html>
|
<head>
|
<title>预览</title>
|
<style>
|
body { margin: 20px; font-family: Arial; }
|
.docx-container { width: 100%; height: 100%; }
|
</style>
|
</head>
|
<body>
|
<div id="container" class="docx-container"></div>
|
</body>
|
</html>
|
`);
|
// 3. 渲染 DOCX
|
await renderAsync(arrayBuffer, win.document.getElementById('container'));
|
|
} catch (error) {
|
console.error('预览失败:', error);
|
alert(`预览失败: ${error.message}`);
|
}
|
}else {
|
window.open(`${import.meta.env.VITE_APP_BASE_API}/${path}`, '_blank');
|
}
|
|
}
|
defineExpose({
|
openDialog
|
});
|
|
</script>
|
|
<style scoped lang="scss">
|
.notice{
|
:deep(.el-form .el-form-item__label) {
|
font-size: 15px;
|
}
|
.file {
|
display: flex;
|
flex-direction: column;
|
align-items: flex-start;
|
}
|
}
|
</style>
|