import { CCPrintingAPI } from '../../js/CCPrintingAPI.min.vue.js'
GetPrinters: function () {
var cfgData = new Object;
cfgData.XAction = "Printers";
CCPrintingAPI.Excute(cfgData,
XTimeout => { },
XFail => {
this.mytipsmessage = 'API可能未安装或未启动, ' + 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);
}
/*设置上次使用的打印机*/
this.selected = this.options[0].value;
}
}
}
);
}
Print: function () {
var cfgPrintSettings = new Object;
cfgPrintSettings.XAction = "Print"
/*指定打印机*/
cfgPrintSettings.PrinterName = this.selected;
/*模板方式,0-客户端模板,1-远程模板,
2-如果本地模板存在,使用本地,不存在使用远程模板,3-不使用模板*/
cfgPrintSettings.TemplateMode = "1";
/*远程模板URL或本地模板的文件夹*/
cfgPrintSettings.TemplateURL = "http://img.51321.cn/web/chicore/VPrinting/API";
//cfgPrintSettings.TemplateURL = "E:\\临时数据\\打印\\打印样本\\API标签模板";
/*模板文件名*/
cfgPrintSettings.TemplateName = "183601-70X40.Lblx";
/*打印数据的类型,0-数组,1-Json数组,元素为JSON对象,字段:值*/
cfgPrintSettings.PrintDataType = 1;
/*传递打印数据 Json数组*/ /*内容不允许 半角的逗号及半角的分隔符*/
var arr = [
{ sku: 'OBJ100001', name: '测试1', kw: 'D12-1', bh: 'RKD123451' },
{ sku: 'OBJ100002', name: '测试2', kw: 'D12-2', bh: 'RKD123452' },
{ sku: 'OBJ100003', name: '测试3', kw: 'D12-3', bh: 'RKD123453' },
];
cfgPrintSettings.PrintData = JSON.stringify(arr);
/*打印 发送给打印机进行打印*/
CCPrintingAPI.Excute(cfgPrintSettings,
XTimeout => { },
XFail => {
this.mytipsmessage = 'API可能未安装或未启动, ' + 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;
}
}
);
}
GetHID: function () {
var cfgData = new Object;
cfgData.XAction = 'HID';
CCPrintingAPI.Excute(cfgData,
XTimeout => { },
XFail => {
this.mytipsmessage = 'API可能未安装或未启动, ' + 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.myhid = smsg;
}
}
);
}