Prechádzať zdrojové kódy

发票添加批量导出功能

徐滕 1 týždeň pred
rodič
commit
66cb4bbaa0

+ 22 - 0
src/api/cw/invoice/CwFinanceInvoiceService.js

@@ -196,6 +196,28 @@ export default {
 		});
 	},
 
+	/**
+	 * 查询当前用户已下载的发票ID列表
+	 */
+	getDownloadedInvoiceIds() {
+		return request({
+			url: prefix + "/cw_finance/invoice/downloadedInvoiceIds",
+			method: "get",
+		});
+	},
+
+	/**
+	 * 批量下载数电票
+	 */
+	batchDownloadInvoice(data) {
+		return request({
+			url: prefix + "/cw_finance/invoice/batchDownloadInvoice",
+			method: "post",
+			data: data,
+			responseType: "blob",
+		});
+	},
+
 	invoiceOMSView(invoiceId) {
 		return request({
 			url: prefix + "/cw_finance/invoice/invoiceOMSView",

+ 10 - 0
src/api/finance/invoice/FinanceInvoiceService.js

@@ -166,4 +166,14 @@ export default class FinanceInvoiceService {
 			responseType: "blob",
 		});
 	}
+
+	// 批量下载数电票
+	batchDownloadInvoice(data) {
+		return request({
+			url: prefix + "/finance/invoice/batchDownloadInvoice",
+			method: "post",
+			data: data,
+			responseType: "blob",
+		});
+	}
 }

+ 73 - 3
src/views/cw/invoice/InvoiceList.vue

@@ -140,6 +140,13 @@
 					</el-select>
 				</el-form-item>
 
+				<el-form-item v-if="showHideItem" label="下载状态" prop="downloadStatusFilter">
+					<el-select v-model="searchForm.downloadStatusFilter" placeholder="请选择下载状态" clearable style="width: 100%;">
+						<el-option label="未下载" value="0"></el-option>
+						<el-option label="已下载" value="1"></el-option>
+					</el-select>
+				</el-form-item>
+
 				<el-form-item>
 					<el-button type="default" @click="showHide" :icon="showHideIcon">{{ showHideName }}</el-button>
 					<el-button type="primary" @click="refreshList()" icon="el-icon-search">查询</el-button>
@@ -163,6 +170,9 @@
 					<el-button v-if="hasPermission('cw_finance:invoice:importInvoiceBatch')" type="primary"
 						@click="projectImport()" plain>批量收款导入</el-button>
 
+					<el-button type="danger" @click="batchDownloadInvoice()" plain
+						:disabled="$refs.invoiceTable && $refs.invoiceTable.getCheckboxRecords().length === 0">批量下载数电票</el-button>
+
 					<el-switch v-if="hasPermission('cw_finance:invoice:dd_notice')" v-model="dingNoticeEnabled"
 						inline-prompt
 						style="margin-left: 10px;--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
@@ -249,9 +259,19 @@
 									$dictUtils.getDictLabel("invoice_status", scope.row.status, '') }} </el-button>
 						</template>
 					</vxe-column>
+					<vxe-column min-width="80" title="下载状态" fixed="right" align="center">
+						<template #default="scope">
+							<span v-if="scope.row.omsAttachmentUrl">
+								<span v-if="scope.row.downloadStatus === '1'" style="color:green;font-weight:bold;">已下载</span>
+								<span v-else style="color:#999;">未下载</span>
+							</span>
+						</template>
+					</vxe-column>
 					<vxe-column min-width="200" title="操作" fixed="right" align="center">
 						<template #default="scope">
 							<div v-if="isAdmin">
+								<el-button v-if="scope.row.omsAttachmentUrl" text type="primary"
+									@click="handleDownloadAllInvoice(scope.row)">{{ scope.row.downloadStatus === '1' ? '再次下载' : '下载所有格式发票' }}</el-button>
 								<el-button v-if="(scope.row.status === '5')" text type="primary"
 									@click="editForm(scope.row.id)">修改</el-button>
 								<el-button v-if="(scope.row.status === '5')" text type="primary"
