From 9c095258e40d4cb38449c7aefe7c7b9d93d859a5 Mon Sep 17 00:00:00 2001 From: zhangxiaoxu123 <819527061@qq.com> Date: 星期六, 31 十二月 2022 11:33:57 +0800 Subject: [PATCH] 发票下载 --- src/components/page/invoice/invoiceForm.vue | 13 +++++- src/assets/js/ByUtils.js | 67 +++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 3 deletions(-) diff --git a/src/assets/js/ByUtils.js b/src/assets/js/ByUtils.js index 47c1026..4183312 100644 --- a/src/assets/js/ByUtils.js +++ b/src/assets/js/ByUtils.js @@ -265,7 +265,7 @@ }).then((response) => { //vm.$loading().close(); let data = response.data; - if (data && data.code==0) { + if (data && data.code==0) { callBackFunction(data); } else { if(data.message=='-9999'){ @@ -294,6 +294,71 @@ }) }, + exportData(vm, url, data, successCallBackFunction) { + if (StringUtil.isNullOrEmpty(url)) { + vm.$alert('璇锋眰鍦板潃涓嶈兘涓虹┖', {'title': '鎻愮ず', 'type': 'warning', 'center': true, 'showClose': false}); + return; + } + let callBackFunction = function (data) { + vm.$message({message: data.message, type: 'success'}); + try { + vm.showDialog(false); + } catch (e) { + } + try { + vm.loadData(); + } catch (e) { + } + } + if (successCallBackFunction) { + callBackFunction = successCallBackFunction; + } + // var token = ""; + // if(this.getUser()){ + // token = this.getUser().token; + // } + // vm.$loading(); + vm.$axios({ + // headers: { + // 'token': token + // }, + withCredentials: false, + url: url, + method: 'post', + data: data + }).then((response) => { + //vm.$loading().close(); + let data = response.data; + console.log(response,'response'); + if (data) { + callBackFunction(data); + } else { + if(data.message=='-9999'){ + vm.$router.push({'path': '/login'}); + vm.$alert('浼氳瘽缁撴潫锛岃閲嶆柊鐧诲綍', {'title': '鎻愮ず', 'type': 'warning', 'center': true, 'showClose': false}); + }else{ + let a = ''; + if(response.data){ + if(response.data.msg){ + a=response.data.msg + }else { + a='鏈嶅姟鍣ㄦ晠闅�' + } + }else { + a="鏁版嵁閿欒" + } + vm.$alert(a , {'title': '鎻愮ず', 'type': 'warning', 'center': true, 'showClose': false}); + } + } + }).catch((e) => { + //vm.$loading().close(); + vm.$alert('鎿嶄綔鍑虹幇寮傚父锛�' + e, {'title': '閿欒', 'type': 'error', 'center': true, 'showClose': false,callback:action=> { + // byUtils.setUser(null); + // vm.$router.push({'path': '/login'}); + }}); + }) + }, + postData4(vm, url, data, successCallBackFunction) { if (StringUtil.isNullOrEmpty(url)) { vm.$alert('璇锋眰鍦板潃涓嶈兘涓虹┖', {'title': '鎻愮ず', 'type': 'warning', 'center': true, 'showClose': false}); diff --git a/src/components/page/invoice/invoiceForm.vue b/src/components/page/invoice/invoiceForm.vue index 001096d..9e2b5f9 100644 --- a/src/components/page/invoice/invoiceForm.vue +++ b/src/components/page/invoice/invoiceForm.vue @@ -167,8 +167,17 @@ let param = { fileIds : result } - this.$byutil.postData(this,url,param,res => { - + this.$byutil.exportData(this,url,param,res => { + console.log(res,'res=========') + let blob = new Blob([res], {type: 'application/pdf'}); + let downloadElement = document.createElement("a"); + let href = window.URL.createObjectURL(blob); //鍒涘缓涓嬭浇鐨勯摼鎺� + downloadElement.href = href; + downloadElement.download = '鍙戠エ涓嬭浇' + document.body.appendChild(downloadElement); + downloadElement.click(); //鐐瑰嚮涓嬭浇 + document.body.removeChild(downloadElement); //涓嬭浇瀹屾垚绉婚櫎鍏冪礌 + window.URL.revokeObjectURL(href); //閲婃斁鎺塨lob瀵硅薄 }) } }, -- Gitblit v1.9.1