import { CCPrintingAPI } from 'static/js/CCPrintingAPI.min.vue.js'
GetPrinters: function () {
var cfgData = new Object;
cfgData.XAction = "Printers";
cfgData.XOpenId = m_OpenId;
cfgData.XTokens = m_Tokens;
CCPrintingAPI.Excute(cfgData,
XTimeout => { },
XFail => {
this.mytipsmessage = 'API可(kě)能未安裝或未啓動, ' + XFail;
},
XSuccess => {
var d = new Date;
this.timetick = d.getTime();
var apiResult = JSON.parse(XSuccess.trim());
if (apiResult.Status == "1") {
if (apiResult.Message.length > 1) {
this.options = [];
for (var i = 1; i < apiResult.Message.length; i++) {
var op = new Object;
op.text = apiResult.Message[i];
op.value = apiResult.Message[i];
this.options.push(op);
}
/*設置上(shàng)次使用的打印機*/
this.selected = this.options[0].value;
}
} else {
if (apiResult.Message.length > 1)
this.mytipsmessage = apiResult.Message[0] + " : " + apiResult.Message[1];
else
this.mytipsmessage = apiResult.Message[0];
}
}
);
}
GetSelfDraw:function(){
var selfdraw = {
"Text":
[
{
"Name" : "Text1" ,
"LabelType" : "1" ,
"X" : "9.525" ,
"Y" : "2.1167" ,
"Width" : "30.9562" ,
"Height" : "6.0854" ,
"Data" : "庫位編碼" ,
"IsBind" : "0" ,
"BindField" : "" ,
"FontName" : "黑(hēi)體(tǐ)" ,
"FontSize" : "9" ,
"FontStyle" : "1" ,
"RotateOrientation" : "0" ,
"HAlignment" : "1" ,
"VAlignment" : "1" ,
"ForeColor" : "Black" ,
"BackColor" : "Transparent" ,
"Visible" : "1"
},
{
"Name" : "Text3" ,
"LabelType" : "1" ,
"X" : "5.0271" ,
"Y" : "21.9604" ,
"Width" : "40.2167" ,
"Height" : "4.4979" ,
"Data" : "智高(gāo)軟件 服務智能制(zhì)造" ,
"IsBind" : "0" ,
"BindField" : "" ,
"FontName" : "黑(hēi)體(tǐ)" ,
"FontSize" : "7" ,
"FontStyle" : "1" ,
"RotateOrientation" : "0" ,
"HAlignment" : "1" ,
"VAlignment" : "1" ,
"ForeColor" : "Black" ,
"BackColor" : "Transparent" ,
"Visible" : "1"
},
{
"Name" : "Text4" ,
"LabelType" : "1" ,
"X" : "10.0542" ,
"Y" : "18.5208" ,
"Width" : "20.6375" ,
"Height" : "4.4979" ,
"Data" : "庫位編碼" ,
"IsBind" : "1" ,
"BindField" : "Field1" ,
"FontName" : "黑(hēi)體(tǐ)" ,
"FontSize" : "7" ,
"FontStyle" : "1" ,
"RotateOrientation" : "0" ,
"TextStyle" : "0" ,
"AutoFontSize" : "0" ,
"HAlignment" : "0" ,
"VAlignment" : "1" ,
"ForeColor" : "Black" ,
"BackColor" : "Transparent" ,
"Visible" : "1"
}
],
"Barcode":
[
{
"Name" : "Barcode1" ,
"LabelType" : "1" ,
"X" : "30.6917" ,
"Y" : "8.4667" ,
"Width" : "12.9646" ,
"Height" : "13.2292" ,
"Data" : "1234567890" ,
"IsBind" : "1" ,
"BindField" : "Field1" ,
"BarcodeType" : "qr" ,
"Code128CodeSet" : "3" ,
"CheckDigit" : "1" ,
"CheckDigitToText" : "1" ,
"Charset" : "3" ,
"FontName" : "Arial" ,
"FontSize" : "9" ,
"FontStyle" : "0" ,
"RotateOrientation" : "1" ,
"Alignment" : "0" ,
"CodeTextSpace" : "0" ,
"ShowText" : "1" ,
"ForeColor" : "Black" ,
"BackColor" : "Transparent" ,
"Visible" : "1"
},
{
"Name" : "Barcode2" ,
"LabelType" : "1" ,
"X" : "10.0542" ,
"Y" : "9.2604" ,
"Width" : "8.4667" ,
"Height" : "10.5833" ,
"Data" : "1234567890" ,
"IsBind" : "1" ,
"BindField" : "Field1" ,
"BarcodeType" : "datamatrix" ,
"Code128CodeSet" : "3" ,
"CheckDigit" : "1" ,
"CheckDigitToText" : "1" ,
"Charset" : "3" ,
"FontName" : "Arial" ,
"FontSize" : "9" ,
"FontStyle" : "0" ,
"RotateOrientation" : "0" ,
"Alignment" : "0" ,
"CodeTextSpace" : "0" ,
"ShowText" : "1" ,
"ForeColor" : "Black" ,
"BackColor" : "Transparent" ,
"Visible" : "1"
}
],
"PageSettings":
{
"Width" : "52" ,
"Height" : "30" ,
"TopMargin" : "0" ,
"BottomMargin" : "0" ,
"LeftMargin" : "1" ,
"RightMargin" : "0" ,
"PrinterPaperAutoSet" : "1" ,
"UseQuickSetTool" : "1" ,
"Landscape" : "0"
},
"LabelDetail":
{
"Width" : "50" ,
"Height" : "30" ,
"RowSpan" : "2" ,
"ColumnSpan" : "2" ,
"Visible" : "1"
},
"DataBase":
{
"FieldNumbers" : "15" ,
"FieldNames":
[
]
}
};
return JSON.stringify(selfdraw);
}
Print: function () {
var cfgData = new Object;
cfgData.XAction = "Print"
cfgData.XOpenId = m_OpenId;
cfgData.XTokens = m_Tokens;
/*指定打印機*/
cfgData.PrinterName = this.selected;
/*模闆方式,0-客戶端模闆,1-遠程模闆,
2-如果本地模闆存在,使用本地,不存在使用遠程模闆,3-不使用模闆*/
cfgData.TemplateMode = "3";
cfgData.SelfDraw = this.GetSelfDraw();
/*打印數(shù)據的類型,0-數(shù)組,1-Json數(shù)組,元素為(wèi)JSON對象,字段:值*/
cfgData.PrintDataType = 1;
/*傳遞打印數(shù)據 Json數(shù)組*/ /*內(nèi)容不允許 半角的逗号及半角的分隔符*/
var arr = [
{ Field1: '5002468301572'}, { Field1: '5002468301573'}
];
cfgData.PrintData = JSON.stringify(arr);
/*打印 發送給打印機進行(xíng)打印*/
CCPrintingAPI.Excute(cfgData,
XTimeout => { },
XFail => {
this.mytipsmessage = 'API可(kě)能未安裝或未啓動, ' + XFail;
},
XSuccess => {
var d = new Date;
this.timetick = d.getTime();
var apiResult = JSON.parse(XSuccess.trim());
if (apiResult.Status == "1") {
var smsg = apiResult.Message[0];
if (apiResult.Message.length > 1)
smsg += " : " + apiResult.Message[1]
this.mytipsmessage = smsg;
} else {
if (apiResult.Message.length > 1)
this.mytipsmessage = apiResult.Message[0] + " : " + apiResult.Message[1];
else
this.mytipsmessage = apiResult.Message[0];
}
}
);
}