@@ -261,7 +281,7 @@
 							<div v-else>
 
 								<el-button v-if="scope.row.omsAttachmentUrl" text type="primary"
-									@click="handleDownloadAllInvoice(scope.row)">下载所有格式发票</el-button>
+									@click="handleDownloadAllInvoice(scope.row)">{{ scope.row.downloadStatus === '1' ? '再次下载' : '下载所有格式发票' }}</el-button>
 								<el-button
 									v-if="hasPermission('cw_finance:invoice:add') && scope.row.status === '5' && scope.row.account > 0"
 									text type="primary" @click="handleRedInvoice(scope.row)">红冲</el-button>
@@ -401,7 +421,8 @@ export default {
 				loginName: this.$store.state.user.name,
 				reportType: '',
 				status: '',
-				name: ''
+				name: '',
+				downloadStatusFilter: ''
 			},
 			dataList: [],
 			tablePage: {
@@ -665,6 +686,7 @@ export default {
 				operator: '',
 				operatorOffice: '',
 				reportType: '',
+				downloadStatusFilter: '',
 			}
 			this.$refs.searchForm.resetFields()
 			this.refreshList()
@@ -1221,11 +1243,14 @@ export default {
 				omsAttachmentUrl = omsAttachmentUrl.substring(0, omsAttachmentUrl.lastIndexOf('/') + 1)
 				financeInvoiceService.downLoadOMSInvoiceAttachzip({
 					fileUrl: omsAttachmentUrl,
-					invoiceNo: row.no
+					invoiceNo: row.no,
+					invoiceId: row.id
 				}).then((res) => {
 					// 将二进制流文件写入excel表,以下为重要步骤
 					this.$utils.downloadZip(res, '发票-' + row.no + '.zip')
 					this.loading = false
+					// 刷新列表以更新下载状态
+					this.refreshList()
 				}).catch(function (err) {
 					this.loading = false
 					if (err.response) {
@@ -1234,6 +1259,51 @@ export default {
 				})
 			})
 		},
+		// 批量下载数电票
+		batchDownloadInvoice() {
+			let selectedRows = this.$refs.invoiceTable.getCheckboxRecords()
+			// 过滤出有OMS附件的行
+			selectedRows = selectedRows.filter(row => row.omsAttachmentUrl)
+			if (selectedRows.length === 0) {
+				this.$message.error('所选数据中不存在可下载的数电票发票,请重新选择')
+				return
+			}
+			if (selectedRows.length > 25) {
+				this.$message.error('单次批量下载不能超过25条,请重新选择')
+				return
+			}
+			let invoiceIds = selectedRows.map(row => row.id)
+			this.$confirm(`确定批量下载选中的 ${selectedRows.length} 条数电票吗?`, '提示', {
+				confirmButtonText: '确定',
+				cancelButtonText: '取消',
+				type: 'warning'
+			}).then(() => {
+				this.loading = true
+				financeInvoiceService.batchDownloadInvoice({ invoiceIds: invoiceIds }).then((res) => {
+					this.$utils.downloadZip(res, '批量数电票_' + this.moment(new Date()).format('YYYY-MM-DD') + '.zip')
+					this.loading = false
+					// 刷新列表以更新下载状态
+					this.refreshList()
+				}).catch((err) => {
+					this.loading = false
+					if (err.response && err.response.status === 400) {
+						// 读取后端返回的错误信息
+						let reader = new FileReader()
+						reader.onload = () => {
+							try {
+								let msg = JSON.parse(reader.result)
+								this.$message.error(msg.message || '批量下载失败')
+							} catch (e) {
+								this.$message.error('批量下载失败,请重试')
+							}
+						}
+						reader.readAsText(err.response.data)
+					} else {
+						this.$message.error('批量下载失败,请重试')
+					}
+				})
+			}).catch(() => {})
+		},
 
 		beforeChangeDingNotice() {
 			let message = this.dingNoticeEnabled == '1' ? '确定要关闭钉钉通知吗?' : '确定要开启钉钉通知吗?'

+ 35 - 0
src/views/cw/reportManagement/ReportManagementForm.vue

@@ -962,6 +962,14 @@
 							{{scope.row.receivablesStatus === '1'?'已收款':'未收款'}}
 						</template>
 					</vxe-column>
+					<vxe-column title="操作" min-width="120" align="center" fixed="right">
+						<template #default="scope">
+							<el-button v-if="scope.row.omsAttachmentUrl" type="primary" text size="small"
+								@click="handleDownloadInvoice(scope.row)">
+								<i class="el-icon-download"></i> 下载
+							</el-button>
+						</template>
+					</vxe-column>
 				</vxe-table>
 			</el-dialog>
 		</el-dialog>
@@ -1833,6 +1841,33 @@ export default {
 				}
 			})
 		},
