Commit 1b2381ea authored by jiangjiantao's avatar jiangjiantao

后屏互动通信

parent d67d90b2
......@@ -3,6 +3,8 @@ App({
globalData: {
TEST_URL: "https://cashier.test.miyahub.net/",
RELEASE_URL: "https://cashier.miyahub.com/",
appId: "2021001107617164",
frontScreenAppId:"2021001107603212",
},
onLaunch(options) {
......
{
"pages": [
"pages/payresult/payresult",
"pages/landscan/landscan",
"pages/payresult/payresult",
"pages/index/index"
],
"window": {
......
......@@ -3,3 +3,9 @@ export const ACTION_PRINT_RESULT = "ACTION_PRINT_RESULT";
//发送重打印指令
export const ACTION_REPRINT = "ACTION_REPRINT";
//商品信息
export const ACTION_GOODS = "ACTION_GOODS";
//去结算页面
export const ACTION_GO_BALANCE = "ACTION_GO_BALANCE";
......@@ -44,9 +44,9 @@
<image class="operat-icon" mode="aspectFit" src="/images/clear_shop_list.png" catchTap="clearGood"/>
</view>
<view class="operating-bottom">
<text class="total-num">共{{totalNum}}件商品,合计金额</text>
<text class="pay-price">¥{{payPrice}}</text>
<button class="go-pay" size="default" type="primary">收款</button>
<text class="total-num">共{{totalQuantity}}件商品,合计金额</text>
<text class="pay-price">¥{{totalPrice}}</text>
<button class="go-pay" size="default" type="primary" onTap="goPay">收款</button>
</view>
</view>
</view>
......
var api = require("../../utils/api.js");
import { API_SCAN } from '../../const/apiurl'
import { ACTION_GOODS } from '../../const/actioncmd'
import { ACTION_GO_BALANCE } from '../../const/actioncmd'
import { ACTION_REQUEST_GOOD_INFO } from '../../const/actioncmd'
Page({
data: {
//是否正在用券
couponUseing:false,
couponUseing: false,
//0代表弹窗关闭 1代表手动输入条码弹窗 2代表会员 3.收款 4.退款
scene: 0,
//总数量
totalNum: 0,
//应付款
payPrice: "0.00",
totalQuantity: 0,
//折后价格
totalPrice: "0.00",
//折扣
totalDisc:"0.00",
goods: [
]
},
onLoad() { },
//键盘完成
onKeyBordFinished(data) {
let mockdata = '{"activityId": "5808753370","activityType": "Skus","activityName": "2020年新活动,中国加油","discnt": 100,"startTime": 1580877000000,"endTime": 1583423999000,"pic": "https://miya-ngm.oss-cn-hangzhou.aliyuncs.com/1560763177031148973127.png?Expires=1876123177&OSSAccessKeyId=LTAItcMpilplOYdV&Signature=9NTSNuDocXKQyr%2FbPlHooey3Vrg%3D","name": "test001","barcode": "09876","price": 100000,"salePrice": 100000,"hasDiscount": true}';
onShow() {
//开启后屏监听
let context = this;
my.ix.onBuddyMessage({
success: (res) => {
console.info(`onBuddyMessage success: ${JSON.stringify(res)}`);
if (res.action == ACTION_GOODS) {
//商品信息同步
my.hideLoading();
let viewGoodsInfo = res.data.viewGoodsInfo
if (viewGoodsInfo.goods != null && viewGoodsInfo.goods.length > 0) {
context.setData({
goods: viewGoodsInfo.goods,
totalPrice: viewGoodsInfo.totalPrice,
totalQuantity: viewGoodsInfo.totalQuantity,
totalDisc: viewGoodsInfo.totalDisc,
})
}
}
}
});
},
onHide() {
//关闭后屏监听
my.ix.offBuddyMessage();
},
//把所有的商品数据发送到后屏
sendGoodInfoToFront() {
let context = this;
var commonRequest = {
action:ACTION_GOODS,
data:this.data
};
my.ix.sendBuddyMessage({
target: getApp().globalData.frontScreenAppId,
data: commonRequest,
success: (res) => {
console.log("发送商品数据到前屏小程序成功 ===》" + JSON.stringify(res));
},
fail: (res) => {
console.log("发送商品数据到前屏小程序 失败 ===》 " + JSON.stringify(res));
//发送失败重试
context.sendGoodInfoToFront();
}
})
},
this.parseGoodInfo(JSON.parse(mockdata))
//键盘完成
onKeyBordFinished(barcode) {
this.onKeyBordClose();
my.showLoading({});
var commonRequest = {
action: ACTION_REQUEST_GOOD_INFO,
data: barcode
};
my.ix.sendBuddyMessage({
target: getApp().globalData.frontScreenAppId,
data: commonRequest,
success: (res) => {
console.log("发送商品条码到前屏小程序成功 ===》" + JSON.stringify(res));
},
fail: (res) => {
console.log("发送商品条码到前屏小程序 失败 ===》 " + JSON.stringify(res));
my.hideLoading();
my.showToast({
type: 'fail',
content: '发送商品条码到后屏失败',
duration: 3000,
success: () => {
},
});
}
})
},
// 键盘关闭
......@@ -37,70 +114,12 @@ Page({
//清空商品信息
clearGood(e) {
this.setData({ goods: [] })
},
//转化商品信息
parseGoodInfo(goodinfo) {
//价格 分转元
goodinfo.quantity = 1;
goodinfo.price = goodinfo.price / 100
goodinfo.salePrice = goodinfo.salePrice / 100
goodinfo.discnt = goodinfo.discnt / 100
//总数量
let totalQuantityTemp = 0
//总价格
let totalPriceTemp = 0.00
//数量+1
let isHasSame = false;
let lastgoods = this.data.goods;
let goodstemp = []
let goodtemp
lastgoods.forEach(function (item, index, array) {
if (item.barcode == goodinfo.barcode) {
let quantitytemp = item.quantity
item.quantity = quantitytemp + 1
isHasSame = true
goodtemp = item
} else {
totalQuantityTemp = totalQuantityTemp + item.quantity
totalPriceTemp = totalPriceTemp + item.price * item.quantity
goodstemp.push(item)
}
})
if (isHasSame) {
totalQuantityTemp = totalQuantityTemp + goodtemp.quantity
totalPriceTemp = totalPriceTemp + goodtemp.price * goodtemp.quantity
let nowgoods = []
nowgoods.push(goodtemp);
var newgoods = nowgoods.concat(goodstemp)
this.setData({ goods: newgoods })
} else {
totalQuantityTemp = totalQuantityTemp + 1
totalPriceTemp = totalPriceTemp + goodinfo.price
let nowgoods = []
nowgoods.push(goodinfo);
var newgoods = nowgoods.concat(lastgoods)
this.setData({ goods: newgoods })
}
//汇总
this.setData({
totalNum: totalQuantityTemp,
payPrice: totalPriceTemp,
})
this.calculation([]);
this.sendGoodInfoToFront();
},
//删除商品
deleteGood(e) {
let barcode = e.target.id;
let lastgoods = this.data.goods;
let newGoods = []
......@@ -110,6 +129,7 @@ Page({
}
})
this.setData({ goods: newGoods })
this.calculation(newGoods);
},
//减少商品
......@@ -131,13 +151,12 @@ Page({
}
})
this.setData({ goods: newGoods })
this.calculation(newGoods);
},
//增加商品
increaseGood(e) {
console.log(e);
let barcode = e.target.id;
let lastgoods = this.data.goods;
let newGoods = []
......@@ -151,15 +170,57 @@ Page({
}
})
this.setData({ goods: newGoods })
this.calculation(newGoods);
},
//计算总价格 总数量 总优惠
calculation(goods) {
if (null != goods && goods.length > 0) {
let quantitytemp = 0;
let pricetemp = 0;
goods.forEach(function (item, index, array) {
quantitytemp = quantitytemp + item.quantity
pricetemp = pricetemp + item.price
})
this.setData({totalQuantity:quantitytemp,totalPrice:pricetem+''})
//数据同步到前屏
this.sendGoodInfoToFront()
}
},
//跳转到支付结果页面
goPay(e) {
var commonRequest = {
action: ACTION_GO_BALANCE,
data: ""
};
my.ix.sendBuddyMessage({
target: getApp().globalData.frontScreenAppId,
data: commonRequest,
success: (res) => {
console.log("通知前屏跳转到结算页面 成功 ===》" + JSON.stringify(res));
},
fail: (res) => {
console.log("通知前屏跳转到结算页面 失败 ===》 " + JSON.stringify(res));
my.showToast({
type: 'fail',
content: '结算失败',
duration: 3000,
success: () => {
},
});
}
})
},
//用券返回
couponBack(e){
couponBack(e) {
this.setData({ couponUseing: false })
},
//使用券
useCoupon(e){
useCoupon(e) {
this.setData({ couponUseing: true })
}
......
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