Commit e8b9d858 authored by pengguangpu's avatar pengguangpu

联调打印;主流程联调;

parent abaa943c
......@@ -11,9 +11,9 @@ App({
appId: "2021001107603212",
//小程序容器版本
containerVersionCode: null,
localAccountInfo:null,
localAccountInfo: null,
//模拟器上需要sn有值
sn:"xx"
sn: "xx"
},
onLaunch(options) {
......@@ -30,20 +30,85 @@ App({
}
});
//添加后屏小程序
my.ix.addExtensionApp({
appId: "2021001107617164",
// 填入后屏小程序的 AppID
type: "screen",
success: (res) => {
console.log("addExtensionApp success:", res)
},
fail: (res) => {
console.log("addExtensionApp fail:", res)
},
})
// my.ix.addExtensionApp({
// appId: "2021001107617164",
// // 填入后屏小程序的 AppID
// type: "screen",
// success: (res) => {
// console.log("addExtensionApp success:", res)
// },
// fail: (res) => {
// console.log("addExtensionApp fail:", res)
// },
// })
},
onShow(options) {
// 从后台被 scheme 重新打开
// options.query == {number:1}
//开启打印机状态检测
my.ix.startMonitorPrinter({
success: (res1) => {
console.log("startMonitorPrinter success==>" + JSON.stringify(res1));
//查询打印机一下
my.ix.queryPrinter({
success: (res) => {
console.log("查询打印机成功:" + JSON.stringify(res));
//如果回调中的设备数为0,则重置打印机id为null,打印机名称为null
if (res.usb != null && res.usb.length != 0) {
getApp().globalData.printerId = res.usb[0].id;
getApp().globalData.printerName = res.usb[0].name;
} else {
getApp().globalData.printerId = null;
getApp().globalData.printerName = null;
}
},
fail: (res) => {
console.log("查询打印机失败:" + JSON.stringify(res));
getApp().globalData.printerId = null;
getApp().globalData.printerName = null;
}
});
//开启打印机状态检测
my.ix.onMonitorPrinter({
success: (res) => {
console.log("onMonitorPrinter success data:" + JSON.stringify(res));
//如果回调中的设备数为0,则重置打印机id为null,打印机名称为null
if (res.usb != null && res.usb.length != 0) {
getApp().globalData.printerId = res.usb[0].id;
getApp().globalData.printerName = res.usb[0].name;
} else {
getApp().globalData.printerId = null;
getApp().globalData.printerName = null;
}
},
fail: (res) => {
console.log("onMonitorPrinter fail data:" + JSON.stringify(res));
}
});
},
fail: (res) => {
console.log("startMonitorPrinter fail==>" + JSON.stringify(res));
//即使开启检测失败也查询一次
//查询打印机一下
my.ix.queryPrinter({
success: (res) => {
console.log("查询打印机成功:" + JSON.stringify(res));
//如果回调中的设备数为0,则重置打印机id为null,打印机名称为null
if (res.usb != null && res.usb.length != 0) {
getApp().globalData.printerId = res.usb[0].id;
getApp().globalData.printerName = res.usb[0].name;
} else {
getApp().globalData.printerId = null;
getApp().globalData.printerName = null;
}
},
fail: (res) => {
console.log("查询打印机失败:" + JSON.stringify(res));
getApp().globalData.printerId = null;
getApp().globalData.printerName = null;
}
});
}
});
},
});
......@@ -3,14 +3,14 @@ var payUtils = require("../../utils/payUtils.js");
Page({
data: {
goodsNum:0,
payPrice:0.00,
totalPrice:0.00,
couponPrice:0.00,
qrPayShow:false,
list:[],
orderNo:"",
isCashierClosed:false,
goodsNum: 0,
payPrice: 0.00,
totalPrice: 0.00,
couponPrice: 0.00,
qrPayShow: false,
list: [],
orderNo: "",
isCashierClosed: false,
isPaying: false,
},
onLoad(options) {
......@@ -32,25 +32,25 @@ Page({
})
}
//商品数据
let context = this;
my.getStorage({
key: 'goods',
success: function (res) {
console.log("商品信息 ===》 " + JSON.stringify(res));
context.setData({
list:res.data
})
},
fail: function (res) {
console.log("商品信息 ===》 " + JSON.stringify(res));
}
});
//商品数据
let context = this;
my.getStorage({
key: 'goods',
success: function (res) {
console.log("商品信息 ===》 " + JSON.stringify(res));
context.setData({
list: res.data
})
},
fail: function (res) {
console.log("商品信息 ===》 " + JSON.stringify(res));
}
});
},
/**
......@@ -73,20 +73,20 @@ Page({
* @todo 支付结果的获取
* @todo 跳转数据的保存
*/
startPay(){
startPay() {
//开始loading
my.showLoading({});
//获取order
payUtils.getOrder(/*this.data.payPrice*/1,this.data.list, function(res){
if(res != null){
payUtils.getOrder(/*this.data.payPrice*/1, this.data.list, function (res) {
if (res != null) {
console.log("callback调用,res=" + JSON.stringify(res));
if(res.resultCode ==1){
if (res.resultCode == 1) {
this.setData({
orderNo:res.data
orderNo: res.data
});
this.payWithOpenCashier(res.data);
this.payWithOpenCashier(res.data);
}
}
}.bind(this));
......@@ -95,34 +95,34 @@ Page({
//调用收款接口
doPay(orderNo, payCode) {
console.log("doPay调用"+orderNo);
this.setData({isPaying:true});
console.log("doPay调用" + orderNo);
this.setData({ isPaying: true });
//使用barCode来当面付
payUtils.startPay(orderNo, payCode, 1, this.data.list, function(res){
payUtils.startPay(orderNo, payCode, 1, this.data.list, function (res) {
my.hideLoading();
console.log("支付回调 ===>" + JSON.stringify(res));
this.setData({isPaying:false});
if(res == null){
this.setData({ isPaying: false });
if (res == null) {
return;
}
if(res.resultCode == 1){
if (res.resultCode == 1) {
//成功
console.log("支付回调成功,跳转 " );
console.log("支付回调成功,跳转 ");
// if(data.isCashierClosed == true){
this.saveData(this.data.list, res);
my.ix.offCashierEventReceive();
my.redirectTo({
url: '/pages/paysuccess/paysuccess?orderPrice=' + this.data.totalPrice + "&couponPrice=" + this.data.couponPrice + "&payPrice=" + this.data.payPrice+"&totalCount="+this.data.totalCount,
});
this.saveData(this.data.list, res.data);
my.ix.offCashierEventReceive();
my.redirectTo({
url: '/pages/paysuccess/paysuccess?totalGoodsNum='+this.data.goodsNum+'&orderPrice=' + this.data.totalPrice + "&couponPrice=" + this.data.couponPrice + "&payPrice=" + this.data.payPrice + "&totalCount=" + this.data.totalCount,
});
// }
}else{
console.log("支付回调失败 ===》 "+res.message);
} else {
console.log("支付回调失败 ===》 " + res.message);
my.ix.offCashierEventReceive();
my.showToast({
type: 'fail',
content: res.message,
duration: 2000
type: 'fail',
content: res.message,
duration: 2000
});
}
}.bind(this));
......@@ -131,10 +131,10 @@ Page({
/**
* 打开收银台,进行扫码收款
*/
payWithOpenCashier(){
try{
payWithOpenCashier() {
try {
console.info("收银台版本" + my.ix.getVersionSync({
packageName: 'zoloz.phone.android.alipay.com.dragonfly'
packageName: 'zoloz.phone.android.alipay.com.dragonfly'
}).versionName);
//开启收银台监听
......@@ -150,7 +150,7 @@ Page({
this.data.isCashierClosed = true;
this.doPay(this.data.orderNo, res.barCode);
}
},fail:(res) => {
}, fail: (res) => {
my.showToast({
type: 'exception',
content: api.decodeErrorMessage(res.error),
......@@ -171,7 +171,7 @@ Page({
//如果正在支付中,则等待支付结果返回
} else {
//跳转支付结果页面,说明支付已完成,无论取消支付还是支付成功等都跳转支付结果页
// if (this.data.actualPayPriceYuan != null) {
// my.redirectTo({
// //payPrice和couponPrice需要考虑支付宝优惠
......@@ -191,10 +191,10 @@ Page({
else
console.log('RESULT: ' + res.bizType);
});
} catch(err) {
} catch (err) {
console.log("收银台启动回调 异常==>" + JSON.stringify(err));
}
},
/**
......@@ -212,6 +212,6 @@ Page({
data: paySuccessResponse
});
},
});
......@@ -135,6 +135,7 @@ Page({
});
//登陆信息设置到全局变量
getApp().globalData.localAccountInfo = res.data;
console.info(`localAccountInfo: ${JSON.stringify(getApp().globalData.localAccountInfo)}`);
//todo 临时跳转到扫商品页面 跳转广告页
my.reLaunch({
url: "/pages/home/home"
......
......@@ -25,7 +25,9 @@
</view>
</view>
<view class="printLoading">
<i-spin hidden="{{!isShowPrinting}}"></i-spin>
<view hidden="{{!isShowPrinting}}">
<i-spin></i-spin>
</view>
<view style="position:absolute;width:100%;height:100%;left:0rpx;top:0rpx;color:#000000;font-weight:bold;">
<view style="display: absolute;margin:0 auto;align-content: center;align-items: center;text-align:center;line-height:186rpx;">
<text>{{printerStatus}}</text>
......
......@@ -21,13 +21,15 @@ Page({
onLoad(query) {
console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
//从本地获取相关数据
this.data.goodsList.push(my.getStorageSync({ key: 'paySuccessGoodsList' }).data);
this.data.goodsList = my.getStorageSync({ key: 'paySuccessGoodsList' }).data;
console.info(`paySuccessGoodsList: ${JSON.stringify(this.data.goodsList)}`);
this.data.paySuccessResponse = my.getStorageSync({ key: 'paySuccessResponse' }).data;
console.info(`paySuccessResponse: ${JSON.stringify(this.data.paySuccessResponse)}`);
//单位转换&赋值
this.data.orderPriceFen = this.data.paySuccessResponse.tradeAmount;
this.data.couponPriceFen = this.data.paySuccessResponse.mdiscount + this.data.paySuccessResponse.discount;
this.data.payPriceFen = this.data.paySuccessResponse.tradeAmount - (this.data.paySuccessResponse.mdiscount + this.data.paySuccessResponse.discount);
this.data.totalCount = query.totalCount;
this.data.totalCount = query.totalGoodsNum;
var miyapay = require("../../utils/miyapay4.js");
this.data.orderPriceYuan = miyapay.fen2Yuan(this.data.orderPriceFen);
......@@ -40,6 +42,8 @@ Page({
} else if (this.data.paySuccessResponse.channel == 3) {
this.data.payChannel = "支付宝";
}
this.print();
},
print() {
......@@ -49,11 +53,11 @@ Page({
var cmds = [
printer.setAlign(printer.ALIGN_CENTER),
printer.printText(getApp().globalData.localAccountInfo.storeName),
printer.printDivide("-"),
printer.setAlign(printer.ALIGN_LEFT),
printer.printText("门店号:" + this.paySuccessResponse.storeId),
printer.printText("收银员账号:" + this.paySuccessResponse.operatorId),
printer.printText("订单号:" + this.paySuccessResponse.tradeNo),
printer.printDivide("-"),
printer.printText("门店号:" + this.data.paySuccessResponse.storeId),
printer.printText("收银员账号:" + this.data.paySuccessResponse.operatorId),
printer.printText("订单号:" + this.data.paySuccessResponse.tradeNo),
printer.printNowDate(),
printer.printDivide("-"),
printer.printText("活动商品"),
......@@ -62,15 +66,13 @@ Page({
for (var i = 0; i < this.data.goodsList.length; i++) {
//循环取出商品数据
cmds.push(printer.setAlign(printer.ALIGN_LEFT));
cmds.push(printer.printText(goodsList[i].goodsName));
cmds.push(printer.printText(goodsList[i].barcode));
cmds.push(printer.setAlign(printer.ALIGN_RIGHT));
cmds.push(printer.printText(goodsList[i].goodsCount));
cmds.push(printer.printText(this.data.goodsList[i].name));
cmds.push(printer.printTwoText(this.data.goodsList[i].barcode,this.data.goodsList[i].quantity+""));
}
cmds.push(printer.setAlign(printer.ALIGN_LEFT));
cmds.push(printer.printDivide("-"));
cmds.push(printer.printText("应收金额:" + this.data.orderPriceYuan));
cmds.push(printer.printText("支付方式实付:" + this.data.payPriceYuan));
cmds.push(printer.printText(this.data.payChannel + ":" + this.data.payPriceYuan));
for (var i = 0; i < 4; i++) {
cmds.push(printer.feedPaper());
}
......
......@@ -115,6 +115,20 @@ function printText(text) {
return { 'cmd': 'addText', 'args': ['' + text + "\n"] };
}
/**
* 一行打印两文字
*/
function printTwoText(leftText, rightText) {
console.info(`leftText: ${JSON.stringify(leftText)}` + ";rightText:" + JSON.stringify(rightText));
var text = leftText;
for (var i = 0; i < 38 - rightText.length - leftText.length; i++) {
text = text + " ";
}
text = text + rightText;
console.info(`text: ${JSON.stringify(text)}`);
return { 'cmd': 'addText', 'args': ['' + text + "\n"] };
}
/**
* 打印分割线
*/
......@@ -166,4 +180,5 @@ module.exports.setAlign = setAlign;
module.exports.feedPaper = feedPaper;
module.exports.printText = printText;
module.exports.printDivide = printDivide;
module.exports.printNowDate = printNowDate;
\ No newline at end of file
module.exports.printNowDate = printNowDate;
module.exports.printTwoText = printTwoText;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment