const app = getApp(); const mqttMessage = require('../../../utils/mqttMessage.js'); var util = require('../../../utils/util.js') const myOrder = require('../../../utils/myOrder.js'); Page({ /** * 页面的初始数据 */ data: { tradeNo: "", isInit: false, hidden: false, storeId: "", once: "再来一单", status: "等待接单", order: null, isShowDetail: false, orderDesc: " " }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ color: app.globalData.color }) //清除订单促销标记 app.orderTicket.promotionFlag = 0; mqttMessage.mqttSubscribe(1); this.data.isInit = options.init; if(options.isMemberPay){ if(options.tempData){ this.cy_programorderpay(JSON.parse(options.tempData)); }else{ wx.showToast({ title: '会员卡支付上传流水失败请联系开发者', icon:'none', duration:60000 }) } }else{ this.data.tradeNo = options.no; app.globalData.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(); app.globalData.tradeNo= tempData.tradeNo; that.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"]; // app.globalData.serverUrl 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 }) }); }, /** * */ onShow: function () { mqttMessage.mqttOn(this); console.log(app.appTop1); }, /** * mqtt消息 */ onMessage: function (top, message) { console.log("mqtt消息", message); var busNo = message.busNo; var type = message.type; if (message.deliverStatus == 1) { util.showSuccessMsg("骑手已接单"); return; } else if (message.deliverStatus == 4) { util.showFailureMsg("您的配送单已取消"); return; } if (busNo == this.data.tradeNo) { var status = "待接单"; var title = "待接单"; app.globalData.tradeNo = busNo; this.data.tradeNo = busNo; 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 }) this.cy_getOrderInfo(); } }, cy_getOrderDeliveryInfo: function (storeId) { var that = this; var params = { method: "program.order.delivery.query", storeId: storeId, busNo: this.data.tradeNo } app.jsapi.api(app.globalData.appKey, app.globalData.appSecret, app.globalData.serverUrl).ajax(params, [], function (json) { console.log(json); var data = json.data; if (data.status == 1) { var result = data.data; if (result.deliverStatus != -1) { that.setData({ orderDesc: result.deliverStatusDesc }) } else { that.setData({ orderDesc: result.statusDesc }) } that.setData({ deliveryInfo: data.data }) } else { wx.showToast({ title: data.message, icon: "none" }) } }, function (err) { console.log(err); wx.showToast({ title: "网络连接失败,请刷新查看", icon: "none" }) }); }, /** * 获取订单信息 */ 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"]; 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; that.cy_getOrderDeliveryInfo(result.storeId); 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; } } } 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, deliverFee: result.deliverFee, receivable: (parseFloat(result.receivable) + parseFloat(result.packageFee) + parseFloat(result.deliverFee)).toFixed(2), saleDate: result.saleDate, name: result.mobile, storeId: result.storeId, tableName: result.tableName, ext2: result.ext2, reserveTime: result.reserveTime, address: result.ticketDeliver[0].address, name: result.ticketDeliver[0].name, orderTel: result.ticketDeliver[0].orderTel, list: result.orderProduct, order: result }) } else { wx.showToast({ title: data.message, icon: "none" }) } }, function (err) { console.log(err); wx.showToast({ title: "网络连接失败,请刷新查看", icon: "none" }) }); }, cy_call_knight: function (e) { if (e.currentTarget.dataset.phone != "") { wx.makePhoneCall({ phoneNumber: e.currentTarget.dataset.phone, }) } else { wx.showToast({ title: '订单还未配送,请等待~', icon:"none" }) } }, /** * 再来一单 */ cy_tapOnceOrder: function (e) { console.log(e); var once = this.data.once; if (once == "再来一单") { wx.navigateBack({ }) } if (once == "申请退款") { var order = this.data.order; if (order.status != 1 || order.refundStatus != 0) { var title = "不支持申请退款"; if (order.refundStatus == 1) { title = "申请退款中"; } wx.showToast({ title: title, icon: 'none' }) return; } var that = this; this.data.formId = e.detail.formId; wx.showModal({ title: '提示', content: '确定申请退款吗?', success: res => { if (res.confirm) { that.cy_orderRefund(); } } }) } }, /** * 申请退款 */ 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; }, closeDelivery: function () { this.setData({ isShowDetail: false }) }, cy_showDelivery: function () { this.setData({ isShowDetail: true }) }, preventTouchMove: function () {}, /** * 页面相关事件处理函数--监听用户下拉动作 */ 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 () { } })