|
@@ -90,11 +90,38 @@
|
|
|
</div>
|
|
|
</div>
|
|
|
</el-dialog>
|
|
|
+ <el-dialog title="批量打印" :visible.sync="bulkPrintVisible" width="60%" :close-on-click-modal="false">
|
|
|
+ <tables :suspension="true" :tableList="tableList1" :tableData="tableData1">
|
|
|
+ </tables>
|
|
|
+ <div style="display: flex;margin-top: 15px;justify-content: flex-end;">
|
|
|
+ <div style="display: flex;align-items: center;margin-right: 10px;">
|
|
|
+ <span style="font-size: 14px;margin-right: 8px;">湿度展示</span>
|
|
|
+ <el-switch v-model="humidity"></el-switch>
|
|
|
+ </div>
|
|
|
+ <el-button size="medium" type="primary" icon="el-icon-printer" :loading="peintFlag"
|
|
|
+ @click="bulkPrint">批量打印</el-button>
|
|
|
+ </div>
|
|
|
+ </el-dialog>
|
|
|
+ <el-dialog title="下载PDF" :visible.sync="pdfDialogVisible" width="400px">
|
|
|
+ <div style="display: flex;align-items: center;margin-right: 10px;">
|
|
|
+ <span style="font-size: 14px;margin-right: 8px;">湿度展示</span>
|
|
|
+ <el-switch v-model="humidityil"></el-switch>
|
|
|
+ </div>
|
|
|
+ <span slot="footer" class="dialog-footer">
|
|
|
+ <el-button size="medium" @click="pdfDialogVisible = false">取 消</el-button>
|
|
|
+ <el-button size="medium" type="primary" @click="downloadPdf(waybillNo)">确 定</el-button>
|
|
|
+ </span>
|
|
|
+ </el-dialog>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import {
|
|
|
+ PDFDocument
|
|
|
+ } from 'pdf-lib'
|
|
|
+ import axios from 'axios'
|
|
|
+ import Buffer from 'vue-buffer'
|
|
|
+ import {
|
|
|
getWaybill,
|
|
|
getWaybillDetails,
|
|
|
addWaybill,
|
|
@@ -128,7 +155,8 @@
|
|
|
formRules,
|
|
|
employee,
|
|
|
addressBook,
|
|
|
- sendList
|
|
|
+ sendList,
|
|
|
+ employee1
|
|
|
} from "./waybill.js";
|
|
|
import {
|
|
|
WaybillStatus
|
|
@@ -150,9 +178,10 @@
|
|
|
data() {
|
|
|
return {
|
|
|
operateList: [{
|
|
|
- type: 'add',
|
|
|
- title: '添加运单',
|
|
|
- icon: 'el-icon-plus',
|
|
|
+ type: 'print',
|
|
|
+ title: '批量打印',
|
|
|
+ colour: 'success',
|
|
|
+ icon: 'el-icon-printer',
|
|
|
}, {
|
|
|
type: 'sends',
|
|
|
title: '批量派单',
|
|
@@ -161,6 +190,10 @@
|
|
|
type: 'import',
|
|
|
title: '批量导入',
|
|
|
colour: 'warning'
|
|
|
+ }, {
|
|
|
+ type: 'add',
|
|
|
+ title: '添加运单',
|
|
|
+ icon: 'el-icon-plus',
|
|
|
}],
|
|
|
formList: [{
|
|
|
type: 'input',
|
|
@@ -239,6 +272,7 @@
|
|
|
cargoType: '',
|
|
|
customerName: '',
|
|
|
remark: '',
|
|
|
+ quantity: '',
|
|
|
},
|
|
|
formRuleList: [],
|
|
|
bookType: '',
|
|
@@ -260,6 +294,15 @@
|
|
|
staffName: '',
|
|
|
sendOrdersId: 2,
|
|
|
searchValue: {},
|
|
|
+ bulkPrintVisible: false,
|
|
|
+ tableList1: employee1(),
|
|
|
+ tableData1: [],
|
|
|
+ printIdList: [],
|
|
|
+ peintFlag: false,
|
|
|
+ humidity: true,
|
|
|
+ pdfDialogVisible: false,
|
|
|
+ humidityil: true,
|
|
|
+ waybillNo: '',
|
|
|
}
|
|
|
},
|
|
|
mounted() {
|
|
@@ -317,21 +360,7 @@
|
|
|
let flag = this.$refs['childRules'].validateForm();
|
|
|
if (senderFlag && recipientsFlag && flag) {
|
|
|
this.confirmLoading = true
|
|
|
- // let senderAddressId = null
|
|
|
- // let consigneeAddressId = null
|
|
|
- // if (!this.senderForm.id) {
|
|
|
- // senderAddressId = await this.getSender(this.senderForm)
|
|
|
- // } else {
|
|
|
- // senderAddressId = this.senderForm.id
|
|
|
- // }
|
|
|
- // if (!this.recipientsForm.id) {
|
|
|
- // consigneeAddressId = await this.getRecipients(this.recipientsForm)
|
|
|
- // } else {
|
|
|
- // consigneeAddressId = this.recipientsForm.id
|
|
|
- // }
|
|
|
var params = {
|
|
|
- // senderAddressId: senderAddressId,
|
|
|
- // consigneeAddressId: consigneeAddressId,
|
|
|
senderAddressName: this.senderForm.name,
|
|
|
senderAddressPhone: this.senderForm.phone,
|
|
|
senderAddressDetails: this.senderForm.address,
|
|
@@ -340,6 +369,7 @@
|
|
|
consigneeAddressDetails: this.recipientsForm.address,
|
|
|
...this.ruleForm
|
|
|
}
|
|
|
+ params.quantity = Number(params.quantity)
|
|
|
if (this.operationType == 'add') {
|
|
|
await addWaybill(params).then(res => {
|
|
|
if (res.code == 200) {
|
|
@@ -485,6 +515,7 @@
|
|
|
this.ruleForm.temperatureInterval = String(row.temperatureInterval)
|
|
|
this.ruleForm.deliveryCondition = row.deliveryCondition
|
|
|
this.ruleForm.cargoType = row.cargoType
|
|
|
+ this.ruleForm.quantity = row.quantity
|
|
|
this.ruleForm.customerName = row.customerName
|
|
|
this.ruleForm.remark = row.remark
|
|
|
})
|
|
@@ -495,17 +526,57 @@
|
|
|
} else if (type == 'del') {
|
|
|
this.deleteUser(row.id)
|
|
|
} else if (type == 'pdf') {
|
|
|
- this.downloadPdf(row)
|
|
|
+ this.pdfDialogVisible = true
|
|
|
+ this.waybillNo = row.waybillNo
|
|
|
+ // this.downloadPdf(row)
|
|
|
}
|
|
|
},
|
|
|
// 下载pdf
|
|
|
downloadPdf(value) {
|
|
|
getTemperature({
|
|
|
- waybillNo: value.waybillNo,
|
|
|
- }).then(res => {
|
|
|
- // console.log(res,26)
|
|
|
+ waybillNo: value,
|
|
|
+ humidityShow: this.humidityil,
|
|
|
+ }).then(response => {
|
|
|
+ if (response.fileName) {
|
|
|
+ this.pdfDialogVisible = false
|
|
|
+ //fileName = decodeURIComponent(filename);//对filename进行转码
|
|
|
+ let fileName = decodeURI(response.fileName);
|
|
|
+ if (window.navigator.msSaveOrOpenBlob) {
|
|
|
+ navigator.msSaveBlob(new Blob([response.data]), fileName);
|
|
|
+ } else {
|
|
|
+ let url = window.URL.createObjectURL(new Blob([response.data]));
|
|
|
+ let link = document.createElement('a');
|
|
|
+ link.style.display = 'none';
|
|
|
+ link.href = url;
|
|
|
+ link.setAttribute('download', fileName);
|
|
|
+ document.body.appendChild(link);
|
|
|
+ link.click();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.$message.error('未获取到文件名');
|
|
|
+ }
|
|
|
})
|
|
|
},
|
|
|
+ // 获取pdf
|
|
|
+ requestPdf(waybillNo) {
|
|
|
+ return new Promise((resolve) => {
|
|
|
+ getTemperature({
|
|
|
+ waybillNo: waybillNo,
|
|
|
+ humidityShow: this.humidity,
|
|
|
+ }).then(response => {
|
|
|
+ if (response.fileName) {
|
|
|
+ //fileName = decodeURIComponent(filename);//对filename进行转码
|
|
|
+ let fileName = decodeURI(response.fileName);
|
|
|
+ if (window.navigator.msSaveOrOpenBlob) {
|
|
|
+ navigator.msSaveBlob(new Blob([response.data]), fileName);
|
|
|
+ } else {
|
|
|
+ let url = window.URL.createObjectURL(new Blob([response.data]));
|
|
|
+ resolve(url);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ });
|
|
|
+ },
|
|
|
// 订单派单
|
|
|
sendHandleAdd() {
|
|
|
let flag = this.$refs['sendRules'].validateForm();
|
|
@@ -628,6 +699,7 @@
|
|
|
})
|
|
|
},
|
|
|
openModel(type) {
|
|
|
+ // console.log(this.$refs.refWaybill.selectionList,333)
|
|
|
this.operationType = type
|
|
|
if (type == 'add') {
|
|
|
this.tableBook()
|
|
@@ -636,9 +708,22 @@
|
|
|
} else if (type == 'sends') {
|
|
|
const arrID = this.$refs.refWaybill.waybillIds
|
|
|
if (arrID.length != 0) {
|
|
|
- this.waybillIdList = arrID
|
|
|
- this.sendDialogVisible = true
|
|
|
- this.getUserList(2)
|
|
|
+ let arr2 = []
|
|
|
+ arrID.forEach(item => {
|
|
|
+ if (item.status == 1 || item.status == 2 || item.status == 3) {
|
|
|
+ arr2.push(item.id)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ this.waybillIdList = arr2
|
|
|
+ if (arr2.length > 0) {
|
|
|
+ this.sendDialogVisible = true
|
|
|
+ this.getUserList(2)
|
|
|
+ } else {
|
|
|
+ this.$message({
|
|
|
+ message: '请选择未派单的运单',
|
|
|
+ type: 'warning'
|
|
|
+ });
|
|
|
+ }
|
|
|
} else {
|
|
|
this.$message({
|
|
|
message: '请先选择需要批量操作的运单',
|
|
@@ -648,6 +733,33 @@
|
|
|
// console.log(type, arrID, '批量派单')
|
|
|
} else if (type == 'import') {
|
|
|
this.bulkImportVisible = true
|
|
|
+ } else if (type == 'print') {
|
|
|
+ const arrID = this.$refs.refWaybill.waybillIds
|
|
|
+ if (arrID.length != 0) {
|
|
|
+ let arr3 = []
|
|
|
+ let arr4 = []
|
|
|
+ arrID.forEach(item => {
|
|
|
+ if (item.status == 8) {
|
|
|
+ arr3.push(item)
|
|
|
+ arr4.push(item.id)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ this.tableData1 = arr3
|
|
|
+ this.printIdList = arr4
|
|
|
+ if (arr3.length > 0) {
|
|
|
+ this.bulkPrintVisible = true
|
|
|
+ } else {
|
|
|
+ this.$message({
|
|
|
+ message: '请选择已签收的运单',
|
|
|
+ type: 'warning'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.$message({
|
|
|
+ message: '请先选择需要批量操作的运单',
|
|
|
+ type: 'warning'
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
// 导入
|
|
@@ -684,6 +796,67 @@
|
|
|
this.downloadFlag = false
|
|
|
})
|
|
|
},
|
|
|
+ // 批量打印
|
|
|
+ async bulkPrint() {
|
|
|
+ this.peintFlag = true
|
|
|
+ try {
|
|
|
+ let resulr = []
|
|
|
+ for (let i = 0; i < this.tableData1.length; i++) {
|
|
|
+ let urlimg = await this.requestPdf(this.tableData1[i].waybillNo)
|
|
|
+ if (urlimg) {
|
|
|
+ resulr.push(urlimg)
|
|
|
+ } else {
|
|
|
+ throw new Error('请求错误,终止请求');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const mergeBuffer = await this.mergePdf(resulr)
|
|
|
+ //文件以pdf形式进行预览
|
|
|
+ let blob = new Blob([mergeBuffer], {
|
|
|
+ type: "application/pdf;chartset=UTF-8",
|
|
|
+ });
|
|
|
+ let fileURL = URL.createObjectURL(blob);
|
|
|
+ window.open(fileURL);
|
|
|
+ this.peintFlag = false
|
|
|
+ this.bulkPrintVisible = false
|
|
|
+ } catch (error) {
|
|
|
+ throw new Error('请求错误,终止请求');
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async mergePdf(urlList) {
|
|
|
+ // eslint-disable-next-line no-async-promise-executor
|
|
|
+ return new Promise(async (resolve) => {
|
|
|
+ const promises = []
|
|
|
+ urlList.map((url) => {
|
|
|
+ // eslint-disable-next-line no-async-promise-executor
|
|
|
+ const tmp = new Promise(async (resolve) => {
|
|
|
+ const response = await axios({
|
|
|
+ method: 'get',
|
|
|
+ url,
|
|
|
+ responseType: 'arraybuffer'
|
|
|
+ })
|
|
|
+ resolve(Buffer.from(response.data))
|
|
|
+ })
|
|
|
+ promises.push(tmp)
|
|
|
+ })
|
|
|
+
|
|
|
+ const pdfBuffers = await Promise.all(promises)
|
|
|
+
|
|
|
+ const newPdf = await PDFDocument.create()
|
|
|
+ for (const buffer of pdfBuffers) {
|
|
|
+ const pdfDocument = await PDFDocument.load(buffer)
|
|
|
+ const contentPages = await newPdf.copyPages(
|
|
|
+ pdfDocument,
|
|
|
+ pdfDocument.getPageIndices()
|
|
|
+ )
|
|
|
+ for (const page of contentPages) {
|
|
|
+ newPdf.addPage(page)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const uint8Array = await newPdf.save()
|
|
|
+ const mergeBuffer = Buffer.from(uint8Array)
|
|
|
+ resolve(new Blob([mergeBuffer]))
|
|
|
+ })
|
|
|
+ },
|
|
|
// 上传文件
|
|
|
UploadImage(param) {
|
|
|
this.importFile = param.file
|