const app = getApp(); const mqttMessage = require('../../../utils/mqttMessage.js'); const util = require("../../../utils/util.js") const utils = require("../../../utils/utils.js") const myOrder = require('../../../utils/myOrder.js'); Page({ /** * 页面的初始数据 */ data: { tradeNo: "", isInit: false, hidden: false, storeId: "", once: "申请退款", status: "等待接单", order: null, isRefund: false, isRefundSuccess: false, isRefundShow: false }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ color: app.globalData.color }) wx.setNavigationBarColor({ backgroundColor: app.globalData.color, frontColor: '#ffffff', }) //清除订单促销标记 app.orderTicket.promotionFlag = 0; this.data.isInit = options.init; console.log("======================", options); mqttMessage.mqttSubscribe(1); if (options.isMemberPay) { if (options.tempData) { console.error("tempData", options.tempData) this.cy_programorderpay(JSON.parse(options.tempData)); } else { wx.showToast({ title: '会员卡支付上传流水失败请联系开发者', icon: 'none', duration: 60000 }) } } else { app.globalData.tradeNo = options.no; this.data.tradeNo = options.no; if (options.once) { this.setData({ once: options.once }); } this.cy_getOrderInfo(); } }, /** * 支付点上传 */ 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(); this.data.tradeNo = tempData.tradeNo; 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) }; var ignores = ["programId", "openId", "jsonString"]; console.log(params); 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; app.globalData.tradeNo = result.busNo; that.data.tradeNo = result.busNo; that.cy_getOrderInfo(); } else { that.setData({ hidden: true }) wx.showToast({ title: data.message, icon: "none" }) } }, function (err) { wx.showToast({ title: "网络连接失败,订单上传异常", icon: "none" }) that.setData({ hidden: true }) }); }, /** * 发送取餐号消息 */ sendTakeFoodMessage: function (order) { var that=this; var data = { 'openId': wx.getStorageSync('openId'), 'formId': "123456", 'wid': app.globalData.memberWid, 'sendType': "takeFood", 'method': 'get.smweixin.formId', 'seqNo': that.data.seqNo, 'shopName': order.storeName, 'foodName': order.orderProduct[0].productName+".....", 'memberId': wx.getStorageSync('memberId'), 'address': order.address } var ignores = ["shopName","foodName","address"]; // app.globalData.memberUrl app.jsapi.memberApi(app.globalData.memberAppKey, app.globalData.memberAppSecret, app.globalData.memberUrl).ajax(data, ignores, function (json) { }, function (error) {} ) }, /** * */ onShow: function () { mqttMessage.mqttOn(this); console.log(app.appTop1); }, /** * mqtt消息 */ onMessage: function (top, message) { console.log("mqtt消息", message); if (message.deliverStatus == 1) { wx.showToast({ title: '骑手已接单', icon: "none" }) return; } else if (message.deliverStatus == 14) { wx.showToast({ title: '您的配送单已取消', icon: "none" }) return; } var busNo = message.busNo; var type = message.type; if (busNo == this.data.tradeNo) { app.globalData.tradeNo = busNo; this.data.tradeNo = busNo; var status = "待接单"; var title = "待接单"; if (type == 0) { title = "商家拒单"; status = "商家拒单"; } if (type == 1) { title = "商家已接单"; status = "已接单"; } if (type == 2) { title = "商家同意退款"; status = "已退款"; } if (type == 3) { title = "商家拒绝退款"; status = "拒绝退款"; } wx.showToast({ title: title, duration: 3000 }) this.setData({ status: status }) // mqtt消息查询订单信息 this.cy_getOrderInfo(); } }, /** * 获取订单信息 */ cy_getOrderInfo: 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"]; console.log("------------------", params); app.jsapi.api(app.globalData.appKey, app.globalData.appSecret, app.globalData.serverUrl).ajax(params, ignores, function (json) { wx.stopPullDownRefresh(); console.log(json); var data = json.data; if (data.status == 1) { console.log(data); var result = data.data; for (var product of result.orderProduct) { product.makeDes = product.specName; for (var make of result.makeInfo) { if (product.clientId == make.orderItemId) { if (product.makeDes != "") { product.makeDes = product.makeDes + "、"; } product.makeDes = product.makeDes + make.makeName; if (make.addPrice > 0) { product.makeDes = product.makeDes + "+" + make.addPrice + "元"; } } } } app.globalData.orderNo = result.no; mqttMessage.mqttSubscribe(6); that.setData({ hidden: true, busMode: result.busMode, seqNo: result.seqNo, status: that.cy_getOrderStatus(result.status, result.refundStatus), no: result.no, packageFee: result.packageFee, receivable: (parseFloat(result.receivable) + parseFloat(result.packageFee)).toFixed(2), saleDate: result.saleDate, name: result.mobile, storeId: result.storeId, tableName: result.tableName, ext2: result.ext2, list: result.orderProduct, order: result }) that.sendTakeFoodMessage(result); } else { wx.showToast({ title: data.message, icon: "none" }) } }, function (err) { console.log(err); wx.showToast({ title: "网络连接失败,请刷新查看", icon: "none" }) }); }, /** * 再来一单 */ cy_tapOnceOrder: function (e) { wx.showLoading({ title: '....', mask: true }) console.log(e); var that = this; var once = that.data.once; if (once == "再来一单") { console.error("com one ") wx.navigateBack({ }) } if (once == "申请退款") { var order = that.data.order; if (order.status != 1 || order.refundStatus != 0) { var title = "不支持申请退款"; if (order.refundStatus == 1) { title = "申请退款中"; } wx.showToast({ title: title, icon: 'none' }) return; } if (that.data.isRefund) { if (that.data.isRefundSuccess) { wx.showToast({ title: "已经申请退款", icon: 'none' }) return; } } var saleDate = that.data.order.saleDate + ""; console.error("that.data.saleDate", that.data.order.saleDate, "---", Date.parse(new Date(saleDate)), Date.parse(new Date(that.data.order.saleDate))); console.error("nowDate reduce 2", Date.parse(new Date()) - (2 * 60 * 60 * 1000)); console.error("compareDate ", (Date.parse(new Date()) - (2 * 60 * 60 * 1000) - (Date.parse(saleDate)))); //判断出外卖订单时间 if (that.data.busMode != 3) { if ((Date.parse(new Date()) - (2 * 60 * 60 * 1000) - (Date.parse(new Date(saleDate)))) > 0) { wx.showToast({ title: "下单时间超过两个小时不支持退款", icon: 'none' }) return; } } if (!this.data.isRefundShow) { this.data.isRefundShow = true; wx.showModal({ title: '提示', content: '确定申请退款吗?', success: res => { if (res.confirm) { that.data.isRefund = true; that.data.isRefundSuccess = true; that.cy_orderRefund(); that.data.formId = e.detail.formId; } else { this.data.isRefundShow = false; } }, }) } } wx.hideLoading(); }, /** * 申请退款 */ cy_orderRefund: function () { var that = this; var params = { method: "program.order.refundapply", programId: app.globalData.programId, openId: app.openId, busNo: this.data.tradeNo } console.log(params); var ignores = ["programId", "openId"]; 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) { wx.showToast({ title: "申请退款,等待商家同意退款", icon: "none" }) that.cy_programuserweixinformid(that.data.tradeNo); that.cy_getOrderInfo(); } else { wx.showToast({ title: data.message, icon: "none" }) } }, function (err) { console.log(err); wx.showToast({ title: '网络连接异常,请检查', icon: "none" }) }); }, /** * */ cy_tapEvaluate: function () { wx.redirectTo({ url: '../../list/shopEvaluate?storeId=' + this.data.storeId, }) }, /** * 联系商家 */ cy_callPhone: function () { var store = wx.getStorageSync("store"); wx.makePhoneCall({ phoneNumber: store.orderTel, }) }, /** * 提交fromId */ cy_programuserweixinformid: function (busNo) { var formId = this.data.formId; var params = { method: "program.userweixin.formid", formId: formId, openId: app.openId, programId: app.globalData.programId, sendType: "orderBack", busNo: busNo, } console.log(params); var ignores = ["openId"]; app.jsapi.api(app.globalData.appKey, app.globalData.appSecret, app.globalData.serverUrl).ajax(params, ignores, function (json) { console.log(json); }, function (err) { console.log(err) }); }, /** * 订单状态 */ // 单据状态(- 1待支付0待接单1已确认2已配送3已取消4已完成) cy_getOrderStatus: function (status, refundStatus) { var result = ""; switch (status) { case -1: result = "待支付"; break; case 0: result = "待接单"; break; case 1: result = "已接单"; break; case 2: result = "已配送"; break; case 3: result = "已取消"; break; case 4: result = "已完成"; break; } if (refundStatus == 1) { result = "申请退款中"; } if (refundStatus == 2) { result = "商家拒绝退款"; } if (refundStatus == 4) { result = "已退款"; } return result; }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { console.log("下拉刷新"); this.cy_getOrderInfo(); }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { if (this.data.isInit) { app.orderTicket.orderList = []; } }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { if (this.data.isInit) { app.orderTicket.orderList = []; } }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })