<template>
|
<div>
|
<el-dialog title="附件查看" :visible.sync="isShow" width="80%" @closed="$emit('closeFilesLook')">
|
<div style="display: flex;justify-content: space-between;">
|
<ul class="tab">
|
<li v-for="(m,i) in dataVisibleTitle" :key="i" :class="{active:i===dataVisibleIndex}" @click="handleDataVisibleTab(m,i)">{{m.label}}</li>
|
</ul>
|
<el-upload :action="action"
|
:auto-upload="true"
|
:data="{orderId: dataVisibleIndex === 0 ? filesLookInfo.enterOrderId : filesLookInfo.quarterOrderId}"
|
:on-success="handleSuccessUp" :show-file-list="false"
|
accept='.jpg,.jpeg,.png,.gif,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.pdf,.zip,.rar' :headers="headers"
|
:before-upload="beforeUpload"
|
style="width: 80px !important;"
|
:on-error="onError" ref='upload'>
|
<el-button size="small" type="primary" style="height: 38px">附件上传</el-button>
|
</el-upload>
|
</div>
|
<div style="height: 70vh;overflow-y: auto;" v-if="filesDialogVisible">
|
<ValueTable ref="fileList"
|
:url="$api.insOrderPlan.getFileList"
|
:delUrl="$api.insOrderPlan.delfile"
|
class="value-table"
|
:key="upIndex"
|
:componentData="componentData"/>
|
</div>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script>
|
import ValueTable from "@/components/Table/value-table.vue";
|
import file from "@/utils/file";
|
|
export default {
|
name: "filesLookVisible",
|
// import 引入的组件需要注入到对象中才能使用
|
components: {ValueTable},
|
props: {
|
filesDialogVisible: {
|
type: Boolean,
|
default: () => false
|
},
|
filesLookInfo: {
|
type: Object,
|
default: () => {}
|
},
|
},
|
data() {
|
// 这里存放数据
|
return {
|
upIndex: 0,
|
isShow: this.filesDialogVisible,
|
dataVisibleTitle: [
|
{
|
label: '进厂检验',
|
value: 0
|
},
|
{
|
label: '季度检验',
|
value: 1
|
},
|
],
|
dataVisibleIndex: 0, // tab栏选择值
|
componentData: {
|
entity: {
|
insOrderId:''
|
},
|
isIndex: true,
|
showSelect: false,
|
select: false,
|
sort: false,
|
init:false,
|
do: [
|
{
|
id: 'parent',
|
font: '下载',
|
type: 'text',
|
method: 'handleDown'
|
},{
|
id: 'delete',
|
font: '删除',
|
type: 'text',
|
method: 'doDiy',
|
}
|
],
|
isPage: false,
|
linkEvent: {},
|
tagField: {
|
type:{
|
select:[
|
{
|
value: 1,
|
label: '图片'
|
},
|
{
|
value: 2,
|
label: '文件'
|
}
|
]
|
}
|
},
|
currentId: '',
|
selectField: {},
|
requiredAdd: [],
|
requiredUp: []
|
},
|
|
}
|
},
|
mounted() {
|
this.refreshTable()
|
},
|
// 方法集合
|
methods: {
|
// 切换数据查看tab栏
|
handleDataVisibleTab (m, i) {
|
this.dataVisibleIndex = i
|
this.refreshTable()
|
},
|
// 查询回调
|
refreshTable(e) {
|
if (this.dataVisibleIndex === 0) {
|
this.componentData.entity.insOrderId = this.filesLookInfo.enterOrderId
|
} else {
|
this.componentData.entity.insOrderId = this.filesLookInfo.quarterOrderId
|
}
|
this.$nextTick(() => {
|
this.$refs['fileList'].selectList(e)
|
})
|
},
|
handleDown(row){
|
this.$axios.post(this.$api.insOrderPlan.downFile, {
|
id: row.id,
|
}).then(res => {
|
if (res.code === 200) {
|
let url = '';
|
if(res.data.type==1){
|
url = this.javaApi+'/img/'+res.data.fileUrl
|
file.downloadIamge(url,row.fileName)
|
}else{
|
url = this.javaApi+'/word/'+res.data.fileUrl
|
const link = document.createElement('a');
|
link.href = url;
|
link.download = row.fileName;
|
link.click();
|
}
|
}
|
}).catch(error => {
|
|
})
|
},
|
handleSuccessUp(response, ) {
|
this.upLoading = false;
|
if (response.code == 200) {
|
this.$message.success('上传成功');
|
this.$refs.fileList.selectList()
|
}
|
},
|
beforeUpload(file) {
|
let flag = true
|
if (this.dataVisibleIndex === 0 && !this.filesLookInfo.enterOrderId) {
|
this.$message.warning('没有相应的检验任务')
|
return
|
} else if (this.dataVisibleIndex === 1 && !this.filesLookInfo.quarterOrderId) {
|
this.$message.warning('没有相应的检验任务')
|
return
|
}
|
if (file.size > 1024 * 1024 * 10) {
|
this.$message.error('上传文件不超过10M');
|
this.$refs.upload.clearFiles()
|
flag = false
|
}
|
if (!flag) {
|
return Promise.reject(flag); //正确的终止
|
}
|
},
|
onError(err, file, fileList) {
|
this.$message.error('上传失败')
|
this.$refs.upload.clearFiles()
|
},
|
},
|
computed: {
|
headers() {
|
return {
|
'token': sessionStorage.getItem('token')
|
}
|
},
|
action() {
|
return this.javaApi + this.$api.insOrderPlan.uploadFile
|
}
|
},
|
}
|
</script>
|
|
<style scoped>
|
.tab {
|
list-style-type: none;
|
display: flex;
|
margin-bottom: 12px;
|
}
|
|
.tab li {
|
line-height: 24px;
|
padding: 6px 14px;
|
font-size: 14px;
|
color: #333333;
|
border: 1px solid #EEEEEE;
|
cursor: pointer;
|
}
|
|
.tab li:nth-child(1) {
|
border-radius: 8px 0 0 8px;
|
}
|
|
.tab li:nth-child(2) {
|
border-radius: 0 8px 8px 0;
|
}
|
|
.tab li.active {
|
border-color: #3A7BFA;
|
color: #3A7BFA;
|
}
|
</style>
|