Commit 1d7b38c3 authored by jiangjiantao's avatar jiangjiantao

Merge branch 'dev-1.0' of…

Merge branch 'dev-1.0' of https://gitlab.infra.miyatech.com/pengguangpu/doublescreen-front into dev-1.0
parents feef5988 3f0efb0d
......@@ -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;
}
});
}
});
},
});
......@@ -14,12 +14,21 @@ page{
color: #ffffff;
position:relative;
margin-top: 91rpx;
font-size:34rpx;
font-family:PingFangSC-Medium,PingFang SC;
font-weight:500;
color:rgba(255,255,255,1);
line-height:38rpx;
}
.payPrice{
color: #ffffff;
font-size: 94rpx;
margin-top: 8rpx;
font-family:PingFangSC-Semibold,PingFang SC;
font-weight:600;
color:rgba(255,255,255,1);
line-height:113rpx;
}
.priceDetailRow{
display: flex;
......
<view class="page">
<image mode="aspectFit" src="/images/bg_balance.png" style="width:750rpx;height:504rpx"/>
<view style="position:absolute;width:100%;height:auto;left:0rpx;top:0rpx;display:flex;flex-direction:column;align-items:center">
<view class="goodsRemind">共计{{goodsNum}}件商品,应付总额</view>
<view class="payPrice">¥{{payPrice}}</view>
......@@ -14,7 +13,7 @@
</view>
</view>
<view style="font-size:38rpx;width:300rpx;color:rgba(0,0,0,0.85);font-weight:500;font-family:PingFangSC-Medium,PingFang SC;opacity:0.85;margin:75rpx auto;">请选择支付方式</view>
<view style="font-size:38rpx;width:300rpx;color:rgba(0,0,0,0.85);font-weight:500;font-family:PingFangSC-Medium,PingFang SC;opacity:0.85;margin:75rpx auto;margin-top:579rpx">请选择支付方式</view>
<view style="width:750rpx;margin-top:78rpx;justify-content:space-between;display:flex;flex-direction:row;box-sizing:border-box;padding-left:96rpx;padding-right:96rpx;">
<view class="payWayContainer" onTap="startPay">
......
......@@ -17,6 +17,9 @@ Page({
var totalQuantity = options.totalQuantity
var totalPrice = options.totalPrice
var totalDisc = options.totalDisc
this.setData({
list:options.goods,
});
if (totalQuantity != null) {
this.setData({
......@@ -29,6 +32,7 @@ Page({
this.setData({
payPrice: totalPrice,
totalPrice: totalPrice,
couponPrice: totalDisc,
})
}
......@@ -50,24 +54,6 @@ Page({
},
/**
* 保存最近支付成功的相关信息,每次支付成功都需刷新
* @param paySuccessGoodsList 支付成功的商品列表信息
* @param paySuccessResponse 支付成功响应,即云中台返回响应中的data信息
*/
saveData(paySuccessGoodsList, paySuccessResponse) {
my.setStorageSync({
key: 'paySuccessGoodsList',
data: paySuccessGoodsList
});
my.setStorageSync({
key: 'paySuccessResponse',
data: paySuccessResponse
});
},
/**
* @todo 支付结果的获取
......@@ -78,7 +64,8 @@ Page({
my.showLoading({});
//获取order
payUtils.getOrder(/*this.data.payPrice*/1,this.data.list, function(res){
var payAmount = payUtils.yuan2Fen(this.data.payPrice);
payUtils.getOrder(/*payAmount*/1,this.data.list, function(res){
if(res != null){
console.log("callback调用,res=" + JSON.stringify(res));
......@@ -92,42 +79,6 @@ Page({
}.bind(this));
},
//调用收款接口
doPay(orderNo, payCode) {
console.log("doPay调用"+orderNo);
this.setData({isPaying:true});
//使用barCode来当面付
payUtils.startPay(orderNo, payCode, 1, this.data.list, function(res){
my.hideLoading();
console.log("支付回调 ===>" + JSON.stringify(res));
this.setData({isPaying:false});
if(res == null){
return;
}
if(res.resultCode == 1){
//成功
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,
});
// }
}else{
console.log("支付回调失败 ===》 "+res.message);
my.ix.offCashierEventReceive();
my.showToast({
type: 'fail',
content: res.message,
duration: 2000
});
}
}.bind(this));
},
/**
* 打开收银台,进行扫码收款
*/
......@@ -197,6 +148,43 @@ Page({
},
//调用收款接口
doPay(orderNo, payCode) {
console.log("doPay调用");
this.setData({isPaying:true});
//使用barCode来当面付
var payAmount = payUtils.yuan2Fen(this.data.payPrice);
payUtils.startPay(orderNo, payCode, /*payAmount*/1, this.data.list, function(res){
my.hideLoading();
console.log("支付回调 ===>" + JSON.stringify(res));
this.setData({isPaying:false});
if(res == null){
return;
}
if(res.resultCode == 1){
//成功
console.log("支付回调成功,跳转 " );
// if(data.isCashierClosed == true){
my.ix.offCashierEventReceive();
this.saveData(this.data.list, res.data);
my.redirectTo({
url: '/pages/paysuccess/paysuccess',
});
// }
} else {
console.log("支付回调失败,toast提示 ");
my.ix.offCashierEventReceive();
my.showToast({
type: 'fail',
content: res.message,
duration: 2000
});
}
}.bind(this));
},
/**
* 保存最近支付成功的相关信息,每次支付成功都需刷新
* @param paySuccessGoodsList 支付成功的商品列表信息
......
......@@ -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());
}
......
......@@ -32,8 +32,6 @@ function getOrder(
if (app.globalData.localAccountInfo != null) {
orderCreateRequest.storeId = app.globalData.localAccountInfo.storeId;
}
//测试代码
orderCreateRequest.storeId = "001";
orderCreateRequest.tradeAmount = tradeAmount;
orderCreateRequest.deviceType = "ALIPAY";
orderCreateRequest.list = list;
......@@ -331,5 +329,16 @@ function queryPayState(tradeNo, callback){
});
}
function fen2Yuan(num) {
if (typeof num !== "number" || isNaN(num)) return null;
return (num / 100).toFixed(2);
}
function yuan2Fen(yuan) {
return parseInt(yuan * 100);
}
module.exports.startPay = startPay;
module.exports.getOrder = getOrder;
\ No newline at end of file
module.exports.getOrder = getOrder;
module.exports.fen2Yuan = fen2Yuan;
module.exports.yuan2Fen = yuan2Fen;
\ No newline at end of file
......@@ -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