|
@@ -143,20 +143,69 @@ export const jGPrint = function (data, type, callback, printLogParams, printPage
|
|
|
}
|
|
|
|
|
|
// 自动排版, 遍历数组,将数组中每一个数值加起来,如果和小于某个数,则将这些数值存放到一个新数组中。
|
|
|
-export const groupLessThan = function(numbers, targetSum) {
|
|
|
- let currentSum = 0;
|
|
|
- let result = [];
|
|
|
- for (let i = 0; i < numbers.length; i++) {
|
|
|
- currentSum += numbers[i].h;
|
|
|
- if (currentSum <= targetSum) {
|
|
|
- result.push(numbers[i].t);
|
|
|
- } else {
|
|
|
- result.push('&-NEWPAGE-&'); // 用'&-NEWPAGE-&'作为分页符
|
|
|
- currentSum = numbers[i].h; // 重新计算当前总和
|
|
|
- result.push(numbers[i].t);
|
|
|
- }
|
|
|
+export const groupLessThan = function(html) {
|
|
|
+ const pageMidHeight = 535 // 半页高度
|
|
|
+ const pageHeight = pageMidHeight*2 // 页高度
|
|
|
+ const arr = []
|
|
|
+ const result = []
|
|
|
+ for (let i = 0; i < html.length; i++) {
|
|
|
+ const h = html[i].clientHeight // 总高度
|
|
|
+ const pz = h<=pageMidHeight ? '0.5' : (h/pageHeight).toFixed(2) // 页数
|
|
|
+ arr.push({
|
|
|
+ h: h,
|
|
|
+ pz: pz,
|
|
|
+ t: '<div style="height:'+(pz<=0.5?pageMidHeight:'auto')+'px'+';border:1px solid #fff;">'+html[i].innerHTML+'</div>',
|
|
|
+ flag: 0
|
|
|
+ })
|
|
|
}
|
|
|
- return result;
|
|
|
+ console.log(arr)
|
|
|
+ // 找出所有小于半张纸的
|
|
|
+ const a = arr.filter(item => item.pz <= 0.5)
|
|
|
+ // 先找出所有超过半张纸的,小于一张纸的
|
|
|
+ const b = arr.filter(item => item.pz >0.5 && item.pz <= 1)
|
|
|
+ // 找出所有超过一张纸的
|
|
|
+ const c = arr.filter(item => item.pz > 1)
|
|
|
+ // 先给c 找匹配的另一半
|
|
|
+ for(let i=0;i<c.length;i++){
|
|
|
+ const pz = Number(c[i].pz.split('.')[1])
|
|
|
+ // 先从b中找
|
|
|
+ const hasOther = b.findIndex(item => (item.pz + pz) < 1)
|
|
|
+ if(hasOther>=0){
|
|
|
+ result.push(c[i].t + b[hasOther].t)
|
|
|
+ // 删除hasOther
|
|
|
+ b.splice(hasOther,1)
|
|
|
+ }else{
|
|
|
+ // 再从a中找
|
|
|
+ const hasOtherA = a.findIndex(item => (item.pz + pz) < 1)
|
|
|
+ if(hasOtherA>=0){
|
|
|
+ result.push(c[i].t + a[hasOtherA].t)
|
|
|
+ // 删除hasOtherA
|
|
|
+ b.splice(hasOther,1)
|
|
|
+ }else{
|
|
|
+ // 都没匹配到
|
|
|
+ result.push(c[i].t)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将b依次加入
|
|
|
+ for(let i=0;i<b.length;i++){
|
|
|
+ result.push(b[i].t)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将a中每2个放到一个容器中
|
|
|
+ if(a.length%2!=0){
|
|
|
+ a.push({t:''})
|
|
|
+ }
|
|
|
+ for(let i=0;i<a.length;i=i+2){
|
|
|
+ result.push(a[i].t + a[i+1].t)
|
|
|
+ }
|
|
|
+
|
|
|
+ // console.log(a)
|
|
|
+ // console.log(b)
|
|
|
+ // console.log(c)
|
|
|
+ // console.log(result)
|
|
|
+ return result
|
|
|
}
|
|
|
|
|
|
// 批量打印销售收款单html
|
|
@@ -189,9 +238,9 @@ export const jGPlPrint = function (data, type, callback, printLogParams, taskNam
|
|
|
// LODOP.SET_PRINT_MODE('CATCH_PRINT_STATUS', true)
|
|
|
// TaskID:任务id,Value:job代码
|
|
|
LODOP.On_Return = function (TaskID, Value) {
|
|
|
- console.log(TaskID, Value, printLogParams)
|
|
|
+ console.log(TaskID, Value!=0, printLogParams)
|
|
|
// 已打印
|
|
|
- if (Value) {
|
|
|
+ if (Number(Value)) {
|
|
|
if(printLogParams){
|
|
|
console.log('已打印,统计打印次数')
|
|
|
printLog(printLogParams, callback)
|
|
@@ -209,7 +258,7 @@ export const jGPlPrint = function (data, type, callback, printLogParams, taskNam
|
|
|
if(data.length>1){
|
|
|
// 循环页
|
|
|
for(var i=0;i<data.length;i++){
|
|
|
- LODOP.NewPage();
|
|
|
+ LODOP.NewPageA();
|
|
|
LODOP.ADD_PRINT_HTM(0, 0, '100%', '99%', data[i])
|
|
|
}
|
|
|
}else{
|