Commit e8b9d858 authored by pengguangpu's avatar pengguangpu

联调打印;主流程联调;

parent abaa943c
...@@ -11,9 +11,9 @@ App({ ...@@ -11,9 +11,9 @@ App({
appId: "2021001107603212", appId: "2021001107603212",
//小程序容器版本 //小程序容器版本
containerVersionCode: null, containerVersionCode: null,
localAccountInfo:null, localAccountInfo: null,
//模拟器上需要sn有值 //模拟器上需要sn有值
sn:"xx" sn: "xx"
}, },
onLaunch(options) { onLaunch(options) {
...@@ -30,20 +30,85 @@ App({ ...@@ -30,20 +30,85 @@ App({
} }
}); });
//添加后屏小程序 //添加后屏小程序
my.ix.addExtensionApp({ // my.ix.addExtensionApp({
appId: "2021001107617164", // appId: "2021001107617164",
// 填入后屏小程序的 AppID // // 填入后屏小程序的 AppID
type: "screen", // 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) => { success: (res) => {
console.log("addExtensionApp 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) => { fail: (res) => {
console.log("addExtensionApp 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;
}
}, },
onShow(options) { fail: (res) => {
// 从后台被 scheme 重新打开 console.log("查询打印机失败:" + JSON.stringify(res));
// options.query == {number:1} getApp().globalData.printerId = null;
getApp().globalData.printerName = null;
}
});
}
});
}, },
}); });
...@@ -3,14 +3,14 @@ var payUtils = require("../../utils/payUtils.js"); ...@@ -3,14 +3,14 @@ var payUtils = require("../../utils/payUtils.js");
Page({ Page({
data: { data: {
goodsNum:0, goodsNum: 0,
payPrice:0.00, payPrice: 0.00,
totalPrice:0.00, totalPrice: 0.00,
couponPrice:0.00, couponPrice: 0.00,
qrPayShow:false, qrPayShow: false,
list:[], list: [],
orderNo:"", orderNo: "",
isCashierClosed:false, isCashierClosed: false,
isPaying: false, isPaying: false,
}, },
onLoad(options) { onLoad(options) {
...@@ -39,7 +39,7 @@ Page({ ...@@ -39,7 +39,7 @@ Page({
success: function (res) { success: function (res) {
console.log("商品信息 ===》 " + JSON.stringify(res)); console.log("商品信息 ===》 " + JSON.stringify(res));
context.setData({ context.setData({
list:res.data list: res.data
}) })
}, },
fail: function (res) { fail: function (res) {
...@@ -73,18 +73,18 @@ Page({ ...@@ -73,18 +73,18 @@ Page({
* @todo 支付结果的获取 * @todo 支付结果的获取
* @todo 跳转数据的保存 * @todo 跳转数据的保存
*/ */
startPay(){ startPay() {
//开始loading //开始loading
my.showLoading({}); my.showLoading({});
//获取order //获取order
payUtils.getOrder(/*this.data.payPrice*/1,this.data.list, function(res){ payUtils.getOrder(/*this.data.payPrice*/1, this.data.list, function (res) {
if(res != null){ if (res != null) {
console.log("callback调用,res=" + JSON.stringify(res)); console.log("callback调用,res=" + JSON.stringify(res));
if(res.resultCode ==1){ if (res.resultCode == 1) {
this.setData({ this.setData({
orderNo:res.data orderNo: res.data
}); });
this.payWithOpenCashier(res.data); this.payWithOpenCashier(res.data);
} }
...@@ -95,29 +95,29 @@ Page({ ...@@ -95,29 +95,29 @@ Page({
//调用收款接口 //调用收款接口
doPay(orderNo, payCode) { doPay(orderNo, payCode) {
console.log("doPay调用"+orderNo); console.log("doPay调用" + orderNo);
this.setData({isPaying:true}); this.setData({ isPaying: true });
//使用barCode来当面付 //使用barCode来当面付
payUtils.startPay(orderNo, payCode, 1, this.data.list, function(res){ payUtils.startPay(orderNo, payCode, 1, this.data.list, function (res) {
my.hideLoading(); my.hideLoading();
console.log("支付回调 ===>" + JSON.stringify(res)); console.log("支付回调 ===>" + JSON.stringify(res));
this.setData({isPaying:false}); this.setData({ isPaying: false });
if(res == null){ if (res == null) {
return; return;
} }
if(res.resultCode == 1){ if (res.resultCode == 1) {
//成功 //成功
console.log("支付回调成功,跳转 " ); console.log("支付回调成功,跳转 ");
// if(data.isCashierClosed == true){ // if(data.isCashierClosed == true){
this.saveData(this.data.list, res); this.saveData(this.data.list, res.data);
my.ix.offCashierEventReceive(); my.ix.offCashierEventReceive();
my.redirectTo({ my.redirectTo({
url: '/pages/paysuccess/paysuccess?orderPrice=' + this.data.totalPrice + "&couponPrice=" + this.data.couponPrice + "&payPrice=" + this.data.payPrice+"&totalCount="+this.data.totalCount, 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{ } else {
console.log("支付回调失败 ===》 "+res.message); console.log("支付回调失败 ===》 " + res.message);
my.ix.offCashierEventReceive(); my.ix.offCashierEventReceive();
my.showToast({ my.showToast({
type: 'fail', type: 'fail',
...@@ -131,8 +131,8 @@ Page({ ...@@ -131,8 +131,8 @@ Page({
/** /**
* 打开收银台,进行扫码收款 * 打开收银台,进行扫码收款
*/ */
payWithOpenCashier(){ payWithOpenCashier() {
try{ try {
console.info("收银台版本" + my.ix.getVersionSync({ console.info("收银台版本" + my.ix.getVersionSync({
packageName: 'zoloz.phone.android.alipay.com.dragonfly' packageName: 'zoloz.phone.android.alipay.com.dragonfly'
}).versionName); }).versionName);
...@@ -150,7 +150,7 @@ Page({ ...@@ -150,7 +150,7 @@ Page({
this.data.isCashierClosed = true; this.data.isCashierClosed = true;
this.doPay(this.data.orderNo, res.barCode); this.doPay(this.data.orderNo, res.barCode);
} }
},fail:(res) => { }, fail: (res) => {
my.showToast({ my.showToast({
type: 'exception', type: 'exception',
content: api.decodeErrorMessage(res.error), content: api.decodeErrorMessage(res.error),
...@@ -191,7 +191,7 @@ Page({ ...@@ -191,7 +191,7 @@ Page({
else else
console.log('RESULT: ' + res.bizType); console.log('RESULT: ' + res.bizType);
}); });
} catch(err) { } catch (err) {
console.log("收银台启动回调 异常==>" + JSON.stringify(err)); console.log("收银台启动回调 异常==>" + JSON.stringify(err));
} }
......
...@@ -135,6 +135,7 @@ Page({ ...@@ -135,6 +135,7 @@ Page({
}); });
//登陆信息设置到全局变量 //登陆信息设置到全局变量
getApp().globalData.localAccountInfo = res.data; getApp().globalData.localAccountInfo = res.data;
console.info(`localAccountInfo: ${JSON.stringify(getApp().globalData.localAccountInfo)}`);
//todo 临时跳转到扫商品页面 跳转广告页 //todo 临时跳转到扫商品页面 跳转广告页
my.reLaunch({ my.reLaunch({
url: "/pages/home/home" url: "/pages/home/home"
......
...@@ -25,7 +25,9 @@ ...@@ -25,7 +25,9 @@
</view> </view>
</view> </view>
<view class="printLoading"> <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="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;"> <view style="display: absolute;margin:0 auto;align-content: center;align-items: center;text-align:center;line-height:186rpx;">
<text>{{printerStatus}}</text> <text>{{printerStatus}}</text>
......
...@@ -21,13 +21,15 @@ Page({ ...@@ -21,13 +21,15 @@ Page({
onLoad(query) { onLoad(query) {
console.info(`Page onLoad with query: ${JSON.stringify(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; 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.orderPriceFen = this.data.paySuccessResponse.tradeAmount;
this.data.couponPriceFen = this.data.paySuccessResponse.mdiscount + this.data.paySuccessResponse.discount; 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.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"); var miyapay = require("../../utils/miyapay4.js");
this.data.orderPriceYuan = miyapay.fen2Yuan(this.data.orderPriceFen); this.data.orderPriceYuan = miyapay.fen2Yuan(this.data.orderPriceFen);
...@@ -40,6 +42,8 @@ Page({ ...@@ -40,6 +42,8 @@ Page({
} else if (this.data.paySuccessResponse.channel == 3) { } else if (this.data.paySuccessResponse.channel == 3) {
this.data.payChannel = "支付宝"; this.data.payChannel = "支付宝";
} }
this.print();
}, },
print() { print() {
...@@ -49,11 +53,11 @@ Page({ ...@@ -49,11 +53,11 @@ Page({
var cmds = [ var cmds = [
printer.setAlign(printer.ALIGN_CENTER), printer.setAlign(printer.ALIGN_CENTER),
printer.printText(getApp().globalData.localAccountInfo.storeName), printer.printText(getApp().globalData.localAccountInfo.storeName),
printer.printDivide("-"),
printer.setAlign(printer.ALIGN_LEFT), printer.setAlign(printer.ALIGN_LEFT),
printer.printText("门店号:" + this.paySuccessResponse.storeId), printer.printDivide("-"),
printer.printText("收银员账号:" + this.paySuccessResponse.operatorId), printer.printText("门店号:" + this.data.paySuccessResponse.storeId),
printer.printText("订单号:" + this.paySuccessResponse.tradeNo), printer.printText("收银员账号:" + this.data.paySuccessResponse.operatorId),
printer.printText("订单号:" + this.data.paySuccessResponse.tradeNo),
printer.printNowDate(), printer.printNowDate(),
printer.printDivide("-"), printer.printDivide("-"),
printer.printText("活动商品"), printer.printText("活动商品"),
...@@ -62,15 +66,13 @@ Page({ ...@@ -62,15 +66,13 @@ Page({
for (var i = 0; i < this.data.goodsList.length; i++) { for (var i = 0; i < this.data.goodsList.length; i++) {
//循环取出商品数据 //循环取出商品数据
cmds.push(printer.setAlign(printer.ALIGN_LEFT)); cmds.push(printer.setAlign(printer.ALIGN_LEFT));
cmds.push(printer.printText(goodsList[i].goodsName)); cmds.push(printer.printText(this.data.goodsList[i].name));
cmds.push(printer.printText(goodsList[i].barcode)); cmds.push(printer.printTwoText(this.data.goodsList[i].barcode,this.data.goodsList[i].quantity+""));
cmds.push(printer.setAlign(printer.ALIGN_RIGHT));
cmds.push(printer.printText(goodsList[i].goodsCount));
} }
cmds.push(printer.setAlign(printer.ALIGN_LEFT)); cmds.push(printer.setAlign(printer.ALIGN_LEFT));
cmds.push(printer.printDivide("-")); cmds.push(printer.printDivide("-"));
cmds.push(printer.printText("应收金额:" + this.data.orderPriceYuan)); 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++) { for (var i = 0; i < 4; i++) {
cmds.push(printer.feedPaper()); cmds.push(printer.feedPaper());
} }
......
...@@ -115,6 +115,20 @@ function printText(text) { ...@@ -115,6 +115,20 @@ function printText(text) {
return { 'cmd': 'addText', 'args': ['' + text + "\n"] }; 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"] };
}
/** /**
* 打印分割线 * 打印分割线
*/ */
...@@ -167,3 +181,4 @@ module.exports.feedPaper = feedPaper; ...@@ -167,3 +181,4 @@ module.exports.feedPaper = feedPaper;
module.exports.printText = printText; module.exports.printText = printText;
module.exports.printDivide = printDivide; module.exports.printDivide = printDivide;
module.exports.printNowDate = printNowDate; 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