diff --git a/src/views/projectFront/buildEquipToolManage/equipmentManage.vue b/src/views/projectFront/buildEquipToolManage/equipmentManage.vue index e09445c8..439e0094 100644 --- a/src/views/projectFront/buildEquipToolManage/equipmentManage.vue +++ b/src/views/projectFront/buildEquipToolManage/equipmentManage.vue @@ -89,11 +89,16 @@ 新增 + + 批量打印 + + max-height="590px" @selection-change="handleSelectionChangeTable"> + + @@ -161,7 +166,8 @@ + :visible.sync="cardDialog" :width="isAdd == 1 || isAdd == 2 ? '600px' : '1100px'" + :before-close="handleClose">
@@ -308,6 +314,21 @@
+ + +
+
+ {{ this.percentageTitle }} +
+ + +
+
@@ -320,61 +341,61 @@
-
- {{ workDetail.equipmentName }} +
+ {{ workDetail.equipmentName }} +
+
+ 特种设备 +
-
- 特种设备 -
-
- - - {{ workDetail.specificationModel }} - - - {{ workDetail.projectEquipmentNumber ? workDetail.projectEquipmentNumber : '--' }} - - - {{ workDetail.equipmentManagerName }} - - - {{ workDetail.onSiteHandlerName }} - - - {{ workDetail.actualOnSiteDate }} - - - {{ workDetail.shipmentDate }} - - - {{ workDetail.status }} - - - {{ workDetail.manufacturer }} - - - {{ workDetail.equipmentSourceUnit }} - - - - {{ workDetail.installationRemovalUnit }} - - - - {{ workDetail.equipmentLocation }} - - - {{ workDetail.ownershipNumber }} - - - {{ workDetail.serviceLife }} - - - +
-
+
- + + 打印方案二维码
@@ -417,6 +461,8 @@ import { getConstructionEquipmentByIdApi, getConstructionEquipmentFileListApi, + + downloadConstructionEquipmentCheckFileApi, } from '@/assets/js/api/buildEquipToolManage' import { getWorkerInfoList } from '@/assets/js/api/laborPerson.js' import { isJSON } from "@/util/nowDate/index"; @@ -428,6 +474,10 @@ export default { }, data() { return { + percentage: 0, + percentageTitle: "正在下载中,请稍后", + cardDialog2: false, + formLabelWidthDetail: "140px", styleType: 1, classificationName: '', @@ -530,6 +580,8 @@ export default { dialogTitle: '', isEdit: false, dialogFormVisible: true, + downloadPicInfoList: [], + equipmentBgImg: "", } }, watch: { @@ -544,19 +596,74 @@ export default { this.getDutyPerson(); }, methods: { + getProgress(rowUrl) { + //进度条恢复为 0 + this.percentage = 0; + //发起请求 + this.$http({ + //下载文件的远端地址。 + url: rowUrl, + //请求方式 get post。 + method: "get", + //设置返回数据类型为base64的数据,这样才可以被new Blob() 解析。 + responseType: "blob", + //请求参数 get-->params post-->data 。 + params: {}, + //xml返回数据的钩子函数,可以用来获取数据的进度 具体可查看axios的官网 + onDownloadProgress: (progressEvent) => { + //progressEvent.loaded 下载文件的当前大小 + //progressEvent.total 下载文件的总大小 如果后端没有返回 请让他加上! + let progressBar = Math.round(progressEvent.loaded / progressEvent.total * 100); + //接收进度为99%的时候需要留一点前端编译的时间 + if (progressBar >= 99) { + this.percentage = 99; + this.percentageTitle = '下载完成,文件正在编译。'; + } else { + this.percentage = progressBar; + this.percentageTitle = '正在下载,请耐心等待...'; + } + } + }).then(res => { + //当前定义res.message 出现的时候说明后端文件返回出现了问题 不然应该直接是个文件流 + if (res.status != 200) { + this.percentageTitle = '下载失败,请重试。'; + return + } + console.log(res.data) + // return; + // 创建一个下载链接 + const url = window.URL.createObjectURL(res.data); + // 创建一个元素 + const link = document.createElement("a"); + link.href = url; + link.download = "施工设备机具二维码"; // 指定下载文件的文件名 + // 模拟点击下载链接 + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + // 释放URL对象 + window.URL.revokeObjectURL(url); + this.percentageTitle = '下载完成'; + //编译文件完成后,进度条展示为100%100 + this.percentage = 100; + }) + }, printBtn() { - // setTimeout(() => { - // console.log(this.$refs["qrCodeDiv"].innerHTML) - // },100) - // qrCode - setTimeout(() => { - let printDemo = this.$refs["qrCodeDiv1"].innerHTML; - console.log(printDemo, oldStr); - window.document.body.innerHTML = printDemo; - //没有图片直接打印 - window.print(); - window.location.reload(); - }, 100); + const printContentHtml = document.getElementById("qrCodeDiv2").innerHTML; + // console.log(printContentHtml); + const iframe = document.createElement("iframe"); + // iframe.setAttribute( + // "style", + // "position:absolute;width:0px;height:0px;left:-500px;top:-500px;" + // ); + document.body.appendChild(iframe); + iframe.contentDocument.write(printContentHtml); + iframe.contentDocument.close(); + iframe.onload = function(){ //解决图片显示不了的问题 + iframe.contentWindow.print(); + document.body.removeChild(iframe); + }; + }, //生成 二维码 bindQRCode(id) { @@ -571,13 +678,40 @@ export default { // `${httpUrl}/doc/h5Entry/index.html?userId=${userId}&projectSn=${projectSn}` new QRCode(this.$refs.qrCodeDiv1, { text: `/pages/projectEnd/buildEquipToolManage/equipmentManage/detail?id=${id}`, - width: 200, - height: 200, + width: 120, + height: 120, colorDark: "#333333", //二维码颜色 colorLight: "#ffffff", //二维码背景色 correctLevel: QRCode.CorrectLevel.L, //容错率,L/M/H }); }, + // 批量打印 + bulkPrint() { + downloadConstructionEquipmentCheckFile(1) + }, + downloadConstructionEquipmentCheckFile(type) { + const ids = type == 1 ? this.downloadPicInfoList.map((item) => item.id).join(",") : this.detailId; + downloadConstructionEquipmentCheckFileApi({ + projectSn: this.projectSn, + ids: ids, + }).then((res) => { + if (res.code == 200) { + const url = res.result.file.includes("http://") ? res.result.file : this.$store.state.FILEURL + res.result.file; + if (type == 1) { + this.getProgress(url); + this.cardDialog2 = true; + } else { + this.equipmentBgImg = url; + } + } else { + this.$message.error(res.msg); + } + }); + }, + handleSelectionChangeTable(selection) { + this.downloadPicInfoList = selection; + console.log(selection); + }, //获取左侧---列表信息 getDangerTypeRecordList() { console.log(22) @@ -588,7 +722,17 @@ export default { getConstructionEquipmentCategoryTreeApi(data).then((res) => { if (res.code == 200) { if (res.result.length > 0) { - this.listData = res.result + if (this.classificationName) { + this.listData = res.result; + this.getCheckedNode(this.listData[0]); + } else { + this.listData = [{ + id: "", + children: [], + classificationName: "全部", + }, ...res.result]; + this.getCheckedNode(this.listData[0]); + } } else { this.listData = [] } @@ -698,7 +842,7 @@ export default { originName: item.fileList[0].name, fileUrl: item.fileList[0].url, }; - if(item.constructionEquipmentToolId){ + if (item.constructionEquipmentToolId) { obj.constructionEquipmentToolId = item.constructionEquipmentToolId; obj.id = item.id; } @@ -738,7 +882,7 @@ export default { this.$t("message.personnelPosition.add_success") ); //添加成功! }); - } + } // else if (this.isAdd == 4) { // editConstructionEquipmentApi(result).then((res) => { // this.cardDialog = false; @@ -987,12 +1131,12 @@ export default { ...val, ...res.result, }; - this.$nextTick(() => { - this.bindQRCode(val.id); - }) + // this.$nextTick(() => { + // this.bindQRCode(val.id); + // }) } }); - + this.downloadConstructionEquipmentCheckFile(2); this.isSuperDanger = val.issuperdanger; }, }, @@ -1008,9 +1152,71 @@ export default { } \ No newline at end of file +} + \ No newline at end of file