|
|
@@ -245,6 +245,7 @@ export default {
|
|
|
],
|
|
|
uniqueId: "",
|
|
|
allFiles: [],
|
|
|
+ hasUploading: false,
|
|
|
invoiceNoSet: new Set(), // 已存在的发票号
|
|
|
}
|
|
|
},
|
|
|
@@ -394,6 +395,7 @@ export default {
|
|
|
this.dataListNew = [...filtered]
|
|
|
this.fileLoading = true
|
|
|
// 防止数据未更新完成,用户操作上传
|
|
|
+
|
|
|
this.loading = false
|
|
|
this.$emit('changeLoading', false)
|
|
|
// this.dataList = JSON.parse(JSON.stringify(fileList))
|
|
|
@@ -453,47 +455,142 @@ export default {
|
|
|
await httpRequest(file, fileNameInvoice(file), this.directory, this.maxValue)
|
|
|
},
|
|
|
handleSuccessUpload(response, file, fileList) {
|
|
|
-
|
|
|
},
|
|
|
-
|
|
|
async beforeUpload(file) {
|
|
|
+ this.changeLoading(true)
|
|
|
if (this.uploadDelFlag) {
|
|
|
this.$message.warning('该文件已上传,请勿重复上传');
|
|
|
this.uploadKey = Math.random()
|
|
|
-
|
|
|
return false; // 取消上传
|
|
|
} else {
|
|
|
+ // 文件大小检查
|
|
|
+ if (!beforeAvatarUpload(file, this.dataListNew, this.maxValue)) {
|
|
|
+ this.$message.error('文件大小不能超过 ' + this.maxValue + ' MB!');
|
|
|
+ this.changeLoading(false)
|
|
|
+ return false;
|
|
|
+ }
|
|
|
// 对文件进行判定
|
|
|
const isXml = file.type === 'text/xml'; // 假设只接受 XML 文件
|
|
|
if (!isXml) {
|
|
|
this.$message.error('只能上传 XML 文件');
|
|
|
+ this.changeLoading(false)
|
|
|
return false; // 取消上传
|
|
|
}
|
|
|
|
|
|
const formBody = new FormData()
|
|
|
formBody.append('file', file)
|
|
|
- let res
|
|
|
+ let fileData
|
|
|
try {
|
|
|
// 后端解析
|
|
|
- res = await this.ossService.disposeXmlFile(formBody)
|
|
|
+ fileData = await this.ossService.disposeXmlFile(formBody)
|
|
|
} catch (e) {
|
|
|
this.$message.error('发票文件解析失败')
|
|
|
+ this.changeLoading(false)
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
- // 取发票号
|
|
|
- const invoiceNo = res?.InvoiceNumber
|
|
|
- if (!invoiceNo) {
|
|
|
- this.$message.warning('发票文件解析失败')
|
|
|
- return false
|
|
|
+ //判断文件是否重复
|
|
|
+ let fileIndex = this.dataList.findIndex(fileItem => {
|
|
|
+ return fileItem.number == fileData.InvoiceNumber
|
|
|
+ })
|
|
|
+ if (fileIndex != -1) {
|
|
|
+ if (JSON.stringify(fileData) === "{}") {
|
|
|
+ this.$message.warning({ message: `数电发票:${file.name}格式错误` });
|
|
|
+ this.changeLoading(false)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.commonJS.isNotEmpty(fileData.InvoiceNumber)) {
|
|
|
+ this.$message.warning({ message: `数电发票:${file.name + "<br/>发票号:" + fileData.InvoiceNumber}<br/>已经上传,请勿重复上传`, dangerouslyUseHTMLString: true });
|
|
|
+ this.changeLoading(false)
|
|
|
+ return false
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- // 去重
|
|
|
- if (this.invoiceNoSet.has(invoiceNo)) {
|
|
|
- this.$message.warning({ message: `数电发票:${file.name + "<br/>发票号:" + invoiceNo}<br/>已经上传,请勿重复上传`, dangerouslyUseHTMLString: true });
|
|
|
- return false
|
|
|
+ this.uploadKey = Math.random();
|
|
|
+
|
|
|
+ const fileUrl = file.url;
|
|
|
+ // 检查临时 URL 是否有效
|
|
|
+ if (fileUrl && fileUrl.trim() !== '') {
|
|
|
+ try {
|
|
|
+ const temporaryUrl = await this.ossService.getTemporaryUrl(fileUrl);
|
|
|
+
|
|
|
+ if (!temporaryUrl || temporaryUrl.trim() === '') {
|
|
|
+ // 如果临时 URL 无效,则标记该文件为无效并删除
|
|
|
+ this.$message.warning({ message: `数电发票:${file.name}获取失败,上传失败。` });
|
|
|
+ this.changeLoading(false)
|
|
|
+ return false
|
|
|
+ } else {
|
|
|
+ // 如果临时 URL 有效,继续添加文件到有效文件列表
|
|
|
+ file.lsUrl = temporaryUrl;
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ // 如果临时 URL 获取失败,也标记该文件为无效
|
|
|
+ this.$message.warning({ message: `数电发票:${file.name}获取失败,上传失败。` });
|
|
|
+ this.changeLoading(false)
|
|
|
+ return false
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ // 6. 给文件添加上传时间和上传人
|
|
|
+ file.createTime = moment(new Date()).format('YYYY-MM-DD HH:mm:ss');
|
|
|
+ file.createBy = {
|
|
|
+ id: this.$store.state.user.id,
|
|
|
+ name: this.$store.state.user.name,
|
|
|
+ };
|
|
|
+ if (file !== undefined && file !== null && file !== {}) {
|
|
|
+ // 设置文件的 URL
|
|
|
+ // 仅处理 XML 文件
|
|
|
+ if (file.name && file.name.toLowerCase().endsWith(".xml")) {
|
|
|
+ if (JSON.stringify(fileData) === "{}") {
|
|
|
+ this.$message.warning({ message: `数电发票:${file.name}格式错误` });
|
|
|
+ this.changeLoading(false)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if (Object.keys(fileData).length > 0) {
|
|
|
+ this.fieldComparison(fileData, this.fileLabel);
|
|
|
+ // 检查 data 是否包含 BuyerInformationBuyerName 属性
|
|
|
+ if (fileData && 'BuyerInformationBuyerName' in fileData) {
|
|
|
+ // 验证是否有效,并进行替换操作
|
|
|
+ if (typeof fileData.BuyerInformationBuyerName === 'string') {
|
|
|
+ var buyerInformationBuyerName = fileData.BuyerInformationBuyerName
|
|
|
+ .replace(/(/g, '(')
|
|
|
+ .replace(/)/g, ')');
|
|
|
+ fileData.BuyerInformationBuyerName = buyerInformationBuyerName
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.toCompany !== fileData.BuyerInformationBuyerName) {
|
|
|
+ this.$message.warning({ message: `仅可上传${this.toCompany}的报销数电发票:<br/>${"文件名: " + file.name + "—— 发票号:" + fileData.InvoiceNumber}<br>上传失败 `, dangerouslyUseHTMLString: true });
|
|
|
+ this.changeLoading(false)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if (this.commonJS.isNotEmpty(fileData.InvoiceNumber)) {
|
|
|
+ var flag = this.invoiceReimbursementDispose(fileData)
|
|
|
+ if (flag) {
|
|
|
+ this.$message.warning({ message: `数电发票:${file.name + "-" + fileData.InvoiceNumber}<br/>已经上传,请勿重复上传`, dangerouslyUseHTMLString: true });
|
|
|
+ this.changeLoading(false)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ //查询当前发票号是否已经被报销
|
|
|
+ let isUsed = await this.ossService.isUsedByInvoiceNumber(fileData.InvoiceNumber);
|
|
|
+ if (isUsed) {
|
|
|
+ this.$message.warning({ message: `数电发票:${file.name + "<br/> 发票号:" + fileData.InvoiceNumber}<br/>已经发起或已完成报销,无法重复报销`, dangerouslyUseHTMLString: true });
|
|
|
+ this.changeLoading(false)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ let inDate = this.formatDate(fileData.IssueTime)
|
|
|
+ if (inDate.indexOf("NaN") != -1 && this.commonJS.isNotEmpty(inDate)) {
|
|
|
+ this.$message.warning({ message: `数电发票:${file.name + "<br/> 发票号:" + fileData.InvoiceNumber}<br/>日期格式错误,上传失败。`, dangerouslyUseHTMLString: true });
|
|
|
+ this.changeLoading(false)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ file.fileData = fileData;
|
|
|
return true
|
|
|
}
|
|
|
},
|
|
|
@@ -507,7 +604,7 @@ export default {
|
|
|
}, 1000) // 一秒后关闭进度条
|
|
|
}
|
|
|
},
|
|
|
- async invoiceReimbursementDisposeData(fileData, file) {
|
|
|
+ invoiceReimbursementDisposeData(fileData, file) {
|
|
|
var invoiceReimbursements = this.dataListNew;
|
|
|
//创建判断值,若行信息存在相同的发票号,则进行数据检查调整,若不存在发票号,则新增行,并将信息写入
|
|
|
var includeFlag = false;
|
|
|
@@ -588,121 +685,29 @@ export default {
|
|
|
},
|
|
|
async changes(file, fileList) {
|
|
|
// 防止上传多次触发changes
|
|
|
- if (file.status == 'ready') return //阻止上传多次触发changes
|
|
|
- try {
|
|
|
- this.uploadKey = Math.random();
|
|
|
- // 2. 文件大小检查
|
|
|
- if (!beforeAvatarUpload(file, fileList, this.maxValue)) {
|
|
|
- this.$message.error('文件大小不能超过 ' + this.maxValue + ' MB!');
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- const fileName = file.raw ? file.raw.name : file.name;
|
|
|
- const fileBody = new FormData();
|
|
|
- fileBody.append('file', file.raw);
|
|
|
- const fileData = await this.ossService.disposeXmlFile(fileBody);
|
|
|
-
|
|
|
- //判断文件是否重复
|
|
|
- let fileIndex = this.dataList.findIndex(fileItem => {
|
|
|
- return fileItem.number == fileData.InvoiceNumber
|
|
|
- })
|
|
|
- if (fileIndex != -1) {
|
|
|
- // // 记录重复文件名
|
|
|
- // const formBody = new FormData();
|
|
|
- // formBody.append('file', file.raw);
|
|
|
- // const data1 = await this.ossService.disposeXmlFile(formBody);
|
|
|
-
|
|
|
- if (JSON.stringify(fileData) === "{}") {
|
|
|
- this.$message.warning({ message: `数电发票:${file.raw.name}格式错误` });
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- if (this.commonJS.isNotEmpty(fileData.InvoiceNumber)) {
|
|
|
- this.$message.warning({ message: `数电发票:${fileName + "<br/>发票号:" + fileData.InvoiceNumber}<br/>已经上传,请勿重复上传`, dangerouslyUseHTMLString: true });
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- const fileUrl = file.raw ? file.raw.url : file.url;
|
|
|
- // 检查临时 URL 是否有效
|
|
|
- if (fileUrl && fileUrl.trim() !== '') {
|
|
|
- try {
|
|
|
- const temporaryUrl = await this.ossService.getTemporaryUrl(fileUrl);
|
|
|
+ if (file.status == 'ready' || file.status == 'uploading') return //阻止上传多次触发changes
|
|
|
+
|
|
|
+ // 检查是否有文件正在上传
|
|
|
+ this.hasUploading = fileList.some(f =>
|
|
|
+ f.status === 'ready' || f.status === 'uploading'
|
|
|
+ )
|
|
|
+ if (!this.hasUploading) {
|
|
|
+ this.$emit('changeLoading', false)
|
|
|
+ this.loading = false
|
|
|
+ } else {
|
|
|
+ this.$emit('changeLoading', this.hasUploading)
|
|
|
+ this.loading = this.hasUploading
|
|
|
+ }
|
|
|
|
|
|
- if (!temporaryUrl || temporaryUrl.trim() === '') {
|
|
|
- // 如果临时 URL 无效,则标记该文件为无效并删除
|
|
|
- this.$message.warning({ message: `数电发票:${file.name}获取失败,上传失败。` });
|
|
|
- return
|
|
|
- } else {
|
|
|
- // 如果临时 URL 有效,继续添加文件到有效文件列表
|
|
|
- file.lsUrl = temporaryUrl;
|
|
|
- }
|
|
|
- } catch (error) {
|
|
|
- // 如果临时 URL 获取失败,也标记该文件为无效
|
|
|
- this.$message.warning({ message: `数电发票:${file.name}获取失败,上传失败。` });
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
+ try {
|
|
|
|
|
|
+ let fileData = file.raw.fileData
|
|
|
// 6. 给文件添加上传时间和上传人
|
|
|
file.createTime = moment(new Date()).format('YYYY-MM-DD HH:mm:ss');
|
|
|
file.createBy = {
|
|
|
id: this.$store.state.user.id,
|
|
|
name: this.$store.state.user.name,
|
|
|
};
|
|
|
- if (file.raw !== undefined && file.raw !== null && file.raw !== {}) {
|
|
|
- // 设置文件的 URL
|
|
|
- file.url = file.raw.url;
|
|
|
- // 仅处理 XML 文件
|
|
|
- if (file.raw.name && file.raw.name.toLowerCase().endsWith(".xml")) {
|
|
|
- // 创建 FormData 对象并发送文件
|
|
|
- // const formBody = new FormData();
|
|
|
- // formBody.append('file', file.raw);
|
|
|
- // 调用后端接口解析 XML 文件
|
|
|
- // let data2 = await this.ossService.disposeXmlFile(formBody);
|
|
|
- if (JSON.stringify(fileData) === "{}") {
|
|
|
- this.$message.warning({ message: `数电发票:${file.raw.name}格式错误` });
|
|
|
- return
|
|
|
- }
|
|
|
- if (Object.keys(fileData).length > 0) {
|
|
|
- this.fieldComparison(fileData, this.fileLabel);
|
|
|
- // 检查 data 是否包含 BuyerInformationBuyerName 属性
|
|
|
- if (fileData && 'BuyerInformationBuyerName' in fileData) {
|
|
|
- // 验证是否有效,并进行替换操作
|
|
|
- if (typeof fileData.BuyerInformationBuyerName === 'string') {
|
|
|
- var buyerInformationBuyerName = fileData.BuyerInformationBuyerName
|
|
|
- .replace(/(/g, '(')
|
|
|
- .replace(/)/g, ')');
|
|
|
- fileData.BuyerInformationBuyerName = buyerInformationBuyerName
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (this.toCompany !== fileData.BuyerInformationBuyerName) {
|
|
|
- this.$message.warning({ message: `仅可上传${this.toCompany}的报销数电发票:<br/>${"文件名: " + file.raw.name + "—— 发票号:" + fileData.InvoiceNumber}<br>上传失败 `, dangerouslyUseHTMLString: true });
|
|
|
- return
|
|
|
- }
|
|
|
- if (this.commonJS.isNotEmpty(fileData.InvoiceNumber)) {
|
|
|
- var flag = this.invoiceReimbursementDispose(fileData)
|
|
|
- if (flag) {
|
|
|
- this.$message.warning({ message: `数电发票:${file.raw.name + "-" + fileData.InvoiceNumber}<br/>已经上传,请勿重复上传`, dangerouslyUseHTMLString: true });
|
|
|
- return
|
|
|
- }
|
|
|
- //查询当前发票号是否已经被报销
|
|
|
- let isUsed = await this.ossService.isUsedByInvoiceNumber(fileData.InvoiceNumber);
|
|
|
- if (isUsed) {
|
|
|
- this.$message.warning({ message: `数电发票:${file.raw.name + "<br/> 发票号:" + fileData.InvoiceNumber}<br/>已经发起或已完成报销,无法重复报销`, dangerouslyUseHTMLString: true });
|
|
|
- return
|
|
|
- }
|
|
|
- let inDate = this.formatDate(fileData.IssueTime)
|
|
|
- if (inDate.indexOf("NaN") != -1 && this.commonJS.isNotEmpty(inDate)) {
|
|
|
- this.$message.warning({ message: `数电发票:${file.raw.name + "<br/> 发票号:" + fileData.InvoiceNumber}<br/>日期格式错误,上传失败。`, dangerouslyUseHTMLString: true });
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
let obj = this.dataList.find(tempFile => {
|
|
|
return tempFile.number == fileData.InvoiceNumber
|
|
|
})
|
|
|
@@ -714,13 +719,46 @@ export default {
|
|
|
// 发票号赋值给文件
|
|
|
file.remarks = this.uniqueId
|
|
|
file.number = fileData.InvoiceNumber
|
|
|
- // 记录发票号,防止重复上传
|
|
|
- this.invoiceNoSet.add(fileData.InvoiceNumber)
|
|
|
// 将新符合条件的文件追加到原文件列表上
|
|
|
this.dataListNew.push(file)
|
|
|
this.fileList.push(file)
|
|
|
this.dataList = this.dataListNew
|
|
|
|
|
|
+ if (fileData.InvoiceNumber == file.number) {
|
|
|
+ // 如果 file.raw 存在且有效
|
|
|
+ if (file.raw !== undefined && file.raw !== null && file.raw !== {}) {
|
|
|
+ // 设置文件的 URL
|
|
|
+ file.url = file.raw.url;
|
|
|
+
|
|
|
+ // 仅处理 XML 文件
|
|
|
+ if (file.raw.name && file.raw.name.toLowerCase().endsWith(".xml")) {
|
|
|
+ // 创建 FormData 对象并发送文件
|
|
|
+ try {
|
|
|
+ // 调用后端接口解析 XML 文件
|
|
|
+ if (fileData && 'BuyerInformationBuyerName' in fileData) {
|
|
|
+ this.fieldComparison(fileData, this.fileLabel);
|
|
|
+ // 验证是否有效,并进行替换操作
|
|
|
+ if (typeof fileData.BuyerInformationBuyerName === 'string') {
|
|
|
+ var buyerInformationBuyerName = fileData.BuyerInformationBuyerName
|
|
|
+ .replace(/(/g, '(')
|
|
|
+ .replace(/)/g, ')');
|
|
|
+ fileData.BuyerInformationBuyerName = buyerInformationBuyerName
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Object.keys(fileData).length > 0) {
|
|
|
+ // 解析成功,更新数据行
|
|
|
+ this.invoiceReimbursementDisposeData(fileData, file);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (error) {
|
|
|
+ this.$message.error('处理 XML 文件失败');
|
|
|
+ console.log('XML 处理失败', error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
// 清空 fileList,如果 fileList 不为空
|
|
|
if (fileList && fileList.length > 0) {
|
|
|
@@ -746,7 +784,8 @@ export default {
|
|
|
// 👇 初始化时主动触发一次
|
|
|
this.setNodeSort(null, null, 'init');
|
|
|
// 在 changes 完成后,手动调用 handleUploadSuccess
|
|
|
- await this.handleUploadSuccess(null, fileData, this.fileList); // 传入空参数或实际参数
|
|
|
+ // await this.handleUploadSuccess(null, fileData, this.fileList); // 传入空参数或实际参数
|
|
|
+
|
|
|
} catch (error) {
|
|
|
this.$message.error({
|
|
|
message: `上传出错,${error.message}`
|
|
|
@@ -814,13 +853,8 @@ export default {
|
|
|
// 仅处理 XML 文件
|
|
|
if (item.raw.name && item.raw.name.toLowerCase().endsWith(".xml")) {
|
|
|
// 创建 FormData 对象并发送文件
|
|
|
- // const formBody = new FormData();
|
|
|
- // formBody.append('file', item.raw);
|
|
|
-
|
|
|
try {
|
|
|
// 调用后端接口解析 XML 文件
|
|
|
- // let data = await this.ossService.disposeXmlFile(formBody);
|
|
|
- // 检查 data 是否包含 BuyerInformationBuyerName 属性
|
|
|
if (fileData && 'BuyerInformationBuyerName' in fileData) {
|
|
|
this.fieldComparison(fileData, this.fileLabel);
|
|
|
// 验证是否有效,并进行替换操作
|
|
|
@@ -836,14 +870,7 @@ export default {
|
|
|
// 解析成功,更新数据行
|
|
|
await this.invoiceReimbursementDisposeData(fileData, item);
|
|
|
}
|
|
|
- // else {
|
|
|
- // // XML 格式错误,删除文件
|
|
|
- // this.$message.warning('上传的数电发票格式错误');
|
|
|
- // const index = this.fileList.findIndex(f => f.name === item.name);
|
|
|
- // if (index !== -1) {
|
|
|
- // this.deleteFileById(this.fileList[index], index, this.fileList);
|
|
|
- // }
|
|
|
- // }
|
|
|
+
|
|
|
} catch (error) {
|
|
|
this.$message.error('处理 XML 文件失败');
|
|
|
console.log('XML 处理失败', error);
|
|
|
@@ -968,6 +995,10 @@ export default {
|
|
|
this.$message.warning('请等待附件上传完成再进行操作')
|
|
|
return true
|
|
|
}
|
|
|
+ if (this.hasUploading === true) {
|
|
|
+ this.$message.warning('请等待附件上传完成再进行操作')
|
|
|
+ return true
|
|
|
+ }
|
|
|
if (this.fileLoading === false) {
|
|
|
this.$message.warning('请等待附件加载完成再进行操作')
|
|
|
if (this.dataListLength === this.dataListNew.length) {
|
|
|
@@ -994,11 +1025,8 @@ export default {
|
|
|
},
|
|
|
// 开启/关闭页面的加载中状态
|
|
|
changeLoading(loading) {
|
|
|
- if (this.commonJS.isNotEmpty(loading)) {
|
|
|
- this.loading = loading
|
|
|
- } else {
|
|
|
- this.loading = false
|
|
|
- }
|
|
|
+ this.$emit('changeLoading', loading)
|
|
|
+ this.loading = loading
|
|
|
},
|
|
|
getSummaries(param) {
|
|
|
const { columns, data } = param;
|