Commit adb411c8 by lichengming

修改了收样管理附件

parent fdadeaf0
<template>
<div>
<Modal v-model="showEditModal" :mask-closable="false" width="600">
<p slot="header">{{modalTitle}}</p>
<div>
<Upload
:action="action"
:show-upload-list="false"
:before-upload="_beupload"
multiple
>
<Button type="dashed" icon="ios-cloud-upload-outline">上传文件(小于50MB)</Button>
</Upload>
<div>
<Card :dis-hover="true" style="width: 100%;height: 400px;overflow: auto;">
<p slot="title">已上传文件列表</p>
<div v-for="(item,index) in fileList" :key="index" class="file-upload-list">
<div>
<div class="file-upload-list-cover">
<Icon @click.native.stop="_handleRemove(item)" type="md-trash" style="color: white;font-size: 20px;"></Icon>
</div>
</div>
{{item.fileName }}
</div>
</Card>
</div>
</div>
<div slot="footer" class="btn-width">
<Button @click="showEditModal = false">取消</Button>
<Button @click="_mutipleUpload" :loading="isLoading" type="primary">{{btnName}}</Button>
</div>
</Modal>
</div>
</template>
<script>
/**
* 上传文件,在文件夹下
*/
import axios from 'axios'
import global from '../../../api/config'
import loading from '../../../api/loading'
export default {
data() {
return {
id: '',
ID: '',
action: '',
modalTitle: '',
showEditModal: false,
name: '',
isLoading: false,
btnName: '上传',
fileList: []
}
},
methods: {
_open(obj) {
this.fileList = []
this.showEditModal = true
this.ID = obj
this.modalTitle = '文件上传'
},
_beupload(file) {
// 单个文件上传超过50M时,取消上传
const isLt50M = file.size / 1024 / 1024 < 50
const fileName = file.name.split('.')[0]
if (!isLt50M) {
this.$Message.warning({
content: '文件 ' + fileName + ' 大小超多50M,请重新上传!',
duration: 3
})
this.isLoading = false
} else {
// 动态循环给文件命名
const temObj = {
file: file,
fileName: fileName
}
this.fileList.push(temObj)
}
return false
},
_mutipleUpload() {
if (this.fileList.length > 0 && this.btnName === '上传') {
this.isLoading = true
this.btnName = '上传中...'
// 创建formula对象
const formData = new FormData()
formData.append('entrustId', this.ID)
// 多个文件
for (let i = 0; i < this.fileList.length; i++) {
formData.append('file' + i, this.fileList[i].file)
}
const config = {
headers: {
'Content-Type': 'multipart/form-data'
}
}
const instanceFile = axios.create()
instanceFile.defaults.withCredentials = true
// 发起请求
instanceFile
.post(
global.baseURL +
'/soil/v1/alone_sample_annex/upload_bath/' +
this.ID,
formData,
{
headers: config
}
)
.then(res => {
if (res.data.code === '1') {
this.$Message.success('上传成功!')
this.showEditModal = false
this.$emit('on-result-change')
} else if (res.data.code === '0') {
loading.toast.show(res.data.code, res.data.msg)
this.$Message.error('操作失败')
}
this._resetLoading()
})
.catch(err => {
console.log(err)
this._resetLoading()
})
} else {
this.$Message.warning('请至少上传一个文件')
this._resetLoading()
}
},
_resetLoading() {
this.isLoading = false
this.btnName = '上传'
},
// 删除对应的上传的文件
_handleRemove(data) {
const index = this.fileList.findIndex(item => item === data)
this.fileList.splice(index, 1)
}
}
}
</script>
<style>
.file-upload-list {
display: inline-block;
width: 100px;
height: 100px;
text-align: center;
line-height: 100px;
border: 1px solid transparent;
border-radius: 4px;
overflow: hidden;
background: #fff;
position: relative;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
margin-right: 4px;
}
.file-upload-list:hover .file-upload-list-cover {
display: block;
}
.file-upload-list-cover {
display: none;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.6);
}
</style>
...@@ -113,13 +113,13 @@ export default { ...@@ -113,13 +113,13 @@ export default {
break break
case 'sampleId': case 'sampleId':
// 样品 // 样品
this.sampleId = id this.entrustId = id
this.urlData = { this.urlData = {
msg: 'FoodSampleAttachment', msg: 'FoodSampleAttachment',
pageUrl: 'soil/v1/alone_sample_annex/page', pageUrl: 'soil/v1/alone_sample_annex/page',
deleteUrl: 'soil/v1/alone_sample_annex/?ids=', deleteUrl: '/soil/v1/alone_sample_annex/?ids=',
uploadFileUrl: '/food/v1/sample_attachment/upload/', uploadFileUrl: '/soil/v1/alone_sample_annex/upload/',
downloadFileUrl: '/food/v1/sample_attachment/download/', downloadFileUrl: '/soil/v1/alone_sample_annex/download/',
downloadBatch: '/food/v1/sample_attachment/download_batch', downloadBatch: '/food/v1/sample_attachment/download_batch',
uri: 'FoodSampleAttachment/getBySampleId', uri: 'FoodSampleAttachment/getBySampleId',
viewUri: '/food/v1/sample_attachment/view' viewUri: '/food/v1/sample_attachment/view'
......
...@@ -117,6 +117,7 @@ ...@@ -117,6 +117,7 @@
</Col> </Col>
</Row> </Row>
<BatchUpload ref="batchUpload" @on-result-change="_page"></BatchUpload> <BatchUpload ref="batchUpload" @on-result-change="_page"></BatchUpload>
<BatchUploadSample ref="batchUploadSample" @on-result-change="_page"></BatchUploadSample>
<!--上传loading--> <!--上传loading-->
<div v-show="isLoad"> <div v-show="isLoad">
<Spin fix> <Spin fix>
...@@ -137,11 +138,12 @@ ...@@ -137,11 +138,12 @@
import global from '../../../api/config' import global from '../../../api/config'
import { meterEntrust } from '../../../api' import { meterEntrust } from '../../../api'
import BatchUpload from './BatchUpload' import BatchUpload from './BatchUpload'
import BatchUploadSample from './BatchUploadSample'
/** /**
* 公共组件modal 弹框(支持上传,下载,预览,删除附件等操作) * 公共组件modal 弹框(支持上传,下载,预览,删除附件等操作)
*/ */
export default { export default {
components: { BatchUpload }, components: { BatchUpload, BatchUploadSample },
props: { props: {
fileName: null fileName: null
}, },
...@@ -206,7 +208,11 @@ export default { ...@@ -206,7 +208,11 @@ export default {
}, },
methods: { methods: {
_batchUpload() { _batchUpload() {
if (this.formObj.sampleId) {
this.$refs.batchUploadSample._open(this.id)
} else {
this.$refs.batchUpload._open(this.id) this.$refs.batchUpload._open(this.id)
}
}, },
_setUploadData(data, idsObj, idKey) { _setUploadData(data, idsObj, idKey) {
this.selectIds = [] this.selectIds = []
......
...@@ -76,6 +76,11 @@ export default { ...@@ -76,6 +76,11 @@ export default {
name: '查看' name: '查看'
}, },
{ {
type: 'ios-cloud',
id: '',
name: '附件'
},
{
type: 'ios-clock', type: 'ios-clock',
id: '', id: '',
name: '操作日志' name: '操作日志'
...@@ -242,7 +247,10 @@ export default { ...@@ -242,7 +247,10 @@ export default {
_upload(id) { _upload(id) {
// 上传文件 // 上传文件
this.$refs.refModal._open(id, 'subcontractorId') this.currentComponent = 'FileManage'
this.$nextTick(() => {
this.$refs.refModal._open(id, 'sampleId')
})
}, },
_getById: async function(id) { _getById: async function(id) {
const result = await soilAptitude.getById(id) const result = await soilAptitude.getById(id)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment