| | |
| | | <el-col :span="1.5"> |
| | | <el-button type="primary" icon="el-icon-date" size="mini" @click="handleRowHide">隐藏列设置</el-button> |
| | | </el-col> |
| | | <el-col :span="1.5"> |
| | | <el-button type="primary" icon="el-icon-upload" size="mini" :disabled="single" |
| | | @click="handleFileUpload">附件上传</el-button> |
| | | </el-col> |
| | | <el-col :span="1.5"> |
| | | <el-button type="primary" icon="el-icon-download" size="mini" :disabled="multiple" |
| | | @click="handleBatchFileDownload">附件下载</el-button> |
| | | </el-col> |
| | | </el-row> |
| | | <div class="tableBox" v-loading="loading"> |
| | | <el-table :data="tableData" ref="tableData" max-height="710" :summary-method="getSummaries" |
| | |
| | | <el-button @click="openCarDriver = false">取 消</el-button> |
| | | </div> |
| | | </el-dialog> |
| | | <!-- 附件上传 --> |
| | | <el-dialog title="附件上传" :visible.sync="openFileUpload" width="600px" append-to-body> |
| | | <el-form ref="fileUploadForm" label-width="100px"> |
| | | <el-form-item label="单据号"> |
| | | <el-input v-model="fileUploadForm.billNo" disabled /> |
| | | </el-form-item> |
| | | <el-form-item label="附件"> |
| | | <el-upload class="upload-demo" ref="fileUpload" action="" :on-preview="handleFilePreview" |
| | | :on-remove="handleFileRemove" :on-change="handleFileChange" :file-list="fileList" |
| | | :auto-upload="false" :limit="10" :on-exceed="handleFileExceed" |
| | | accept=".jpg,.png,.jpeg,.pdf,.doc,.docx,.xls,.xlsx,.zip,.rar"> |
| | | <el-button size="small" type="primary">点击上传</el-button> |
| | | <div slot="tip" class="el-upload__tip"> |
| | | 支持上传jpg/png/jpeg/pdf/doc/docx/xls/xlsx/zip/rar格式文件,最多10个</div> |
| | | </el-upload> |
| | | </el-form-item> |
| | | <el-form-item label="已上传附件" v-if="uploadedFileList.length > 0"> |
| | | <el-table :data="uploadedFileList" border size="small" max-height="200"> |
| | | <el-table-column label="文件名" prop="name" align="center" show-overflow-tooltip /> |
| | | <el-table-column label="上传时间" prop="uploadTime" align="center" width="150" /> |
| | | <el-table-column label="操作" align="center" width="100"> |
| | | <template slot-scope="scope"> |
| | | <el-button type="text" size="small" @click="downloadFile(scope.row)">下载</el-button> |
| | | <el-button type="text" size="small" style="color: red;" |
| | | @click="deleteUploadedFile(scope.row, scope.$index)">删除</el-button> |
| | | </template> |
| | | </el-table-column> |
| | | </el-table> |
| | | </el-form-item> |
| | | </el-form> |
| | | <div slot="footer" class="dialog-footer"> |
| | | <el-button type="primary" @click="submitFileUpload" :loading="fileUploadLoading">上传</el-button> |
| | | <el-button @click="openFileUpload = false">关 闭</el-button> |
| | | </div> |
| | | </el-dialog> |
| | | <!-- 附件批量下载 --> |
| | | <el-dialog title="附件批量下载" :visible.sync="openBatchDownload" width="900px" append-to-body> |
| | | <div style="margin-bottom: 10px;"> |
| | | <el-alert :title="`已选择 ${selectedBillCount} 条单据,共 ${batchFileList.length} 个附件`" type="info" show-icon :closable="false" /> |
| | | </div> |
| | | <el-table :data="batchFileList" border v-loading="batchDownloadLoading" max-height="400" |
| | | @selection-change="handleBatchFileSelectionChange"> |
| | | <el-table-column type="selection" width="55" align="center" /> |
| | | <el-table-column label="单据号" prop="billNo" align="center" width="150" show-overflow-tooltip /> |
| | | <el-table-column label="文件名" prop="name" align="center" show-overflow-tooltip /> |
| | | <el-table-column label="文件类型" prop="fileType" align="center" width="100" /> |
| | | <el-table-column label="上传时间" prop="uploadTime" align="center" width="150" /> |
| | | <el-table-column label="操作" align="center" width="80"> |
| | | <template slot-scope="scope"> |
| | | <el-button type="text" size="small" @click="downloadSingleFile(scope.row)">下载</el-button> |
| | | </template> |
| | | </el-table-column> |
| | | </el-table> |
| | | <div slot="footer" class="dialog-footer"> |
| | | <el-button type="primary" @click="batchDownloadFiles" :loading="batchDownloadLoading" :disabled="selectedBatchFiles.length === 0">批量下载选中</el-button> |
| | | <el-button type="primary" @click="downloadAllFiles" :loading="batchDownloadLoading">下载全部</el-button> |
| | | <el-button @click="openBatchDownload = false">关 闭</el-button> |
| | | </div> |
| | | </el-dialog> |
| | | </div> |
| | | </div> |
| | | </template> |
| | |
| | | DriverHName: [{ required: true, message: '请输入驾驶员', trigger: 'blur' }], |
| | | DriverHIDCard: [{ required: true, message: '请输入身份证号', trigger: 'blur' }], |
| | | }, |
| | | openFileUpload: false, //附件上传弹窗标记 |
| | | fileUploadForm: { //附件上传表单 |
| | | billNo: '', |
| | | hInterID: 0 |
| | | }, |
| | | fileList: [], //待上传文件列表 |
| | | uploadFiles: [], //待上传文件数据 |
| | | fileUploadLoading: false, //上传加载状态 |
| | | uploadedFileList: [], //已上传文件列表 |
| | | openBatchDownload: false, //批量下载弹窗标记 |
| | | batchFileList: [], //批量下载文件列表 |
| | | selectedBatchFiles: [], //选中的批量下载文件 |
| | | batchDownloadLoading: false, //批量下载加载状态 |
| | | selectedBillCount: 0, //选中的单据数量 |
| | | dialogTypeNum: null, //部门弹窗1,仓库弹窗2 |
| | | gyCarShow: false, //车辆数据组件显示标记 |
| | | gyDriverShow: false, //司机数据组件显示标记 |
| | |
| | | }, |
| | | |
| | | methods: { |
| | | |
| | | //#region 设置表头 |
| | | renderHeader(h, { column, $index }) {// 新建一个 span |
| | | let span = document.createElement(span)// 设置表头名称 |
| | |
| | | }) |
| | | }, |
| | | //#endregion |
| | | //#region 附件上传 |
| | | handleFileUpload() { |
| | | this.fileUploadForm = { |
| | | billNo: this.rowForm.单据号, |
| | | hInterID: this.rowForm.HInterID |
| | | } |
| | | this.fileList = [] |
| | | this.uploadFiles = [] |
| | | this.uploadedFileList = [] |
| | | this.getUploadedFileList() |
| | | this.openFileUpload = true |
| | | }, |
| | | handleFileChange(file, fileList) { |
| | | this.uploadFiles = fileList |
| | | }, |
| | | handleFileRemove(file, fileList) { |
| | | this.uploadFiles = fileList |
| | | }, |
| | | handleFilePreview(file) { |
| | | if (file.url) { |
| | | window.open(file.url, '_blank') |
| | | } else if (file.raw) { |
| | | const url = URL.createObjectURL(file.raw) |
| | | window.open(url, '_blank') |
| | | } else { |
| | | this.$modal.msgWarning('无法预览该文件') |
| | | } |
| | | }, |
| | | handleFileExceed(files, fileList) { |
| | | this.$modal.msgWarning(`当前限制选择 10 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`) |
| | | }, |
| | | submitFileUpload() { |
| | | if (this.uploadFiles.length === 0) { |
| | | this.$modal.msgWarning('请先选择要上传的文件') |
| | | return |
| | | } |
| | | this.fileUploadLoading = true |
| | | const formData = new FormData() |
| | | this.uploadFiles.forEach(file => { |
| | | formData.append('files', file.raw) |
| | | }) |
| | | formData.append('HBillNo', this.fileUploadForm.billNo) |
| | | formData.append('HInterID', this.fileUploadForm.hInterID) |
| | | formData.append('HUserName', sessionStorage["HUserName"] || '') |
| | | axios.post(this.$baseUrl + '/WLYayBillController/UploadFile', formData, { |
| | | headers: { |
| | | 'Content-Type': 'multipart/form-data' |
| | | } |
| | | }).then(response => { |
| | | this.fileUploadLoading = false |
| | | if (response.data.code == 1) { |
| | | this.$modal.msgSuccess(response.data.Message || '文件上传成功') |
| | | this.fileList = [] |
| | | this.uploadFiles = [] |
| | | this.getUploadedFileList() |
| | | } else { |
| | | this.$modal.msgError(response.data.code + response.data.Message || '上传失败') |
| | | } |
| | | }).catch(error => { |
| | | this.fileUploadLoading = false |
| | | this.$modal.msgError('上传请求失败') |
| | | console.error('上传错误:', error) |
| | | }) |
| | | }, |
| | | getUploadedFileList() { |
| | | axios.get(this.$baseUrl + '/WLYayBillController/GetFileList', { |
| | | params: { |
| | | HInterID: this.fileUploadForm.hInterID |
| | | } |
| | | }).then(response => { |
| | | if (response.data.code == 1) { |
| | | this.uploadedFileList = response.data.data || [] |
| | | } |
| | | }).catch(error => { |
| | | console.error('获取文件列表失败:', error) |
| | | }) |
| | | }, |
| | | downloadFile(row) { |
| | | if (row.url) { |
| | | window.open(row.url, '_blank') |
| | | } else { |
| | | axios.get(this.$baseUrl + '/WLYayBillController/DownloadFile', { |
| | | params: { |
| | | fileId: row.id || row.fileId |
| | | }, |
| | | responseType: 'blob' |
| | | }).then(response => { |
| | | const blob = new Blob([response.data]) |
| | | const url = window.URL.createObjectURL(blob) |
| | | const link = document.createElement('a') |
| | | link.href = url |
| | | link.download = row.name || row.fileName |
| | | link.click() |
| | | window.URL.revokeObjectURL(url) |
| | | }).catch(error => { |
| | | this.$modal.msgError('下载失败') |
| | | console.error('下载错误:', error) |
| | | }) |
| | | } |
| | | }, |
| | | deleteUploadedFile(row, index) { |
| | | this.$modal.confirm('确认要删除该文件吗?').then(() => { |
| | | axios.get(this.$baseUrl + '/WLYayBillController/DeleteFile', { |
| | | params: { |
| | | fileId: row.id || row.fileId, |
| | | HInterID: this.fileUploadForm.hInterID, |
| | | HUserName: sessionStorage["HUserName"] |
| | | } |
| | | }).then(response => { |
| | | if (response.data.code == 1) { |
| | | this.$modal.msgSuccess('删除成功') |
| | | this.uploadedFileList.splice(index, 1) |
| | | } else { |
| | | this.$modal.msgError(response.data.Message || '删除失败') |
| | | } |
| | | }).catch(error => { |
| | | this.$modal.msgError('删除请求失败') |
| | | console.error('删除错误:', error) |
| | | }) |
| | | }).catch(() => { }) |
| | | }, |
| | | //#endregion |
| | | //#region 附件批量下载 |
| | | handleBatchFileDownload() { |
| | | if (this.rowList.length === 0) { |
| | | this.$modal.msgWarning('请先选择要下载附件的单据') |
| | | return |
| | | } |
| | | this.selectedBillCount = this.rowList.length |
| | | this.batchFileList = [] |
| | | this.selectedBatchFiles = [] |
| | | this.getBatchFileList() |
| | | this.openBatchDownload = true |
| | | }, |
| | | getBatchFileList() { |
| | | this.batchDownloadLoading = true |
| | | const interIds = this.rowList.map(item => item.HInterID).join(',') |
| | | axios.get(this.$baseUrl + '/WLYayBillController/GetBatchFileList', { |
| | | params: { |
| | | HInterIDs: interIds |
| | | } |
| | | }).then(response => { |
| | | this.batchDownloadLoading = false |
| | | if (response.data.code == 1) { |
| | | this.batchFileList = response.data.data || [] |
| | | } else { |
| | | this.$modal.msgError(response.data.Message || '获取文件列表失败') |
| | | } |
| | | }).catch(error => { |
| | | this.batchDownloadLoading = false |
| | | this.$modal.msgError('获取文件列表失败') |
| | | console.error('获取文件列表错误:', error) |
| | | }) |
| | | }, |
| | | handleBatchFileSelectionChange(selection) { |
| | | this.selectedBatchFiles = selection |
| | | }, |
| | | downloadSingleFile(row) { |
| | | if (row.url) { |
| | | window.open(row.url, '_blank') |
| | | } else { |
| | | axios.get(this.$baseUrl + '/WLYayBillController/DownloadFile', { |
| | | params: { |
| | | fileId: row.id || row.fileId |
| | | }, |
| | | responseType: 'blob' |
| | | }).then(response => { |
| | | const blob = new Blob([response.data]) |
| | | const url = window.URL.createObjectURL(blob) |
| | | const link = document.createElement('a') |
| | | link.href = url |
| | | link.download = row.name || row.fileName |
| | | link.click() |
| | | window.URL.revokeObjectURL(url) |
| | | }).catch(error => { |
| | | this.$modal.msgError('下载失败') |
| | | console.error('下载错误:', error) |
| | | }) |
| | | } |
| | | }, |
| | | batchDownloadFiles() { |
| | | if (this.selectedBatchFiles.length === 0) { |
| | | this.$modal.msgWarning('请先选择要下载的文件') |
| | | return |
| | | } |
| | | this.downloadFiles(this.selectedBatchFiles) |
| | | }, |
| | | downloadAllFiles() { |
| | | if (this.batchFileList.length === 0) { |
| | | this.$modal.msgWarning('没有可下载的文件') |
| | | return |
| | | } |
| | | this.downloadFiles(this.batchFileList) |
| | | }, |
| | | downloadFiles(fileList) { |
| | | this.batchDownloadLoading = true |
| | | const fileIds = fileList.map(item => item.id || item.fileId).join(',') |
| | | axios.get(this.$baseUrl + '/WLYayBillController/BatchDownloadFiles', { |
| | | params: { |
| | | fileIds: fileIds |
| | | }, |
| | | responseType: 'blob' |
| | | }).then(response => { |
| | | this.batchDownloadLoading = false |
| | | const blob = new Blob([response.data], { type: 'application/zip' }) |
| | | const url = window.URL.createObjectURL(blob) |
| | | const link = document.createElement('a') |
| | | link.href = url |
| | | const now = new Date() |
| | | const timestamp = `${now.getFullYear()}${(now.getMonth() + 1).toString().padStart(2, '0')}${now.getDate().toString().padStart(2, '0')}_${now.getHours().toString().padStart(2, '0')}${now.getMinutes().toString().padStart(2, '0')}${now.getSeconds().toString().padStart(2, '0')}` |
| | | link.download = `附件下载_${timestamp}.zip` |
| | | link.click() |
| | | window.URL.revokeObjectURL(url) |
| | | this.$modal.msgSuccess('下载成功') |
| | | }).catch(error => { |
| | | this.batchDownloadLoading = false |
| | | this.$modal.msgError('批量下载失败') |
| | | console.error('批量下载错误:', error) |
| | | }) |
| | | }, |
| | | //#endregion |
| | | //清除选中数据的缓存 |
| | | clearData() { |
| | | this.ids = [] |
| | |
| | | this.OperationType = 0 |
| | | this.copyType = 0 |
| | | }, |
| | | |
| | | } |
| | | }; |
| | | </script> |