1.创建一个map 动态加入数组
2.每个数据只要平台变化了就新增一个新数组
//混平台打印并且循环给打印机而且保证顺序
sendToPrint3(printData) {
const self = this
return new Promise((resolve, reject) => {
if (printData) {
let sourcePlatformCode = printData[0].expressPrintType;
let key = 1
let platformData = new Map()
for (let i = 0; i < printData.length; i++) {
if (printData[i].expressPrintType == sourcePlatformCode) {
if (platformData.get(key)) {
platformData.get(key).push(printData[i])
} else {
let arr = new Array()
arr.push(printData[i])
platformData.set(key, arr)
}
} else {
key++
sourcePlatformCode = printData[i].expressPrintType
let arr = new Array()
arr.push(printData[i])
platformData.set(key, arr)
}
}
console.log('组装的map对不对: ', platformData); 这个是重点
let num = 1
self.doPrintFn3(platformData, num, resolve, reject)
}
})
},
打印
doPrintFn3(platformData, num,resolve, reject) {
const self = this
let listObj=platformData.get(num)
listObj.map((item,i,arr)=>{
if (item.templateType === 'KDMD' && item.expressPrintType === 'STD-PDD') {
let count = 0
PddPrint.PddPrint(null, item, function (data) {
if (data.printStatus && data.printStatus[0].status === 'success' && data.cmd == 'notifyPrintResult') {//成功
count++
if (count == arr.length && num < platformData.size) {//保证小数组最后一条
self.doPrintFn3(platformData, num+1, resolve, reject)
}
if(num == platformData.size&&count == arr.length){//所有打印完调用更新热敏次数方法
resolve('success')
}
}
// 打印成功失败
if (data.cmd !== undefined && data.cmd !== 'print') {
if (data.printStatus[0].status === 'failed') {
reject(data)
}
}
})
} else if (item.templateType === 'KDMD' && item.expressPrintType === 'STD-TIKTOK') {
let count = 0
TikTokPrint.TikTokPrint(null, item, function (data) {
if (data.printStatus && data.printStatus[0].status == 'success' && data.cmd == 'notifyPrintResult') { //成功
count++
if (count == arr.length && num < platformData.size) {//保证小数组最后一条
self.doPrintFn3(platformData, num+1, resolve, reject)
}
if(num == platformData.size&&count == arr.length){//所有打印完调用更新热敏次数方法
resolve('success')
}
}
if (data.cmd === 'print' && data.status !== 'success') {
self.$Notice.error({
title: this.$t('public.title.failTitle'),
desc: 'TaskID:' + data.taskID + '打印失败,错误原因:' + data.status,
duration: 0
})
}else if (data.printStatus && data.printStatus[0].status === 'failed ' && data.taskStatus === 'printed') {
self.$Notice.error({
title: this.$t('public.title.failTitle'),
desc: '承运商单号:' + data.printStatus[0].documentID + '打印失败,错误原因:' + data.printStatus[0].msg,
duration: 0
})
}
})
} else if (item.templateType === 'KDMD' && item.expressPrintType === 'STD-JD') {
let count = 0;
JdPrint.JdPrint(null, item, function (data) {
if (data.success === 'true') {
count++
if (count == arr.length && num < platformData.size) {//保证小数组最后一条
self.doPrintFn3(platformData, num+1, resolve, reject)
}
if(num == platformData.size&&count == arr.length){//所有打印完调用更新热敏次数方法
resolve('success')
}
}
if (data.success !== 'true') {
self.$Notice.error({
title: self.$t('public.title.failTitle'),
desc: '承运商单号:' + data.key + '打印失败,错误原因:' + data.message,
duration: 0
})
}
})
} else if (item.templateType === 'KDMD' && item.expressPrintType === 'STD-KUAISHOU') {
let count;
KuaiShou.KuaiShouPrint(null, item, function (data) {
if (data.printStatus && data.printStatus[0].status == 'success' && data.cmd == 'notifyPrintResult') {//成功
count++
if (count == arr.length && num < platformData.size) {//保证小数组最后一条
self.doPrintFn3(platformData, num+1, resolve, reject)
}
if(num == platformData.size&&count == arr.length){//所有打印完调用更新热敏次数方法
resolve('success')
}
}
// 打印成功失败
if (data.cmd !== undefined && data.cmd !== 'print') { // 打印完成
if (data.printStatus && data.printStatus[0].status === 'failed') { // 全部打印失败
reject(data)
}
}
})
} else if (item.templateType === 'KDMD' && item.expressPrintType === 'STD-WPH') {
let count = 0
WeiPinHui.WPHPrint(null, item, function (data) {
if (data.result == 'success' && data.cmd == 'notifyPrintResult') {
count++
if (count == arr.length && num < platformData.size) {//保证是最后一条
self.doPrintFn3(platformData, num+1, resolve, reject)
}
if(num == platformData.size&&count == arr.length){//所有打印完调用更新热敏次数方法
resolve('success')
}
}
if (data.cmd === 'print' && data.result !== 'success') { //失败
self.$Notice.error({
title: this.$t('public.title.failTitle'),
desc: 'traceId:' + data.traceId + '打印失败,错误原因:' + data.result,
duration: 0
})
}
})
} else if (item.templateType === 'KDMD' && item.expressPrintType === 'STD-WPH-JITX') {
//唯品会打印机打印json开始
let count = 0
WPHCainiao.CainiaoPrint(null, item, function (data) {
if (data.result == 'success' && data.cmd == 'notifyPrintResult') {//成功
count++
if (count == arr.length && num < platformData.size) {//保证是最后一条
self.doPrintFn3(platformData, num+1,resolve, reject)
}
if(num == platformData.size&&count == arr.length){//所有打印完调用更新热敏次数方法
resolve('success')
}
}
// 打印成功失败
if (data.cmd !== undefined && data.cmd !== 'print') {
if (data.printStatus && data.printStatus[0].status === 'failed') {
reject(data)
}
}
})
//唯品会打印机打印json结束templateType: "FHQD"
} else if (item.templateType === 'KDMD' && item.expressPrintType === 'STD-DW') {
ZPL_JSSDK.tmsPrint(item, function (data) {
self.$Notice.error({
title: self.$t('public.title.warningTitle'),
desc: data
})
//tmsPrint(data,callback)的data参数为第二步中,品牌直发订单获取打印面单接口返回的data对象,callback为打印失败时的回调函数。
})
this.getList()
} else {
let count = 0
Cainiao.CainiaoPrint(null, item, function (data) {
if (data.printStatus && data.printStatus[0].status == 'success' && data.taskStatus === 'rendered') {//渲染成功
count++
if (count == arr.length && num < platformData.size) {//保证是最后一条
self.doPrintFn3(platformData, num+1, resolve, reject)
}
if(num == platformData.size&&count == arr.length){//所有打印完调用更新热敏次数方法
resolve('success')
}
}
// 打印成功失败
if (data.cmd !== undefined && data.cmd !== 'print') {
if (data.taskStatus == 'failed' || data.printStatus[0].status === 'failed') {
reject(data)
self.$Notice.error({
title: self.$t('public.title.failTitle'),
desc: 'taskID:' + data.taskID + '打印失败,错误原因:' + data.mag ? (data.msg + ',' + data.printStatus[0].msg) : data.printStatus[0].msg,
duration: 0
})
}
}
})
}
})
},