// user/payment/payment.js const app = getApp(); const regeneratorRuntime = app.loadAsync() const model = app.loadModel("index") const http = app.loadHttp() Page({ /** * 页面的初始数据 */ data: { system: app.globalData.system, //设备相关信息 pageTitle: "订单支付", //头部标题 isBack: true,//显示返回, isLoading: true,//加载条 oreder: {},//订单信息 coupon: { id: 0, price: 0 },//优惠券信息, giftCard: {},//卡劵 isgiftCard: "",//拼接的卡劵信息方便操作 isPay: 2,//2微信支付 1卡支付 all: {},//总价格和差价 postage_money: {//邮费配置 satisfy_money: 0,//邮费 postage_money: 0,//未满指定免邮金额需要支付的邮费 }, }, // 支付 async pay(e) { let formId = e.detail.formId let payInfo = { orderID: this.data.oreder.orederId, payType: this.data.isPay, form_id: formId, userCouponID: 0, userCardID: 0 } if (!!this.data.coupon && !!this.data.coupon.price) { payInfo.userCouponID = this.data.coupon.id } if (this.data.isPay == 1) { payInfo.userCardID = this.data.giftCard.id } let api = http.api.preShopOrder if (this.data.oreder.type == 1) { api = http.api.pre_order } let res = await model.payment.pay(api, payInfo) if (res == 1) { wx.showToast({ title: '支付成功', icon: 'none', duration: 1000 }) // 改变变量使返回列表页刷新 app.globalData.isOrderList = true setTimeout(() => { wx.navigateBack({ delta: 2 }) }, 1000); return } }, // 获取优惠券 async getCoupon() { let coupon = await model.storage.getSetting("coupon") if (!!coupon) { model.storage.deleteStorage('coupon') this.setData({ coupon: coupon }) this.calculate() } }, // 获取卡劵 async getGiftCard() { let giftCard = await model.storage.getSetting("giftCard") if (!!giftCard) { model.storage.deleteStorage('giftCard') this.setData({ giftCard: giftCard, isgiftCard: giftCard.title + " " + giftCard.price + '折', isPay: 1 }) this.calculate() } }, // 选择支付方式 selectPay(e) { let type = e.currentTarget.dataset.type let url = e.currentTarget.dataset.url if (type == 2) { this.setData({ isgiftCard: "", giftCard: {}, isPay: type }) this.calculate() } else if (type == 1) { wx.navigateTo({ url: url }) } }, // 计算价格 async calculate() { let order = this.data.oreder.realPrice //订单价格 let fjPrice = parseInt(this.data.oreder.fjPrice) //洗衣附加费 let postage_money = this.data.postage_money // 邮寄费 let coupon = this.data.coupon.price || 0 // 优惠券 let giftCard = this.data.giftCard.price || 10 // 卡支付 let oreder = this.data.oreder // 上一个页面传来的信息 let oriPrice = order //洗衣订单减去附加费计算 let all = { allPrice: null, difPrice: null } // 商城 (总-优惠) + 邮费 if (!!oreder.type) { all = { allPrice: parseFloat((oriPrice - coupon).toFixed(2)), difPrice: parseFloat((oriPrice - (oriPrice - coupon)).toFixed(2)) || 0 } // 运费 // if (all.allPrice < postage_money.satisfy_money) { // all.allPrice += parseFloat(postage_money.postage_money) // } } else { let data = { orderID: this.data.oreder.orederId, payType: this.data.isPay, userCouponID: this.data.coupon.id || 0, userCardID: this.data.giftCard.id || 0 } let res = await http.http.request2({ url: `${http.api.shopOrderMoney}`, method: "POST", data: data }) if (res.data.status == 1) { if (oriPrice <= postage_money.satisfy_money) { oriPrice += postage_money.postage_money } all = { allPrice: res.data.data.totalPrice, difPrice: oriPrice - res.data.data.totalPrice || 0 } } } all.allPrice = all.allPrice.toFixed(2) all.difPrice = all.difPrice.toFixed(2) this.setData({ all: all }) }, // 获取邮费配置 async postage() { let order = this.data.oreder let type = !!order.type ? 1 : 2 let res = await http.http.request2({ url: `${http.api.postage}`, method: "POST", data: { type: type } }) this.setData({ postage_money: res.data.data }) this.calculate() }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ oreder: JSON.parse(options.data), }) this.postage() // 一秒后显示 setTimeout(() => { this.setData({ isLoading: false }) }, 1000) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.getCoupon() this.getGiftCard() }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })