<template>
|
<div>
|
<div class="header">
|
<div>防雷检测</div>
|
<div>
|
<el-button type="primary" size="small" @click="clickAdd">导 入</el-button>
|
<el-button type="primary" size="small" @click="downLoadPost">导 出</el-button>
|
</div>
|
</div>
|
<el-table
|
:data="tableData"
|
style="width: 100%"
|
height="calc(100vh - 18em)">
|
<el-table-column type="index" label="序号" width="120">
|
<template v-slot="scope">
|
<span>{{ (search.current - 1) * search.size + scope.$index + 1 }}</span>
|
</template>
|
</el-table-column>
|
<el-table-column
|
prop="fileName"
|
label="原文件名"
|
min-width="180">
|
</el-table-column>
|
<el-table-column
|
prop="detectionDate"
|
label="检测日期"
|
min-width="180">
|
</el-table-column>
|
<el-table-column
|
prop="termValidity"
|
min-width="180"
|
label="有效期">
|
</el-table-column>
|
<el-table-column
|
prop="detectionUnit"
|
min-width="180"
|
label="检测单位">
|
</el-table-column>
|
<el-table-column fixed="right" label="操作" min-width="100">
|
<template v-slot="scope">
|
<el-button type="text" size="small" @click="edit(scope.row)">编辑</el-button>
|
<el-button type="text" size="small" @click="deleteRowFun(scope.row)">删除</el-button>
|
<el-button type="text" size="small" @click="download(scope.row)">下载</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
<el-pagination :current-page="1" :page-size="search.size" :page-sizes="[10, 20, 30, 50, 100]"
|
:total="search.total" layout="->,total, sizes, prev, pager, next, jumper"
|
@size-change="handleSizeChange"
|
@current-change="handleCurrentChange">
|
</el-pagination>
|
<el-dialog
|
title="新 增"
|
:visible.sync="dialogVisible"
|
width="50%">
|
<div style="height: 50vh;">
|
<el-form ref="form" :model="form" label-width="80px">
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="检测日期" prop="detectionDate"
|
:rules="[{ required: true, message: '请输入测试地点', trigger: 'blur' }]">
|
<el-date-picker
|
value-format="yyyy-MM-dd"
|
format="yyyy-MM-dd"
|
style="width: 100%"
|
size="small"
|
v-model="form.detectionDate"
|
type="date"
|
placeholder="选择日期">
|
</el-date-picker>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="有效期" prop="termValidity"
|
:rules="[{ required: true, message: '请输入测试地点', trigger: 'blur' }]">
|
<el-date-picker
|
value-format="yyyy-MM-dd"
|
format="yyyy-MM-dd"
|
style="width: 100%"
|
size="small"
|
v-model="form.termValidity"
|
type="date"
|
placeholder="选择日期">
|
</el-date-picker>
|
</el-form-item>
|
</el-col>
|
<el-col :span="24">
|
<el-form-item label="检测单位" prop="detectionUnit"
|
:rules="[{ required: true, message: '请输入测试地点', trigger: 'blur' }]">
|
<el-input v-model="form.detectionUnit" size="small"></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="检测单位" >
|
<el-upload
|
class="upload-demo"
|
drag
|
action="#"
|
:on-remove="handleRemove"
|
:http-request="httpRequest"
|
:file-list="form.fileList"
|
:on-exceed="handleExceed"
|
:limit="1"
|
multiple>
|
<i class="el-icon-upload"></i>
|
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
|
</el-upload>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
</el-form>
|
</div>
|
<span slot="footer" class="dialog-footer">
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
<el-button type="primary" @click="addImport">确 定</el-button>
|
</span>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script>
|
|
export default {
|
data() {
|
return {
|
search: {
|
size: 20,
|
current: 1,
|
total: 0
|
},
|
tableData: [],
|
dialogVisible: false,
|
form: {
|
fileList: [],
|
fileData: []
|
},
|
}
|
},
|
mounted() {
|
this.initData()
|
},
|
watch: {
|
dialogVisible(newVal) {
|
if (!newVal) {
|
this.form = {
|
fileList: [],
|
fileData: []
|
}
|
}
|
}
|
},
|
methods: {
|
// 导出
|
downLoadPost() {
|
this.$axios.get(this.$api.facilitiesAndEnvironment.exportOfLightningProtectionDetection,{responseType: "blob"}).then(res => {
|
this.outLoading = false
|
const blob = new Blob([res],{ type: 'application/msword' });
|
//将Blob 对象转换成字符串
|
let reader = new FileReader();
|
reader.readAsText(blob, 'utf-8');
|
reader.onload = () => {
|
try {
|
let result = JSON.parse(reader.result);
|
if (result.message) {
|
this.$message.error(result.message);
|
} else {
|
const url = URL.createObjectURL(blob);
|
const link = document.createElement('a');
|
link.href = url;
|
link.download = '防雷检测导出' + '.xlsx';
|
link.click();
|
this.$message.success('导出成功')
|
}
|
} catch (err) {
|
console.log(err);
|
const url = URL.createObjectURL(blob);
|
const link = document.createElement('a');
|
link.href = url;
|
link.download = '防雷检测导出' + '.xlsx';
|
link.click();
|
this.$message.success('导出成功')
|
}
|
}
|
})
|
},
|
initData() {
|
this.$axios.get(this.$api.facilitiesAndEnvironment.getLightningProtectionDetection + '?size=' + this.search.size + '¤t=' + this.search.current).then(res => {
|
if (res.code === 201) return;
|
this.tableData = res.data.records;
|
this.search.total = res.data.total;
|
});
|
},
|
handleSizeChange(val) {
|
this.search.size = val;
|
this.initData();
|
},
|
handleCurrentChange(val) {
|
this.search.current = val;
|
this.initData();
|
},
|
clickAdd() {
|
this.dialogVisible = true
|
},
|
// 文件数量过多时提醒
|
handleExceed() {
|
this.$message({type: 'error', message: '最多支持1个附件上传'})
|
},
|
// 覆盖默认的上传行为,可以自定义上传的实现,将上传的文件依次添加到fileList数组中,支持多个文件
|
httpRequest(option) {
|
this.form.fileData.push(option)
|
},
|
addImport() {
|
console.log(this.form)
|
this.$refs.form.validate((valid) => {
|
if (valid) {
|
let params = new FormData()
|
if (this.form.lightningProtectionId) {
|
params.append("lightningProtectionId", this.form.lightningProtectionId)
|
}
|
params.append("termValidity", this.form.termValidity)
|
params.append("detectionUnit", this.form.detectionUnit)
|
params.append("detectionDate", this.form.detectionDate)
|
if (this.form.fileData.length > 0) {
|
params.append("file", this.form.fileData[0].file)
|
}
|
this.$axios.post(this.$api.facilitiesAndEnvironment.addLightningProtectionDetection, params, {
|
headers: {'Content-Type': 'multipart/form-data;'},
|
noQs: true
|
}).then(res => {
|
if (res.code === 201) return;
|
this.dialogVisible = false
|
this.initData()
|
});
|
}
|
});
|
},
|
edit(row) {
|
this.dialogVisible = true
|
this.form = {...row}
|
this.form.fileList = []
|
this.form.fileData = []
|
this.form.fileList.push({name: row.systemFileName, url: "123434"})
|
console.log(this.form)
|
},
|
deleteRowFun(row) {
|
this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
|
confirmButtonText: '确定',
|
cancelButtonText: '取消',
|
type: 'warning'
|
}).then(() => {
|
this.$axios.delete(this.$api.facilitiesAndEnvironment.deleteLightningProtectionDetection + '?lightningProtectionId=' + row.lightningProtectionId).then(res => {
|
this.$message.success('删除成功!')
|
this.initData()
|
})
|
})
|
},
|
handleRemove(file) {
|
this.$axios.delete(this.$api.personnel.deleteCNASFile + "?fileName=" + file.name).then(res => {
|
if (res.code === 201) return;
|
this.$message.success('删除成功!')
|
let index = this.form.fileList.indexOf(fileName)
|
if (index != -1) {
|
this.successFileList.splice(index, 1)
|
}
|
})
|
},
|
download(row) {
|
let url = '';
|
|
// fileDownload.downloadIamge(url, row.fileName)
|
url = this.javaApi + 'img/' + row.systemFileName
|
const link = document.createElement('a');
|
link.href = url;
|
link.download = row.fileName;
|
link.click();
|
}
|
}
|
}
|
</script>
|
|
<style scoped>
|
.header {
|
height: 3em;
|
width: 100%;
|
display: flex;
|
justify-content: space-between;
|
}
|
</style>
|