var config = require("../../../config/config.js"); var app = getApp(); const Http = require("../../../utils/HttpBasics"); const util = require("../../../utils/util"); Page({ data: { data: {}, carList: [], couponChannelId: null, couponId: null, orderId: "", day: "", hour: "", minute: "" }, phone: function () { let that = this; console.log(that.data); if (that.data.data.merchantLinkPhone) { wx.makePhoneCall({ phoneNumber: that.data.data.merchantLinkPhone }); } }, onLoad(options) { let that = this; wx.showLoading({ title: "加载中..." }); /** * 暂时注销 * this.orderFunc() */ // if (options.flag) { // // this.orderFunc(); // } // else { // } that.setData({ couponChannelId: options.couponChannelId, couponId: options.couponId }); var parmer = { url: config.api.couponDetail, data: { couponChannelId: options.couponChannelId } }; Http.get(parmer).then(res => { console.log(res); console.log("details"); //当前时间与优惠券下架时间做计算 var endTime = util.fmtDate(res.data.endTime); util.timechuo(endTime); that.setData({ endtime: util.timechuo(endTime) }); wx.hideLoading(); that.setData({ data: res.data }); }); // } }, /** * 支付订单更新 */ payOrderUpdate: (orderId, payOrderId, status, reason) => { // 支付成功 Http.post({ url: config.api.payOrderUpdate, data: { payOrderId: payOrderId, orderId: orderId, status: status, reason: reason } }) .then(res => { console.log("payOrderUpdate then", res); // wx.showToast({ // title: "购买成功", // duration: 2500 // }); }) .catch(err => { console.log("payOrderUpdate catch", err); }); }, /** * 拉取车牌列表 */ // init: function () { // var that = this // app.parkInitCallback = token => { // that.initPark() // that.initUsrCarList() // if (!app.globalData.carLogin) { // // 共同登录 // Http.post({ // url: config.api.carInit, // data: { // phone: app.globalData.phone // } // }).then(res => { // app.globalData.carLogin = true // app.globalData.parkVendor = res.data.vendor // if (res.data.token != "undefined") { // app.globalData.etcpToken = res.data.token // console.log("etcpToken", app.globalData.etcpToken) // } // // 获取 停车费 // that.getStopFee() // }) // } // } // if (app.globalData.token && app.globalData.token != null) { // app.parkInitCallback(app.globalData.token) // } // }, // getStopFee: function () { // var that = this // // carLogin // for (var i = 0; i < that.data.carList.length; i++) { // that.getStopFeeItem(that.data.carList[i], i) // } // // console.log(JSON.stringify(getStopFeeItem)) // }, // initPark: function () { // var that = this // // 车场信息获取 // Http.get({ // url: config.api.getParkInfo, // data: {} // }) // .then(res => { // console.log(res) // that.setData({ // park: res.data, // }) // }) // }, // initUsrCarList: function () { // var that = this // // 绑定车获取 // Http.get({ // url: config.api.getUserCarList, // data: {} // }).then(res => { // console.log('>>>>>>>>>>>>>>>>>1' + JSON.stringify(res)); // that.setData({ // carList: res.data // }) // }) // }, /** * 发起支付 */ orderFunc() { var that = this; wx.showLoading({ title: "加载中..." }); if (that.data.data.type == 6) {} else { Http.post({ url: config.api.checkPhoneStatus, data: {} }) .then(res => { console.log(res); var data = { couponChannelId: "" + that.data.couponChannelId, couponId: "" + that.data.couponId }; if (that.data.couponChannelId == null) { var data = { couponId: "" + that.data.couponId }; } /** * orderSave 下单 */ return Http.post({ url: config.api.orderSave, data: data }); }) .catch(err => { console.log(err); console.log(that.data.couponChannelId); console.log(that.data.couponId); //console.log("我即将要跳转到用户手机号授权的页面"); if (err.code == "2011") { wx.showToast({ title: "商户信息没找到", image: "./../../../assets/img/fail.png", duration: 2000, mask: false }); } else if (err.code == "2013") { wx.showToast({ title: "商户信息禁用", image: "./../../../assets/img/fail.png", duration: 2000, mask: false }); } else if (err.code == "3000") { wx.showToast({ title: "库存不足", image: "./../../../assets/img/fail.png", duration: 2000, mask: false }); } else if (err.code == "3001") { wx.showToast({ title: "领取达到上限", image: "./../../../assets/img/fail.png", duration: 2000, mask: false }); } else if (err.code == "3002") { wx.showToast({ title: "订单失败", image: "./../../../assets/img/fail.png", duration: 2000, mask: false }); } else if (err.code == "3003") { wx.showToast({ title: "订单不存在", image: "./../../../assets/img/fail.png", duration: 2000, mask: false }); } else if (err.code == "3004") { wx.showToast({ title: "订单不存在", image: "./../../../assets/img/fail.png", duration: 2000, mask: false }); } else if (err.code == "4003") { wx.showToast({ title: "卡券已作废", image: "./../../../assets/img/fail.png", duration: 2000, mask: false }); } else if (err.code == 11005) { // 用户手机未授权 /** * 将值传到用户手机号授权的页面 * */ wx.redirectTo({ url: "/pages/getphoneInfo/index?couponChannelId=" + that.data.couponChannelId + "&couponId=" + that.data.couponId }); } else if (err.code == 11006) { // 用户手机已加密 wx.redirectTo({ url: "/pages/phoneinput/phoneinput?couponChannelId=" + that.data.couponChannelId + "&couponId=" + that.data.couponId }); } else { wx.showToast({ title: err.message, image: "./../../../assets/img/fail.png", duration: 2000, mask: false }); } }) .then(res => { console.log(res); console.log("点击领取卡券一直在loading"); if (typeof (res) != "undefined") { console.log("", res); let orderId = "" + res.data.id; that.setData({ orderId: orderId }); if (res.data.payment > 0) { // 支付金额不为0 /** * 支付订单创建 */ Http.post({ url: config.api.payOrderCreate, data: { orderId: orderId } }).then(res => { console.log(res); /// Begin payment ---- var payOrderId = "" + res.data.payOrderId; wx.hideLoading(); wx.requestPayment({ timeStamp: res.data.timeStamp, nonceStr: res.data.nonceStr, package: res.data.package, signType: (res.data.signType) ? res.data.signType : "MD5", paySign: res.data.paySign, success: res => { that.payOrderUpdate(that.data.orderId, payOrderId, 1); // 支付成功 console.log(res); if (res.errMsg == "requestPayment:ok") { wx.showToast({ title: "购买成功", image: "./../../../assets/img/success.png", duration: 1000, mask: false, success: function () { setTimeout(function () { wx.hideLoading(); }, 1600); setTimeout(() => { wx.navigateTo({ url: `/pages/order/detail/index?orderId=${ that.data.orderId }` }); }, 1000) } }); /** * 用户支付成功以后跳转到券包列表 */ wx.setStorage({ key: 'couponNum', data: "couponNum", }) if (that.data.data.type == 5) { setTimeout(() => { wx.switchTab({ url: '/pages/passCar/passCar' }); }, 1600); // this.initUsrCarList() // 领取 5.停车券 // TODO 选取用户下的车牌 } } }, fail: res => { that.payOrderUpdate(that.data.orderId, payOrderId, 2); // 支付失败 console.log(res); // wx.showToast({ // title: "支付失败", // image: "./../../../assets/img/fail.png", // duration: 2000, // mask: false // }); return; }, complete: res => { // console.log(res); // console.log("支付完成"); // if (res.errMsg == "requestPayment:ok") { // } else { // wx.showToast({ // title: "支付失败", // image: "./../../../assets/img/fail.png", // duration: 2000, // mask: false // }); // } // return; } }); /// End payment -------- ///// virtual pay //var payOrderId = "" + res.data.out_trade_no; //that.payOrderUpdate(that.data.orderId, payOrderId, 1); // 支付成功 ///// end virtual pay }); } else { // 免费券 that.payOrderUpdate(orderId, "0", 1); wx.setStorage({ key: 'couponNum', data: "couponNum" }) wx.showToast({ title: "领取成功", image: "./../../../assets/img/success.png", duration: 1000, mask: false, success: function () { setTimeout(function () { wx.navigateTo({ url: `/pages/order/detail/index?orderId=${ that.data.orderId }` }); }, 1000) } }); //////////////////////////停车券 console.log(that.data.data.type) if (that.data.data.type == 5) { setTimeout(() => { wx.switchTab({ url: '/pages/passCar/passCar' }); }, 1600); } } } }) .catch(err => { console.log("ERR", err); }); } } });