Quellcode durchsuchen

评估-发票台账处理功能开发

徐滕 vor 1 Woche
Ursprung
Commit
02cb0e818d

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

@@ -176,4 +176,14 @@ export default class FinanceInvoiceService {
 			responseType: "blob",
 		});
 	}
+
+	// 台账导入导出
+	importLedger(data) {
+		return request({
+			url: prefix + "/finance/invoice/importLedger",
+			method: "post",
+			data: data,
+			responseType: "blob",
+		});
+	}
 }

+ 30 - 1
src/views/finance/invoice/InvoiceList.vue

@@ -154,7 +154,11 @@
 					<el-button v-if="hasPermission('finance:invoice:importInvoiceBatch')" type="primary"
 							   @click="projectImport()" plain>批量收款导入</el-button>
 
-					<el-button type="danger" @click="batchDownloadInvoice()" plain
+					<el-button v-if="hasPermission('finance:invoice:ledgerImportExport')" type="success"
+							   @click="ledgerImportExport()" plain style="margin-left: 10px;">台账导入导出</el-button>
+					<input ref="ledgerFileInput" type="file" accept=".xls,.xlsx" style="display:none" @change="handleLedgerFileChange" />
+
+					<el-button type="danger" @click="batchDownloadInvoice()" plain style="margin-left: 10px;"
 						:disabled="$refs.invoiceTable && $refs.invoiceTable.getCheckboxRecords().length === 0">批量下载数电票</el-button>
 
 
@@ -417,6 +421,31 @@ export default {
 			this.$refs.invoiceListImport.init()
 		},
 
+		// 台账导入导出
+		ledgerImportExport() {
+			this.$refs.ledgerFileInput.click()
+		},
+		handleLedgerFileChange(event) {
+			const file = event.target.files[0]
+			if (!file) return
+
+			const formData = new FormData()
+			formData.append('file', file)
+
+			this.loading = true
+			this.financeInvoiceService.importLedger(formData).then((res) => {
+				this.$utils.downloadExcel(res, '评估公司台账_' + this.moment(new Date()).format('YYYY-MM-DD') + '.xlsx')
+				this.$message.success('台账导出成功')
+				this.loading = false
+			}).catch((err) => {
+				this.$message.error('台账导入导出失败:' + (err.message || '未知错误'))
+				this.loading = false
+			}).finally(() => {
+				// 清空input,允许重复选择同一文件
+				event.target.value = ''
+			})
+		},
+
 		handleImportError(data) {
 			console.log("父页面收到错误:", data);