irc_web/.svn/pristine/86/862a9be66f2a9cb7dc4e602ec8b...

137 lines
3.9 KiB
Plaintext

<template>
<div class="upload-container">
<el-upload
class="upload-demo"
action
:http-request="uploadFile"
:before-upload="beforeUpload"
:file-list="fileList"
:before-remove="beforeRemove"
:on-remove="handleRemoveFile"
:on-preview="handlePreview"
:limit="1"
:on-exceed="handleExceed"
accept=".pdf"
>
<el-button size="small" type="primary" :loading="btnDisabled">{{ $t('trials:enrolledReviews:button:upload') }}</el-button>
<span slot="tip" class="el-upload__tip">{{ `(${$t('trials:enrolledReviews:label:mustBepdf')})` }}</span>
</el-upload>
</div>
</template>
<script>
import { uploadFile } from '@/api/attachment'
import { uploadReviewerAckSOW, deleteReviewerAckSOW } from '@/api/trials'
const type = 'ACK of SOW'
export default {
name: 'UploadFile',
props: {
doctorId: {
type: String,
required: true
},
trialId: {
type: String,
required: true
}
},
data() {
return {
fileList: [],
btnDisabled: false
}
},
methods: {
initFileList(fileList) {
this.fileList = fileList
},
uploadFile(param) {
var fileName = param.file.name
this.btnDisabled = true
uploadFile(param.file, type, this.doctorId)
.then(res => {
if (res.IsSuccess) {
this.fileList.push({ DoctorId: this.doctorId, name: fileName, FileName: fileName, Path: res.Result.FilePath, FullPath: res.Result.FullFilePath, Type: type })
this.saveFile()
}
})
.catch(() => {
this.btnDisabled = false
})
},
saveFile() {
const { name, Path, FullPath, Type } = this.fileList[0]
const param = { DoctorId: this.doctorId, Type: Type, Path: Path, FullPath: FullPath, FileName: name }
uploadReviewerAckSOW(this.trialId, param).then(res => {
this.btnDisabled = false
if (res.IsSuccess) {
this.fileList[0].Id = res.Result
// this.$message.success('Uploaded successfully')
this.$message.success(this.$t('common:message:savedSuccessfully'))
this.$emit('getFileList', this.fileList)
}
})
.catch(() => {
this.btnDisabled = false
})
},
beforeUpload(file, fileList) {
const isValidFile = this.fileValid(file.name, 'pdf')
if (isValidFile) {
this.fileList = []
} else {
this.$alert(this.$t('trials:enrolledReviews:label:mustBepdf'))
return false
}
},
beforeRemove(file, fileList) {
if (file && file.status === 'success') {
return this.$confirm(this.$t('trials:enrolledReviews:message:deleteSOWWarning'))
}
},
handleRemoveFile(file, fileList) {
if (file && file.status === 'success') {
if (file.Id) {
deleteReviewerAckSOW(this.trialId, this.doctorId, file.Id).then(res => {
if (res.IsSuccess) {
this.fileList = []
this.$message.success(this.$t('common:message:savedSuccessfully'))
this.$emit('getFileList', this.fileList)
}
})
} else {
this.fileList = []
this.$emit('getFileList', this.fileList)
}
}
},
handlePreview(file) {
file.FullPath ? window.open(file.FullPath, '_blank') : ''
},
handleExceed(files, fileList) {
this.$message.warning(this.$t('trials:enrolledReviews:message:uploadSowWaring1'))
},
fileValid(fileName, typeArr) {
var extendName = fileName.substring(fileName.lastIndexOf('.') + 1).toLocaleLowerCase()
if (typeArr.toLocaleLowerCase().indexOf(extendName) > -1) {
return true
} else {
return false
}
}
}
}
</script>
<style>
.upload-container .el-upload--text {
border: none;
width: 80px;
height: 30px;
}
.upload-container .el-form-item__label {
font-size: 12px;
}
.upload-container .el-upload-list__item {
font-size: 12px;
}
</style>