You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

753 lines
19 KiB
JavaScript

9 months ago
const app = getApp();
const myOrder = require("../../utils/myOrder.js");
Page({
/**
* 页面的初始数据
*/
data: {
isMember: 0,
hidden: true,
payFlag: true,
isPasswd: true,
passwd: "",
queryCount: 0,
busNo: "",
phone: "",
tableNo: "",
tableName: "选择桌号",
people: 1,
busMode: 0,
reserveTime: "",
boxFee: 0,
comment: "",
payMode: "02",
order: null,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
this.data.tradeNo = options.tradeNo;
var time = app.utils.getFormatTime(new Date(), 0);
this.setData({
startTime: time,
time: time,
});
this.cy_getProgramOrderDetail();
},
/**
* 订单详情
*/
cy_getProgramOrderDetail: function() {
var that = this;
var params = {
method: "program.order.detail",
programId: app.globalData.programId,
openId: app.openId,
tradeNo: this.data.tradeNo
}
var ignores = ["programId", "openId", "tradeNo"];
app.jsapi.api(app.globalData.appKey, app.globalData.appSecret, app.globalData.serverUrl).ajax(params, ignores, function(json) {
console.log(json.data);
var data = json.data;
if (data.status == 1) {
var result = data.data;
var boxFee = 0;
for (var product of result.orderProduct) {
if (product.isSuit != 2) {
boxFee += product.count * product.basePackageFee;
}
product.makeInfo = [];
product.makeDes = product.specName;
for (var make of result.makeInfo) {
if (product.clientId == make.orderItemId) {
product.makeInfo.push(make);
if (product.makeDes != "") {
product.makeDes = product.makeDes + "、";
}
product.makeDes = product.makeDes + make.makeName;
}
}
}
var receiveAddress = "",
receiveName = "",
receiveMobile = "";
if (result.ticketDeliver.length != 0) {
var ticketDeliver = result.ticketDeliver[0];
receiveAddress = ticketDeliver.address;
receiveName = ticketDeliver.name;
receiveMobile = ticketDeliver.orderTel;
}
var sumMoney = 0;
if (result.busMode == 0) { // 堂食
sumMoney = result.receivable;
}
if (result.busMode == 1) { // 外带
sumMoney = parseFloat(result.receivable) + boxFee;
}
if (result.busMode == 3) { // 外送
sumMoney = parseFloat(result.receivable) + boxFee + result.deliverFee;
}
var tableName = "就餐桌号";
if (result.tableName != "") {
tableName = result.tableName;
}
console.log(result);
that.setData({
busMode: result.busMode,
storeName: result.storeName,
storeAddress: result.address,
tableNo: result.tableNo,
tableName: tableName,
phone: result.mobile,
receiveAddress: receiveAddress,
receiveName: receiveName,
receiveMobile: receiveMobile,
comment: result.ext2,
deliverFee: result.deliverFee,
boxFee: parseFloat(boxFee.toFixed(2)),
receivable: result.receivable,
sumMoney: sumMoney.toFixed(2),
list: result.orderProduct,
order: result,
});
} else {
wx.showToast({
title: data.message,
icon: "none"
});
}
}, function(err) {
console.log(err);
});
},
/**
* 选择收货地址
*/
cy_selectAddress: function() {
wx.navigateTo({
url: 'managerAddress',
})
},
/**
*
*/
cy_cancelTime: function() {
},
/**
* 就餐时间
*/
cy_selectTime: function(e) {
var time = e.detail.value
this.setData({
outTime: time,
time: time,
});
},
/**
* 加载收货地址
*/
cy_loadAddress: function(address) {
console.log(address);
if (!address) {
return;
}
var receiveAddress = address.receiveAddress + address.receiveDoor;
this.setData({
receiveAddress: receiveAddress,
receiveName: address.receiveName,
receiveMobile: address.receiveMobile,
});
},
/**
* 就餐桌号
*/
cy_tapSelectTable: function() {
var url = "../order/table/table?storeId=" + this.data.order.storeId;
wx.navigateTo({
url: url,
})
},
/**
* 就餐方式
*/
cy_tapSelectEatType: function(e) {
var busMode = e.currentTarget.dataset.busmode;
console.log(busMode);
var sumMoney = 0;
var boxFee = 0;
var order = this.data.order;
if (busMode == 0) { // 堂食
console.log("堂食");
sumMoney = order.receivable;
}
if (busMode == 1) { // 外带
console.log("外带");
for (var product of order.orderProduct) {
if (product.isSuit != 2) {
boxFee = boxFee + product.basePackageFee * product.count;
}
}
sumMoney = parseFloat(order.receivable) + boxFee;
}
this.setData({
boxFee: parseFloat(boxFee).toFixed(2),
receivable: order.receivable,
sumMoney: parseFloat(sumMoney).toFixed(2),
busMode: busMode
});
},
/**
* 备注信息
*/
cy_tapInputCommont: function() {
wx.navigateTo({
url: '../order/balance/userComment',
})
},
/**
* 去支付
*/
cy_tapGoPay: function() {
console.log(this.data.order);
for (var productInfo of this.data.order.orderProductInfo) {
if (productInfo.type == 2) {
wx.showToast({
title: '该订单已失效,请重新点单',
icon: "none"
})
return;
}
}
this.setData({
payFlag: false
});
},
/**
* 关闭支付
*/
cy_closePay: function() {
this.setData({
payFlag: true
});
},
/**
* 会员支付
*/
cy_tapMemberPay: function() {
this.data.isMember = 1;
// wx.showToast({
// title: '即将上线',
// icon: "none"
// })
// this.cy_programWeixinPay();
this.cy_programOorderEdit();
},
/**
* 微信支付
*/
cy_tapWxPay: function() {
this.data.isMember = 0;
//
this.cy_programOorderEdit();
},
/**
* 订单修改
*/
cy_programOorderEdit: function() {
this.setData({
hidden: false,
msg: "处理中..."
})
var busNo = this.data.tradeNo;
var mobile = this.data.phone;
var tableNo = this.data.tableNo;
var tableName = this.data.tableName;
var reserveTime = this.data.time;
var packageFee = 0;
var deliverFee = 0;
var busMode = this.data.busMode;
var jsonStringProduct = [];
if (busMode == 0) { // 堂食
packageFee = 0;
for (var product of this.data.order.orderProduct) {
var item = {};
item.id = product.clientId;
item.packageFee = 0;
jsonStringProduct.push(item);
}
}
if (busMode == 1) { // 外带
packageFee = 0;
for (var product of this.data.order.orderProduct) {
if (product.isSuit != 2) {
var item = {};
item.id = product.clientId;
item.packageFee = (product.count * product.basePackageFee).toFixed(2);
packageFee += product.count * product.basePackageFee;
jsonStringProduct.push(item);
}
}
}
if (busMode == 3) { // 外卖
packageFee = 0;
deliverFee = this.data.order.deliverFee;
for (var product of this.data.order.orderProduct) {
if (product.isSuit != 2) {
var item = {};
item.id = product.clientId;
item.packageFee = (product.count * product.basePackageFee).toFixed(2);
packageFee += product.count * product.basePackageFee;
jsonStringProduct.push(item);
}
}
}
var that = this;
var params = {
method: "program.order.edit",
programId: app.globalData.programId,
openId: app.openId,
busNo: busNo, // 订单编号
mobile: mobile, // 手机
tableNo: tableNo, // 桌号
tableName: tableName, //
people: 1, // 就餐人数
busMode: busMode, // 营业模式
reserveTime: reserveTime, // 预定时间
deliverFee: deliverFee, // 配送费
packageFee: packageFee, // 餐盒费
ext2: this.data.comment, //
jsonStringProduct: JSON.stringify(jsonStringProduct),
}
console.log(params);
var ignores = ["programId", "openId", "busNo", "mobile", "tableNo", "tableName", "people", "busMode", "reserveTime", "deliverFee", "packageFee", "ext2", "jsonStringProduct"];
app.jsapi.api(app.globalData.appKey, app.globalData.appSecret, app.globalData.serverUrl).ajax(params, ignores, function(json) {
console.log(json);
var data = json.data;
if (data.status == 1) {
if (that.data.isMember == 0) { // 微信支付
that.cy_programWeixinPay();
}
if (that.data.isMember == 1) { // 会员支付
that.cy_memberCreateVoucherNoPlatform();
}
} else {
that.setData({
hidden: true
})
wx.showToast({
title: data.message,
icon: "none"
})
}
}, function(err) {
that.setData({
hidden: true
})
wx.showToast({
title: '网络连接异常, 请检查',
icon: "none"
})
});
},
/**
* 统一订单创建
*/
cy_memberCreateVoucherNoPlatform: function() {
var that = this;
var saleDate = app.utils.getFormatTime(new Date(), 1);
var goodsDetails = [];
for (var product of this.data.order.orderProduct) {
var detail = {};
detail.goodsId = product.productId;
detail.name = product.productName;
detail.spec = product.specName;
detail.quantity = product.count;
detail.discountMoney = product.discountTotal;
detail.money = product.receivable;
goodsDetails.push(detail);
}
var money = parseInt((this.data.order.receivable * 100));
if (that.data.busMode == 1) { // 外带
money = parseInt(this.data.order.receivable * 100) + parseInt(this.data.boxFee * 100);
}
if (that.data.busMode == 3) { // 外卖
money = parseInt(this.data.order.receivable * 100) + parseInt(this.data.boxFee * 100) + parseInt(this.data.deliverFee * 100);
}
var params = {
method: "jw.trade.create.voucherNo.platform",
tradeNo: that.data.tradeNo,
saleDate: saleDate,
subject: app.openId,
totalAmount: money,
amount: money,
shopId: that.data.order.storeId,
cardNo: app.globalData.cardNo,
body: "微信小程序点餐",
sourceSign: "wechat",
goodsDetails: JSON.stringify(goodsDetails)
}
console.log(params);
var ignores = ["body", "sourceSign", "goodsDetails"];
app.jsapi.memberApi(app.globalData.memberAppKey, app.globalData.memberAppSecret, app.globalData.memberUrl).ajax(params, ignores,
function(json) {
console.log(json);
var data = json.data;
if (data.status == 1) {
var result = data.data;
that.cy_memberJwtradepayplatform(result);
} else {
wx.showToast({
title: data.errMessage,
icon: "none"
})
that.setData({
hidden: true
})
}
},
function(err) {
wx.showToast({
title: '网络连接异常',
icon: "none"
})
that.setData({
hidden: true
})
});
},
/**
* 会员卡统一收单支付
*/
cy_memberJwtradepayplatform: function(tempData) {
var that = this;
var cardInfo = wx.getStorageSync("cardInfo");
var cardPayInfo = [{
prepayment: tempData.prepayment,
cardNo: app.globalData.cardNo,
amount: tempData.totalAmount
}];
var pays = [{
payTypeNo: "02",
payType: "会员卡",
money: tempData.totalAmount,
}];
var params = {
method: "jw.trade.pay.platform",
tradeVoucherNo: tempData.tradeVoucherNo, // 交易参考号(预支付生成的订单号)
tradeNo: tempData.tradeNo, // 商户订单号
totalAmount: tempData.totalAmount, // 订单总金额(精确到分)
payCardAmount: tempData.totalAmount, // 刷卡总金额(精确到分)
pointAmount: tempData.totalAmount, // 参与积分运算总金额(精确到分)
shopId: that.data.order.storeId, //
memberId: cardInfo.memberId,
mobile: cardInfo.mobile, //
realAmount: tempData.totalAmount, // 实收总金额(精确到分)
// couponTotalAmount: "", // 优惠券总金额(精确到分)
cardPayInfo: JSON.stringify(cardPayInfo), // 卡支付明细(参数值为JSON字符串,如果刷卡金额大于0此项必填)
pays: JSON.stringify(pays), // 支付方式明细(参数值为JSON字符串)
}
console.log("----------------", params);
var ignores = ["memberId", "mobile", "realAmount", "cardPayInfo", "pays"];
app.jsapi.memberApi(app.globalData.memberAppKey, app.globalData.memberAppSecret, app.globalData.memberUrl).ajax(params, ignores,
function(json) {
console.log("会员卡统一支付");
console.log(json);
var data = json.data;
if (data.status == 1) {
var result = data.data;
that.cy_programorderpay(result);
} else {
wx.showToast({
title: data.errMessage,
icon: "none",
})
that.setData({
hidden: true
})
}
},
function(err) {
console.log(err);
that.setData({
hidden: true
})
});
},
/**
* 支付点上传
*/
cy_programorderpay: function(tempData) {
console.log("支付上传");
var that = this;
var saleDate = app.utils.getFormatTime(new Date(), 1);
var payCard = tempData.cardList[0];
var jsonString = myOrder.getMemberOrder();
jsonString.paid = app.utils.getTwo(payCard.amount / 100);
jsonString.money = app.utils.getTwo(payCard.amount / 100);
jsonString.cardNo = payCard.cardNo;
jsonString.payNo = payCard.tradeVoucherNo;
jsonString.payDate = saleDate;
jsonString.voucherNo = tempData.tradeVoucherNo;
console.log(jsonString);
var params = {
method: "program.order.pay",
programId: app.globalData.programId, //
openId: app.openId, //
busNo: tempData.tradeNo, //
jsonString: JSON.stringify(jsonString)
};
console.log("支付上传");
console.log(params);
var ignores = ["programId", "openId", "jsonString"];
app.jsapi.api(app.globalData.appKey, app.globalData.appSecret, app.globalData.serverUrl).ajax(params, ignores, function(json) {
console.log(json);
that.setData({
hidden: true
})
var data = json.data;
if (data.status == 1) {
var result = data.data;
if (that.data.busMode == 0 || that.data.busMode == 1) {
wx.redirectTo({
url: '../order/balance/paySuccess?no=' + result.busNo,
})
}
if (that.data.busMode == 3) {
wx.redirectTo({
url: '../order/balance/payOrderSuccess?no=' + result.busNo,
})
}
} else {
that.setData({
hidden: true
})
wx.showToast({
title: data.message,
icon: "none"
})
}
},
function(err) {
wx.showToast({
title: "网络连接失败,订单上传异常",
icon: "none"
})
that.setData({
hidden: true
})
});
},
/**
* 获取微信JSAPI支付参数
*/
cy_programWeixinPay: function() {
var that = this;
var order = that.data.order;
var busMode = that.data.busMode;
var amount = 0;
if (busMode == 0) { // 堂食
amount = order.receivable;
}
if (busMode == 1) { // 外带
amount = order.receivable + that.data.boxFee;
}
if (busMode == 3) { // 外卖
amount = order.receivable + that.data.boxFee + that.data.deliverFee;
}
var params = {
method: "program.weixin.pay",
storeId: order.storeId,
programId: app.globalData.programId,
appid: app.globalData.appid,
openId: app.openId,
tradeNo: order.no,
amount: amount.toFixed(2),
}
console.log("微信支付", params);
var ignores = ["appid", "openId", "tradeNo", "amount"];
app.jsapi.api(app.globalData.appKey, app.globalData.appSecret, app.globalData.serverUrl).ajax(params, ignores, function(json) {
console.log(json);
var data = json.data;
if (data.status == 1) {
that.setData({
hidden: true
})
var param = data.data;
that.cy_wxpay(param);
} else {
that.setData({
hidden: true
})
wx.showToast({
title: data.message,
icon: "none"
})
}
}, function(err) {
console.log(err);
that.setData({
hidden: true
})
wx.showToast({
title: "网络连接异常,请检查",
icon: "none"
})
});
},
/**
* 拉起微信支付
*/
cy_wxpay: function(param) {
console.log(param);
var that = this;
wx.requestPayment({
'timeStamp': param.timeStamp,
'nonceStr': param.nonceStr,
'package': param.package,
'signType': param.signType,
'paySign': param.paySign,
success: function(res) {
console.log("cy_wxpay-success", res);
that.cy_queryWXPayReult();
},
fail: function(res) {
app.msg.showMsg("提示", "微信支付失败");
// wx.redirectTo({
// url: 'paySuccess?no=',
// })
},
complete: function(res) {
that.setData({
hidden: true,
});
console.log("cy_wxpay-complete", res);
}
})
},
/**
* 查询微信支付结果
*/
cy_queryWXPayReult: function() {
var that = this;
var order = this.data.order;
var params = {
method: "program.weixin.pay.query",
storeId: order.storeId,
programId: app.globalData.programId,
tradeNo: app.orderTicket.tradeNo
}
console.log(params);
var ignores = ["tradeNo"];
app.jsapi.api(app.globalData.appKey, app.globalData.appSecret, app.globalData.serverUrl).ajax(params, ignores, function(json) {
console.log(json);
var data = json.data;
if (data.status == 1) {
if (that.data.busMode == 0 || that.data.busMode == 1) {
wx.redirectTo({
url: '../order/balance/paySuccess?no=' + that.data.tradeNo,
})
}
if (that.data.busMode == 3) {
wx.redirectTo({
url: '../order/balance/payOrderSuccess?no=' + that.data.tradeNo,
})
}
} else {
wx.showToast({
title: data.message,
icon: "none"
})
}
}, function(err) {
console.log(err);
});
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
}
})