sleep(ms) {return new Promise(resolve => setTimeout(resolve, ms));
},
/** 导出按钮操作 */handleExport() {if (this.ids.length === 0) {this.$message.warning("请至少选择一条记录进行导出");return;}this.$confirm('是否确认导出所选交接记录?', "警告", {confirmButtonText: "确定",cancelButtonText: "取消",type: "warning"}).then(async () => {try {this.$message.info("正在导出...")for (const id of this.ids) {await this.sleep(1000)await exportTxJjjlExcel(id).then(response => {this.download(response,id);});}this.$message.success('导出完成');} catch (error) {this.$message.error(`导出失败: ${error.message}`);} finally {}});
},// 下载文件
download(res,id) {// 检查响应是否为JSON格式的错误信息let find = this.jjjlList.find((e)=>e.ID==id);console.log("res",res)if (res.type === 'application/json') {// 读取JSON错误信息const reader = new FileReader();reader.onload = e => {try {const errorInfo = JSON.parse(e.target.result);this.$message.error(`导出失败: ${errorInfo.msg || '未知错误'}`);} catch (error) {this.$message.error('导出失败,请联系管理员');}};reader.readAsText(res);return;}// 正常处理Excel文件下载const blob = new Blob([res], { type: 'application/vnd.ms-excel' });const link = document.createElement('a');link.href = URL.createObjectURL(blob);link.download = `${this.parseTime(find.JBRQ,'{y}-{m}-{d}')}_${find.JBBYB}_${new Date().getTime()}.xlsx`;link.click();URL.revokeObjectURL(link.href);
}