prints-dynamic.js
26.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
/**
* Created by Administrator on 2015/2/27.
*/
angular.module("xn/template/print.html", []).run(["$templateCache", function ($templateCache) {
"use strict";
$templateCache.put("xn/template/print/printLogisticsDynamic.html",
" <div class=\"print-logistics\" id=\"{{logisticsId}}\" onselectstart=\"return false\" ng-mousemove=\"doMove($event)\" ng-mouseup=\"doUp()\" >"+
" <div class=\"logistics-box-top\" >" +
" <div class='print-logistics-line clearfix'>" +
" <label class='logistics-label'>选择模板:</label> " +
" <select ng-disabled=\"{{isEdit}}\" name=\"template\" class='form-control logistics-input' ng-model=\"templateData\" ng-change=\"selectTemplate(templateData)\" " +
" ng-options=\"template as template.name for template in templateList\">"+
" <option value=\"\" >---请选择模板---</option>"+
" </select>" +
" </div>" +
" <div class='print-logistics-line clearfix'>" +
" <label class='logistics-label'>模板名称:</label> " +
" <input type=\"text\" name=\"account\" ng-model=\"logistics.title\" class=\"form-control logistics-input\">" +
" </div>" +
" <div class='print-logistics-line clearfix'>" +
" <label class='logistics-label'>快递公司:</label> " +
" <select name=\"logistics.templateKey\" class='form-control logistics-input' ng-model=\"logistics.carrierId\" " +
" ng-options=\"carrier.id as carrier.name for carrier in carrierList\">"+
" <option value=\"\" >---请选择快递公司---</option>"+
" </select>" +
" </div>" +
" <div class='print-logistics-line clearfix'>" +
" <label class='logistics-label'>运单图片:</label>"+
" <button ng-click=\"upImg()\" class='btn btn-default'>上传图片</button> " +
" <div xn-attachment-box-single ng-Model=\"logisticsImg\" data-is-open-single=\"isOpenSingle\"></div>"+
" </div>" +
" <div class='print-logistics-line clearfix'>" +
" <label class='logistics-label'>模板尺寸:</label>"+
" <div class='f-left'>宽:</div> <input type=\"text\" name=\"account\" ng-model=\"size.width\" class=\"form-control logistics-size\"> <div class='f-left mr_10'>mm</div>" +
" <div class='f-left'> 高:</div> <input type=\"text\" name=\"account\" ng-model=\"size.height\" class=\"form-control logistics-size\"><div class='f-left mr_10'>mm</div>" +
" <button ng-click=\"setSize()\" class='btn btn-default mr_10 f-left'>重设</button> " +
" <div ng-show=\"setSizeTip.state\" class='f-left' ng-click=\"closeSize()\" >{{setSizeTip.content}}</div> " +
" </div>" +
" <div class='print-logistics-line clearfix'>" +
" <label class='logistics-label'>模板偏移量:</label>"+
" <div class='f-left'>宽:</div> <input type=\"text\" name=\"account\" ng-model=\"logistics.offset.offsetX\" class=\"form-control logistics-size\"> <div class='f-left mr_10'>mm</div>" +
" <div class='f-left'> 高:</div> <input type=\"text\" name=\"account\" ng-model=\"logistics.offset.offsetY\" class=\"form-control logistics-size\"><div class='f-left mr_10'>mm</div>" +
" </div>" +
" <div class='print-logistics-line clearfix'>" +
" <label class='logistics-label'>设置基本参数:</label>"+
" <div class='f-left'>字体大小:</div> <input type=\"text\" name=\"account\" ng-model=\"itemParam.fontSize\" class=\"form-control logistics-sm\" ng-change=\"setFontSize()\"> <div class='f-left mr_10'>px</div>" +
" <div class='f-left'> 字间距:</div> <input type=\"text\" name=\"account\" ng-model=\"itemParam.letterSpacing\" class=\"form-control logistics-sm\" ng-change=\"setLetterSpacing()\"><div class='f-left mr_10'>px</div>" +
" <label class=\"mr_15 xn-label-checkbox\" ng-click=\"itemParam.isBold= !itemParam.isBold\" >"+
" <i class=\"xn-checkbox\"></i>"+
" <i class=\"icon icon-right_3\" ng-if=\"itemParam.isBold\"></i>"+
" 是否加粗"+
" </label>"+
" <label class=\"mr_15 xn-label-checkbox\" ng-click=\"itemParam.isOblique= !itemParam.isOblique\" >"+
" <i class=\"xn-checkbox\"></i>"+
" <i class=\"icon icon-right_3\" ng-if=\"itemParam.isOblique\"></i>"+
" 是否斜体"+
" </label>"+
" </div>" +
" <div class='print-logistics-line clearfix'>" +
" <label class='logistics-label'>选择打印项:</label>" +
" <div class='f-left xn-checkbox-contect'>" +
" <label class=\"mr_15 xn-label-checkbox\" for=\"{{checkbox.key}}{{$index}}\" ng-repeat=\"checkbox in logisticList\" ng-click=\"checkbox.state= !checkbox.state\" >"+
" <i class=\"xn-checkbox\"></i>"+
" <i class=\"icon icon-right_3\" ng-if=\"checkbox.state\"></i>"+
" {{checkbox.value}}"+
" </label>"+
" </div>"+
" </div>" +
" </div>"+
" <div class=\"logistics-box clearfix\" style='width:{{logisticsBox.width}}px;height:{{logisticsBox.height}}px' >"+
" <div class=\"logistics-img clearfix\" >"+
" <img ng-src=\"{{logistics.pictureUrl}}\" width=\"{{logisticsBox.width}}\" height=\"{{logisticsBox.height}}\" " +
" style='width:{{logisticsBox.width}}px;height:{{logisticsBox.height}}px' >"+
" </div>"+
" <div class=\"items-field\" xn-logistic=\"{{logistic.key}}\" ng-style={{logistic.style}} " +
" ng-repeat=\"logistic in logisticList\" ng-show=\"logistic.state\" ng-click=setBaseParam(logistic,$index)" +
" ng-mousedown=\"doDown($event,$index)\" >" +
" <span class=\"title\" ng-style={{logistic.titleStyle}} ng-class=\"{ 'title-Bold':logistic.isBold, 'title-oblique':logistic.isOblique}\">{{logistic.value}}</span>"+
" <span class=\"close-btn\" ng-click=\"logistic.state=false\">X</span>"+
" <div class=\"items-field-r\" ng-mousedown=\"doDownX($event,$index)\" ></div>"+
" <div class=\"items-field-b\" ng-mousedown=\"doDownY($event,$index)\" ></div>"+
" <div class=\"items-field-br\" ng-mousedown=\"doDownXY($event,$index)\" ></div>"+
" </div>"+
" </div>");
}]);
var printLogisticsDynamic=function($modal,$timeout,$filter,LogisticsDirectiveService,dialogService){
return {
restrict: "A",
templateUrl: "xn/template/print/printLogisticsDynamic.html",
scope: {
logistics: '=ngModel',
logisticsOld: '=logisticsOld',
options: '=options',
isEdit:"@isEdit",
printUrl:"@printUrl"
},
replace: true,
require: "?ngModel",
link: function(scope,elem,atter,ngModel) {
scope.logisticsId = "logistics"+new Date().getTime();
if(!scope.printUrl){
dialogService.tip([{"message":"请添加默认运单图片地址!" }]);
return;
}
var logistics=scope.logistics;
scope.logisticList=[];
var zIndex=0;
//设置比例尺
scope.setScale=function(){
scope.logistics.scale=Number(scope.logistics.size.sizeWidth)/Number(scope.logisticsBox.width);
};
//获取承运商
scope.carrierList=[];
LogisticsDirectiveService.getAllListCarrier().success(function(data){
if(data.errors === null || data.errors.length > 0){
dialogService.tip(data.errors);
}else{
scope.carrierList=data.result;
}
});
//模板列表
scope.templateList=[];
scope.templateData={};
var templateData=angular.copy(scope.templateData);
if(scope.isEdit == "true"){
scope.isEdit=true;
}else{
scope.isEdit=false;
//获取模板列表
LogisticsDirectiveService.getAllListPrintTemplate().success(function(data){
if(data.errors === null || data.errors.length > 0){
dialogService.tip(data.errors);
}else{
scope.templateList=data.result;
}
});
}
scope.selectTemplate=function(data) {
var modalInstance = $modal.open({
template:"<div class=\"modal-header\">"+
"<h3 class=\"modal-title\">更换模板</h3>"+
"</div>"+
" <div class=\"modal-body\">确定更换模板?</div>"+
" <div class=\"modal-footer\">" +
" <button class=\"btn btn-primary\" ng-click=\"ok()\">OK</button>"+
" <button class=\"btn btn-warning\" ng-click=\"cancel()\">Cancel</button>" +
"</div>",
controller:["$scope","$modalInstance", function($scope,$modalInstance){
$scope.ok = function () {
$modalInstance.close();
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
}],
size: "sm"
});
modalInstance.result.then(function () {
templateData=angular.copy(scope.templateData);
if(scope.templateData){
//赋值模板
var templateModel={
size:{
sizeWidth:data.sizeWidth,
sizeHeight:data.sizeHeight
},
offset:{
offsetX:data.offsetLeft,
offsetY:data.offsetTop
},
pictureId:data.pictureId,
pictureUrl:data.pictureUrl,
title:data.name,
carrierId:data.carrierId,
scale:"0.17",
items:JSON.parse(data.itemConfig)
};
scope.logistics=angular.copy(templateModel);
}else{
scope.initialize();
}
}, function () {
scope.templateData=angular.copy(templateData);
});
};
//宽度尺寸
scope.logisticsBox={
width:590,
height:1062
};
//初始化
scope.initialize=function(){
scope.logistics={
size:{
sizeWidth:100,
sizeHeight:180
},
offset:{
offsetX:"0",
offsetY:"0"
},
scale:"0.17",
pictureId:"",
pictureUrl:scope.printUrl,
title:"",
carrierId:"",
items:[]
};
angular.extend(scope.logistics,scope.options);
scope.setScale();
scope.setLogisticList();
};
//上传附件
scope.isOpenSingle=false;
scope.upImg=function(){
scope.isOpenSingle=true;
};
scope.logisticsImg={
idList:"",
attachmentList:""
};
scope.$watch("isOpenSingle",function(newdata){
if(!newdata){
if(scope.logisticsImg.idList){
scope.logistics.pictureId=scope.logisticsImg.idList;
scope.logistics.pictureUrl=scope.logisticsImg.attachmentList.path;
}
}
});
scope.size={
width:200,
height:120
};
//数据展示
scope.setLogisticList=function(){
scope.logisticList=scope.logistics.items;
angular.forEach( scope.logisticList,function(logistic,index){
logistic.style={
top:logistic.offsetY+"px",
left:logistic.offsetX+"px",
width:logistic.width+"px",
height:logistic.height+"px",
"z-index":zIndex++
};
/* angular.element("#"+scope.logisticsId+" .items-field").eq(index).css(logistic.style);*/
logistic.titleStyle={
"letter-spacing":logistic.letterSpacing+"px",
"font-size":logistic.fontSize+"px"
};
});
if(scope.logistics.size.sizeWidth){
scope.size.width=scope.logistics.size.sizeWidth;
scope.size.height=scope.logistics.size.sizeHeight;
}else{
//设置宽高
scope.size={
width:200,
height:120
};
}
scope.logisticsBox.height=(Number(scope.size.height)/Number(scope.size.width))*scope.logisticsBox.width;
angular.element("#"+scope.logisticsId+" .logistics-box").css("width", scope.logisticsBox.width+"px");
angular.element("#"+scope.logisticsId+" .logistics-box").css("height", scope.logisticsBox.height+"px");
scope.setScale();
};
scope.$watch("logisticsOld",function(newVal,oldVal){
if(newVal && newVal.items.length){
scope.logistics=angular.copy(scope.logisticsOld);
scope.setLogisticList();
}else{
scope.initialize();
}
});
//监控宽与高
scope.setSizeTip={
state:false,
content:""
};
scope.setSize=function(){
scope.logistics.size.sizeWidth=scope.size.width;
scope.logistics.size.sizeHeight=scope.size.height;
if((Number( scope.size.height)/Number(scope.size.width))>3|| (Number( scope.size.height)/Number(scope.size.width))<0.1){
scope.setSizeTip.state=true;
scope.setSizeTip.content="宽高比应为 0.1 ~ 10 之间";
return;
}else if(Number( scope.size.height)>=1000|| Number(scope.size.width)>1000){
scope.setSizeTip.state=true;
scope.setSizeTip.content="宽和高为1至3位数字";
return;
}
scope.logisticsBox.height=(Number( scope.size.height)/Number(scope.size.width))*scope.logisticsBox.width;
angular.element("#"+scope.logisticsId+" .logistics-box").css("width", scope.logisticsBox.width+"px");
angular.element("#"+scope.logisticsId+" .logistics-box").css("height", scope.logisticsBox.height+"px");
scope.setSizeTip.state=false;
scope.setSizeTip.content="";
//设置比例尺
scope.setScale();
};
//closeSize
scope.closeSize=function(){
scope.setSizeTip.state=false;
scope.setSizeTip.content="";
};
//设置基本参数
scope.itemPaam={};
var listIndex=0;
scope.setBaseParam=function(item,index){
scope.itemParam=item;
listIndex=index;
};
scope.setFontSize=function(){
angular.element(".items-field .title").eq(listIndex).css( "font-size",scope.itemParam.fontSize+"px");
};
scope.setLetterSpacing=function(){
angular.element(".items-field .title").eq(listIndex).css("letter-spacing",scope.itemParam.letterSpacing+"px");
};
//拖动等效果
var isMover=false;
var isMoverX=false;
var isMoverY=false;
var isMoverXY=false;
var xVal=0;
var yVal=0;
var widthVal=100;
var heightVal=24;
var number=0;
var pointVal={};
//拖动
scope.doDown=function(e,index){
if(!(isMoverX || isMoverY ||isMoverXY)){
isMover=true;
}
pointVal=getMousePoint(e);
xVal=pointVal.x-parseInt( angular.element(".items-field").eq(index).css("left"));
yVal=pointVal.y-parseInt(angular.element(".items-field").eq(index).css("top"));
widthVal=parseInt( angular.element(".items-field").eq(index).css("width"));
heightVal=parseInt( angular.element(".items-field").eq(index).css("height"));
number=index;
};
//拖动X轴
scope.doDownX=function(e,index){
if(!isMoverXY){
isMoverX=true;
}
pointVal=getMousePoint(e);
widthVal=parseInt( angular.element(".items-field").eq(index).css("width"));
number=index;
};
//拖动Y轴
scope.doDownY=function(e,index){
if(!isMoverXY){
isMoverY=true;
}
pointVal=getMousePoint(e);
heightVal=parseInt( angular.element(".items-field").eq(index).css("height"));
number=index;
};
//拖动Y轴
scope.doDownXY=function(e,index){
isMoverXY=true;
pointVal=getMousePoint(e);
widthVal=parseInt( angular.element(".items-field").eq(index).css("width"));
heightVal=parseInt( angular.element(".items-field").eq(index).css("height"));
number=index;
};
scope.doMove=function(e){
//整体拖动
if(isMover){
var point=getMousePoint(e);
//最大宽度
var maxWidth= widthVal+(point.x-xVal);
//最小宽度也是实时宽度
var minWidth=point.x-xVal;
if(point.x-xVal>0 && maxWidth< scope.logisticsBox.width){
scope.logisticList[number].offsetX =minWidth; //移动时鼠标位置计算控件左上角的绝对位置
scope.logisticList[number].style.left=minWidth;
angular.element(".items-field").eq(number).css("left", minWidth);
}
//最大高度
var maxHeight= heightVal+(point.y-yVal);
//最小高度也是实时高度
var minHeight=point.y-yVal;
if(minHeight >0 && maxHeight< scope.logisticsBox.height ){
scope.logisticList[number].offsetY=minHeight;
scope.logisticList[number].style.top=minHeight;
angular.element(".items-field").eq(number).css("top",minHeight);
}
}
//整体拖动 X轴
if(isMoverX){
var pointX=getMousePoint(e);
//最大宽度
var maxWidth= widthVal+pointX.x-pointVal.x+Number(scope.logisticList[number].offsetX);
//最小宽度也是实时宽度
var minWidth=widthVal+pointX.x-pointVal.x;
if(minWidth>100 && maxWidth< scope.logisticsBox.width){
scope.logisticList[number].width =minWidth; //移动时鼠标位置计算控件左上角的绝对位置
scope.logisticList[number].style.width =minWidth;
angular.element(".items-field").eq(number).css("width", minWidth);
}
}
//整体拖动 X轴
if(isMoverY){
var pointY=getMousePoint(e);
//最大宽度
var maxHeight = heightVal+pointY.y-pointVal.y+Number(scope.logisticList[number].offsetY);
//最小宽度也是实时宽度
var minHeight=heightVal+pointY.y-pointVal.y;
if(minHeight>24 && maxHeight< scope.logisticsBox.height){
scope.logisticList[number].height =minHeight; //移动时鼠标位置计算控件左上角的绝对位置
scope.logisticList[number].style.height =minHeight; //移动时鼠标位置计算控件左上角的绝对位置
angular.element(".items-field").eq(number).css("height", minHeight);
}
}
//整体拖动 XY轴
if(isMoverXY){
var pointXY=getMousePoint(e);
//最大宽度
var maxWidth= widthVal+pointXY.x-pointVal.x+Number(scope.logisticList[number].offsetX);
//最小宽度也是实时宽度
var minWidth=widthVal+pointXY.x-pointVal.x;
if(minWidth>100 && maxWidth< scope.logisticsBox.width){
scope.logisticList[number].width =minWidth; //移动时鼠标位置计算控件左上角的绝对位置
scope.logisticList[number].style.width =minWidth; //移动时鼠标位置计算控件左上角的绝对位置
angular.element(".items-field").eq(number).css("width",minWidth);
}
//最大宽度
var maxHeight = heightVal+pointXY.y-pointVal.y+Number(scope.logisticList[number].offsetY);
//最小宽度也是实时宽度
var minHeight=heightVal+pointXY.y-pointVal.y;
if(minHeight>24 && maxHeight< scope.logisticsBox.height){
scope.logisticList[number].height =minHeight; //移动时鼠标位置计算控件左上角的绝对位置
scope.logisticList[number].style.height =minHeight; //移动时鼠标位置计算控件左上角的绝对位置
angular.element(".items-field").eq(number).css("height", minHeight);
}
}
};
scope.doUp=function() {
isMover=false;
isMoverX=false;
isMoverY=false;
isMoverXY=false;
};
function getMousePoint(ev) {
// 定义鼠标在视窗中的位置
var point = {
x:0,
y:0
};
// 如果浏览器支持 pageYOffset, 通过 pageXOffset 和 pageYOffset 获取页面和视窗之间的距离
if(typeof window.pageYOffset != 'undefined') {
point.x = window.pageXOffset;
point.y = window.pageYOffset;
}
// 如果浏览器支持 compatMode, 并且指定了 DOCTYPE, 通过 documentElement 获取滚动距离作为页面和视窗间的距离
// IE 中, 当页面指定 DOCTYPE, compatMode 的值是 CSS1Compat, 否则 compatMode 的值是 BackCompat
else if(typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
point.x = document.documentElement.scrollLeft;
point.y = document.documentElement.scrollTop;
}
// 如果浏览器支持 document.body, 可以通过 document.body 来获取滚动高度
else if(typeof document.body != 'undefined') {
point.x = document.body.scrollLeft;
point.y = document.body.scrollTop;
}
// 加上鼠标在视窗中的位置
point.x += ev.clientX;
point.y += ev.clientY;
// 返回鼠标在视窗中的位置
return point;
}
}
}
};
angular.module("xn.directive.prints",["ng","xn/template/print.html"])
.factory('LogisticsDirectiveService', ['$http', function ($http) {
var service = {};
var url = "/transpation/api.do";
service.getAllListCarrier = function (data) {
return $http({
method: 'POST',
url: url,
data: data,
params: {"method": "api.transpation.carrier.getalllist"} });
};
service.getAllListPrintTemplate = function (data) {
return $http({
method: 'POST',
url: url,
data: data,
params: {"method": "api.transpation.printtemplate.getalllist"} });
};
return service;
}])
.directive('printLogisticsDynamic', ["$modal","$timeout","$filter","LogisticsDirectiveService","dialogService", printLogisticsDynamic]);