<template>
|
<div class="notice">
|
<el-dialog
|
v-model="dialogVisible"
|
:title="title"
|
width="800px"
|
: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" >
|
<template #default="{row,$index}">
|
<el-form-item :prop="'subscribeHazmats.' + '[' + $index + ']' + '.hazmatName'" >
|
<span>{{row.hazmatName}}</span>
|
</el-form-item>
|
</template>
|
</el-table-column>
|
<el-table-column label="数量" align="center" >
|
<template #default="{row,$index}">
|
<el-form-item :prop="'subscribeHazmats.' + '[' + $index + ']' + '.hazmatCount'">
|
<span>{{row.hazmatCount}}</span>
|
</el-form-item>
|
</template>
|
</el-table-column>
|
</el-table>
|
</div>
|
</el-form-item>
|
<el-form-item label="申购文件:">
|
<div>
|
<el-link type="primary" @click="openFile(state.form.filePath)">{{state.form.fileName}}</el-link>
|
</div>
|
</el-form-item>
|
<el-form-item label="申购人:" >
|
<span>{{state.form.subscribePersonName }}</span>
|
</el-form-item>
|
<el-form-item label="审批人:" >
|
<span>{{state.form.checkName }}</span>
|
</el-form-item>
|
<el-form-item label="审批状态:" v-if="title === '查看' ">
|
<span>{{state.form.status == 1 ? '审批通过' : state.form.status == 2 ?'审批驳回': '未审批' }}</span>
|
</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>
|
</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";
|
|
const dialogVisible = ref(false);
|
const title = ref("");
|
const busRef = ref();
|
const length = ref()
|
const emit = defineEmits(["getList"]);
|
const state = reactive({
|
form: {
|
id: '',
|
creditCode: '',
|
name: '',
|
major: '',
|
phone: '',
|
code: '',
|
subscribeHazmats:[],
|
},
|
})
|
|
|
const openDialog = async (type, value) => {
|
title.value = type === 'approval' ? '审批' : type ==='edit' ? '申购编辑' : '查看' ;
|
state.form = JSON.parse(JSON.stringify(value));
|
dialogVisible.value = true;
|
}
|
|
const handleClose = () => {
|
busRef.value.clearValidate();
|
reset();
|
dialogVisible.value = false;
|
emit("getList")
|
}
|
const reset = () => {
|
state.form = {
|
id: '',
|
creditCode: '',
|
name: '',
|
major: '',
|
phone: '',
|
code: ''
|
}
|
}
|
|
|
|
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>
|