+		// 下载单个发票
+		handleDownloadInvoice(row) {
+			this.$confirm(`确定下载当前发票文件吗?`, '提示', {
+				confirmButtonText: '确定',
+				cancelButtonText: '取消',
+				type: 'warning'
+			}).then(() => {
+				this.invoiceLoading = true
+				// 去除第一个/
+				let omsAttachmentUrl = row.omsAttachmentUrl.substring(1)
+				// 去除最后一个/线后面的内容,保留/
+				omsAttachmentUrl = omsAttachmentUrl.substring(0, omsAttachmentUrl.lastIndexOf('/') + 1)
+				cwFinanceInvoiceService.downLoadOMSInvoiceAttachzip({
+					fileUrl: omsAttachmentUrl,
+					invoiceNo: row.no
+				}).then((res) => {
+					// 将二进制流文件写入zip文件
+					this.$utils.downloadZip(res, '发票-' + row.no + '.zip')
+					this.invoiceLoading = false
+				}).catch((err) => {
+					this.invoiceLoading = false
+					if (err.response) {
+						console.log(err.response)
+					}
+				})
+			})
+		},
 	}
 }
 </script>

+ 69 - 5
src/views/finance/invoice/InvoiceList.vue

@@ -125,6 +125,13 @@
 					</el-date-picker>
 				</el-form-item>
 
+				<el-form-item v-if="showHideItem" label="下载状态" prop="downloadStatusFilter">
+					<el-select v-model="searchForm.downloadStatusFilter" placeholder="请选择下载状态" clearable style="width: 100%;">
+						<el-option label="未下载" value="0"></el-option>
+						<el-option label="已下载" value="1"></el-option>
+					</el-select>
+				</el-form-item>
+
 				<el-form-item>
 					<el-button type="default" @click="showHide" :icon="showHideIcon">{{ showHideName }}</el-button>
 					<el-button type="primary" @click="refreshList()" icon="el-icon-search">查询</el-button>
@@ -144,6 +151,9 @@
 					<el-button v-if="hasPermission('finance:invoice:importInvoiceBatch')" type="primary"
 							   @click="projectImport()" plain>批量收款导入</el-button>
 
+					<el-button type="danger" @click="batchDownloadInvoice()" plain
+						:disabled="$refs.invoiceTable && $refs.invoiceTable.getCheckboxRecords().length === 0">批量下载数电票</el-button>
+
 
 					<el-switch v-if="hasPermission('cw_finance:invoice:dd_notice')" v-model="dingNoticeEnabled"
 						inline-prompt
@@ -226,11 +236,19 @@
 									$dictUtils.getDictLabel("invoice_status", scope.row.status, '-') }} </el-button>
 						</template>
 					</vxe-column>
+					<vxe-column min-width="80" title="下载状态" fixed="right" align="center">
+						<template #default="scope">
+							<span v-if="scope.row.omsAttachmentUrl">
+								<span v-if="scope.row.downloadStatus === '1'" style="color:green;font-weight:bold;">已下载</span>
+								<span v-else style="color:#999;">未下载</span>
+							</span>
+						</template>
+					</vxe-column>
 					<vxe-column min-width="300" title="操作" fixed="right" align="center">
 						<template #default="scope">
 
 							<el-button v-if="scope.row.omsAttachmentUrl" text type="primary"
-								@click="handleDownloadAllInvoice(scope.row)">下载所有格式发票</el-button>
+								@click="handleDownloadAllInvoice(scope.row)">{{ scope.row.downloadStatus === '1' ? '已下载-再次下载' : '下载所有格式发票' }}</el-button>
 							<el-button
 								v-if="hasPermission('finance:invoice:add') && scope.row.status === '5' && scope.row.account > 0"
 								text type="primary" @click="handleRedInvoice(scope.row)">红冲</el-button>
@@ -329,7 +347,8 @@ export default {
 				reconciliationPeopleName: '',
 				reconciliationPeople: '',
 				operator: '',
-				operatorOffice: ''
+				operatorOffice: '',
+				downloadStatusFilter: ''
 			},
 			dataList: [],
 			tablePage: {
@@ -585,7 +604,8 @@ export default {
 				programId: '',
 				reconciliationPeopleName: '',
 				operator: '',
-				operatorOffice: ''
+				operatorOffice: '',
+				downloadStatusFilter: ''
 			}
 			this.$refs.searchForm.resetFields()
 			this.refreshList()
@@ -1006,11 +1026,12 @@ export default {
 				omsAttachmentUrl = omsAttachmentUrl.substring(0, omsAttachmentUrl.lastIndexOf('/') + 1)
 				this.financeInvoiceService.downLoadOMSInvoiceAttachzip({
 					fileUrl: omsAttachmentUrl,
-					invoiceNo: row.no
+					invoiceNo: row.no,
+					invoiceId: row.id
 				}).then((res) => {
-					// 将二进制流文件写入excel表,以下为重要步骤
 					this.$utils.downloadZip(res, '发票-' + row.no + '.zip')
 					this.loading = false
+					this.refreshList()
 				}).catch(function (err) {
 					this.loading = false
 					if (err.response) {
@@ -1019,6 +1040,49 @@ export default {
 				})
 			})
 		},
+		// 批量下载数电票
+		batchDownloadInvoice() {
+			let selectedRows = this.$refs.invoiceTable.getCheckboxRecords()
+			// 过滤出有OMS附件的行
+			selectedRows = selectedRows.filter(row => row.omsAttachmentUrl)
+			if (selectedRows.length === 0) {
+				this.$message.error('所选数据中不存在可下载的数电票发票,请重新选择')
+				return
+			}
+			if (selectedRows.length > 25) {
+				this.$message.error('单次批量下载不能超过25条,请重新选择')
+				return
+			}
+			let invoiceIds = selectedRows.map(row => row.id)
+			this.$confirm(`确定批量下载选中的 ${selectedRows.length} 条数电票吗?`, '提示', {
+				confirmButtonText: '确定',
+				cancelButtonText: '取消',
+				type: 'warning'
+			}).then(() => {
+				this.loading = true
+				this.financeInvoiceService.batchDownloadInvoice({ invoiceIds: invoiceIds }).then((res) => {
+					this.$utils.downloadZip(res, '批量数电票_' + this.moment(new Date()).format('YYYY-MM-DD') + '.zip')
+					this.loading = false
+					this.refreshList()
+				}).catch((err) => {
+					this.loading = false
+					if (err.response && err.response.status === 400) {
+						let reader = new FileReader()
+						reader.onload = () => {
+							try {
+								let msg = JSON.parse(reader.result)
+								this.$message.error(msg.message || '批量下载失败')
+							} catch (e) {
+								this.$message.error('批量下载失败,请重试')
+							}
+						}
+						reader.readAsText(err.response.data)
+					} else {
+						this.$message.error('批量下载失败,请重试')
+					}
+				})
+			}).catch(() => {})
+		},
 		beforeChangeDingNotice() {
 			let message = this.dingNoticeEnabled == '1' ? '确定要关闭钉钉通知吗?' : '确定要开启钉钉通知吗?'
 			return ElMessageBox.confirm(