<template>
|
<div>
|
<template v-if="indexInfo">
|
<el-upload
|
class="upload-demo"
|
drag
|
action="/mes/qualityLabelPrintConfig/uploadFile"
|
:headers="headers"
|
accept="image/jpg,image/png,image/jpeg,image/gif"
|
:limit="1"
|
:auto-upload="true"
|
:on-exceed="exceedFile"
|
:file-list="fileList"
|
:on-success="uploadSuccess"
|
:with-credentials="true"
|
:on-remove="handleRemove"
|
:on-preview="handlePreview"
|
:before-upload="submitUpload"
|
:data="paramData"
|
list-type="picture"
|
>
|
<i class="el-icon-upload"></i>
|
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
|
</el-upload>
|
</template>
|
<template v-else>
|
<div style="padding:30px 0;font-size:14px">
|
请先选择检测类别
|
</div>
|
</template>
|
</div>
|
</template>
|
|
<script>
|
import { getObj, putObj } from '@/api/print/config'
|
import { mapGetters } from 'vuex'
|
import { getStore } from '@/util/store.js'
|
|
export default {
|
props: {
|
indexInfo: {
|
type: Object,
|
default: null
|
}
|
},
|
data() {
|
return {
|
headers: {
|
Authorization: 'Bearer ' + getStore({ name: 'access_token' })
|
},
|
paramData: {},
|
fileList: []
|
}
|
},
|
components: {},
|
computed: {
|
...mapGetters(['permissions'])
|
},
|
created() {},
|
watch: {
|
indexInfo: {
|
deep: true,
|
handler(newVal) {
|
this.fileList = []
|
if (newVal && newVal.fileName) {
|
const fileEl = {}
|
fileEl.name = newVal.fileName
|
fileEl.url = '/mes/document/file/' + newVal.fileName
|
fileEl.id = 1
|
fileEl.fileName = newVal.fileName
|
this.fileList.push(fileEl)
|
}
|
}
|
}
|
},
|
methods: {
|
// 附件上传下载
|
submitUpload() {
|
this.paramData.printConfigId = this.indexInfo.id
|
},
|
getFileList() {
|
this.fileList = []
|
getObj(this.indexInfo.id).then((response) => {
|
const v = response.data.data
|
if (v && v.fileName) {
|
const fileEl = {}
|
fileEl.name = v.fileName
|
fileEl.url = '/mes/document/file/' + v.fileName
|
fileEl.id = 1
|
fileEl.fileName = v.fileName
|
this.fileList.push(fileEl)
|
}
|
})
|
},
|
// 上传成功给newFileList
|
uploadSuccess(response, file, fileList) {
|
this.getFileList()
|
},
|
|
exceedFile(files, fileList) {
|
this.$notify.warning({
|
title: '警告',
|
message: '只能选择1个文件'
|
})
|
},
|
handlePreview(file) {
|
window.open(file.url)
|
},
|
handleRemove(file, fileList) {
|
putObj(
|
Object.assign(this.indexInfo, {
|
fileName: ''
|
})
|
).then((data) => {
|
if (data.data.code !== 0) {
|
this.fileList = []
|
}
|
})
|
}
|
}
|
}
|
</script>
|