<template>
|
<div class="notice">
|
<el-dialog
|
v-model="dialogVisible"
|
:title="title"
|
width="850px"
|
:before-close="handleClose"
|
:close-on-press-escape="false"
|
:close-on-click-modal="false"
|
>
|
<el-form :model="state.form" size="default" ref="busRef" :rules="state.formRules" label-width="150px" >
|
<el-form-item required label= "危化品列表" >
|
<div style="display: flex;width: 100%;margin-top: 5px">
|
<el-table :data="state.form.subscribeHazmats" :border="true">
|
<el-table-column type="index" label="序号" width="80" align="center"></el-table-column>
|
<el-table-column label="危化品名称" align="center" width="200" >
|
<template #default="{row,$index}">
|
<el-form-item :prop="'subscribeHazmats.' + '[' + $index + ']' + '.hazmatName'" :rules="state.formRules.hazmatName">
|
<el-select
|
clearable
|
v-model="row.hazmatName"
|
filterable
|
remote
|
@change="selectValueHazmat(row.hazmatName,$index)"
|
reserve-keyword
|
placeholder="请输入危化品名称"
|
remote-show-suffix
|
:remote-method="getHazmaList"
|
style="width: 100%"
|
>
|
<el-option
|
v-for="item in state.hazmatList"
|
:key="item.id"
|
:label="item.name"
|
:value="item.name"
|
/>
|
</el-select>
|
<!-- <el-input type="textarea" :rows="1" v-model="row.hazmatName" placeholder="请输入危化品名称"></el-input>-->
|
</el-form-item>
|
</template>
|
</el-table-column>
|
<el-table-column label="数量" align="center" >
|
<template #default="{row,$index}">
|
<el-form-item :prop="'subscribeHazmats.' + '[' + $index + ']' + '.hazmatCount'" :rules="state.formRules.hazmatCount">
|
<el-input v-model="row.hazmatCount" @input="row.hazmatCount = row.hazmatCount.replace(/[^0-9]/g,'')" placeholder="请输入数量"></el-input>
|
</el-form-item>
|
</template>
|
</el-table-column>
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" v-if="title !== '查看'" >
|
<template #default="scope" >
|
<el-button link type="danger" @click="handleDelete(scope.row)" >删除</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
<el-button
|
v-if="title !== '查看'"
|
style="margin-left: 20px"
|
type="primary"
|
@click="addObject"
|
>新增</el-button>
|
</div>
|
</el-form-item>
|
<el-form-item label="审批人:" prop="checkId" >
|
<el-select
|
clearable
|
v-model="state.form.checkName"
|
filterable
|
remote
|
@change="selectValue"
|
reserve-keyword
|
placeholder="请输入审批人名称"
|
remote-show-suffix
|
:remote-method="getPeopleList"
|
style="width: 50%"
|
>
|
<el-option
|
v-for="item in state.peopleList"
|
:key="item.id"
|
:label="item.name"
|
:value="item.name"
|
/>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="申购文件:" prop="filePath">
|
<el-upload accept=".doc,.docx,.xls,.xlsx,.pdf" v-if="title!=='查看'" :action="state.uploadUrl" :headers="state.header" method="post" :on-success="(res, uploadFile)=>handleAvatarSuccess(res, uploadFile)" :on-exceed="showTip" :limit='state.fileLimit' v-model:file-list="state.fileList" :before-upload="picSize" :on-remove="(file)=>handleRemove(file)" >
|
<el-button type="primary">点击上传</el-button>
|
<template #tip>
|
<div class="el-upload__tip">支持上传.doc、.docx、.pdf、.xls、.xlsx格式文档,尺寸小于50M,最多可上传1个</div>
|
</template>
|
</el-upload>
|
<div v-else>
|
<el-link v-if="state.form.fileName" style="" type="primary" @click="openFile(state.form.filePath)">{{state.form.fileName}}</el-link>
|
</div>
|
</el-form-item>
|
<el-form-item label="审批意见:" v-if="title === '查看' && state.form.status == 2" style="width: 70%">
|
<el-input v-model="state.form.opinion" type="textarea" :rows="5"></el-input>
|
</el-form-item>
|
</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 {reactive, ref, toRefs} from 'vue'
|
import {ElMessage, ElMessageBox} from "element-plus";
|
import {addCompany, checkName, distributeCompany, editCompany} from "@/api/hazardousChemicals/company";
|
import {verifyPhone, verifyPwd} from "@/utils/validate";
|
import {getUser} from "@/api/hazardousChemicals/user";
|
import {getToken} from "@/utils/auth";
|
import {renderAsync} from "docx-preview";
|
import {addSubscribe, editSubscribe} from "@/api/hazardousChemicals/subscribeApply";
|
import {getBasicList} from "@/api/hazardousChemicals/basicInfo";
|
|
const dialogVisible = ref(false);
|
const title = ref("");
|
const busRef = ref();
|
const length = ref()
|
const emit = defineEmits(["getList"]);
|
const state = reactive({
|
form: {
|
id: '',
|
checkId: null,
|
checkName:'',
|
filePath: '',
|
fileName: '',
|
subscribeHazmats:[],
|
},
|
formRules:{
|
checkId: [{ required: true, message: '请选择审核人', trigger: 'blur' }],
|
filePath:[{ required: true, message: '请上传文件', trigger: 'blur' }],
|
hazmatName: [{ required: true, message: '', trigger: 'blur' }],
|
hazmatCount: [{ required: true, message: '', trigger: 'blur' }],
|
},
|
|
peopleList:[],
|
hazmatList:[],
|
fileList:[],
|
uploadUrl: import.meta.env.VITE_APP_BASE_API + '/system/common/uploadFile',
|
header: {
|
Authorization: getToken()
|
},
|
fileLimit: 1,
|
})
|
|
|
const openDialog = async (type, value) => {
|
await getPeopleList("")
|
await getHazmaList("")
|
title.value = type === 'add' ? '申购申请' : type ==='edit' ? '申购编辑' : '查看' ;
|
if(type === 'edit' || type === 'view') {
|
state.form = JSON.parse(JSON.stringify(value));
|
if(state.form.filePath) {
|
const obj = {
|
url: value.filePath,
|
name: value.fileName
|
}
|
state.fileList = [obj]
|
}
|
}
|
dialogVisible.value = true;
|
}
|
|
const onSubmit = async () => {
|
const valid = await busRef.value.validate();
|
if(valid){
|
if(title.value === '申购申请'){
|
const {id, ...data} = JSON.parse(JSON.stringify(state.form))
|
const res = await addSubscribe(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 editSubscribe(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: '',
|
checkId: null,
|
filePath: '',
|
fileName: '',
|
subscribeHazmats:[],
|
}
|
state.fileList = []
|
}
|
const addObject = () => {
|
|
state.form.subscribeHazmats.push({hazmatName:'',hazmatCount:null})
|
}
|
const handleDelete = (val) => {
|
state.form.subscribeHazmats = state.form.subscribeHazmats.filter(item=> item != val)
|
}
|
const selectValue = (val) => {
|
if(!val){
|
state.form.checkId = null
|
}
|
state.peopleList.forEach(item => {
|
if(item.name === val){
|
state.form.checkId = item.id
|
state.form.checkName = item.name
|
}
|
})
|
}
|
|
const getPeopleList = async (val)=>{
|
let queryParams = {}
|
if(val != ""){
|
queryParams = {
|
name: val
|
}
|
}else {
|
queryParams = {
|
pageNum: 1,
|
pageSize: 10
|
}
|
}
|
const res = await getUser(queryParams)
|
if (res.code == 200) {
|
state.peopleList = res.data.list
|
} else {
|
ElMessage.warning(res.message)
|
}
|
}
|
const selectValueHazmat = (val,index) => {
|
if(!val){
|
state.form.subscribeHazmats.forEach((item, i) => i === index && (item.basicId = null));
|
}
|
const match = state.hazmatList.find(item => item.name === val);
|
if (match) {
|
state.form.subscribeHazmats[index].basicId = match.id;
|
state.form.subscribeHazmats[index].hazmatName = match.name;
|
}
|
}
|
const getHazmaList = async (val)=>{
|
let queryParams = {}
|
if(val != ""){
|
queryParams = {
|
name: val
|
}
|
}else {
|
queryParams = {
|
pageNum: 1,
|
pageSize: 10
|
}
|
}
|
const res = await getBasicList(queryParams)
|
if(res.code == 200){
|
state.hazmatList = res.data.list
|
}else{
|
ElMessage.warning(res.message)
|
}
|
}
|
const handleAvatarSuccess = (res, uploadFile) => {
|
if(res.code == 200){
|
state.form.fileName = res.data.originName
|
state.form.filePath = res.data.path
|
state.form.format = '.' + res.data.filename.split('.')[1]
|
}else{
|
state.fileList = []
|
ElMessage({
|
type: 'warning',
|
message: '文件上传失败'
|
})
|
}
|
}
|
|
const showTip =()=>{
|
ElMessage({
|
type: 'warning',
|
message: '超出文件上传数量'
|
});
|
}
|
const picSize = async (rawFile) => {
|
if(rawFile.size / 1024 / 1024 > 50){
|
ElMessage({
|
type: 'warning',
|
message: '文件大小不能超过50M'
|
});
|
return false
|
}
|
};
|
const handleRemove = async (file) => {
|
const index = state.fileList.indexOf(file)
|
const newFileList = state.fileList.slice()
|
newFileList.splice(index, 1)
|
state.fileList = newFileList;
|
}
|
const openFile = async(path)=>{
|
const ext = path.split('.').pop().toLowerCase();
|
if (ext === 'doc' || ext === 'xls' || ext === 'xlsx' || ext === 'ppt' || ext === 'pptx') {
|
ElMessageBox.confirm(`暂不支持线上预览.${ext}文件,是否下载查看?`, '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning' }).then(() => {
|
window.open(`${import.meta.env.VITE_APP_BASE_API}/${path}`, '_blank');
|
}).catch(() => {
|
console.log('取消预览')
|
});
|
return
|
}else if(ext === 'pdf' || ext === 'jpg'|| ext === 'jpeg' || ext === 'png' ){
|
window.open(`${import.meta.env.VITE_APP_BASE_API}/${path}`, '_blank');
|
}else{
|
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}`);
|
}
|
}
|
}
|
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>
|