123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- const {
- default: api
- } = require("../../js/api");
- const util = require('../../utils/util.js')
- Page({
-
- data: {
- nozzleId: 0,
- type: '预支付',
- order: null,
- },
-
- onLoad(options) {
- this.setData({
- nozzleId:options.nozzleId
- })
- const that = this;
- const eventChannel = this.getOpenerEventChannel();
- eventChannel.on('acceptDataFromQuantify', function (data) {
- console.log("获取到下单页的订单",data)
- that.setData({
- order:data
- })
- });
- },
-
- onReady() {
- },
-
- onShow() {
- },
-
- onHide() {
- },
-
- onUnload() {
- },
-
- onPullDownRefresh() {
- },
-
- onReachBottom() {
- },
-
- onShareAppMessage() {
- },
-
- toPay() {
- var that = this;
- api.request_wechatPay(this.data.order.orderId).then(res => {
- console.log("支付结果", res)
- that.subMessage()
-
- }).catch(err => {
- console.log("支付失败", err)
- })
- },
-
- subMessage() {
- const that = this;
- wx.requestSubscribeMessage({
- tmplIds: ['V0tl-4n-5hwNZc4SrEttvrmawAyM-SB0pQWZNwp54Ks'],
- success(res) {
- that.pay()
-
- if (res['V0tl-4n-5hwNZc4SrEttvrmawAyM-SB0pQWZNwp54Ks'] === 'accept') {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- },
- fail(err) {
- that.pay()
- }
- })
- },
- pay() {
- const that = this;
- api.request_wechatPay(this.data.order.orderId)
- .then(res => {
- wx.requestPayment({
- timeStamp: res.data.data.unifiedOrderResult.timeStamp,
- nonceStr: res.data.data.unifiedOrderResult.nonceStr,
- package: res.data.data.unifiedOrderResult.package,
- signType: res.data.data.unifiedOrderResult.signType,
- paySign: res.data.data.unifiedOrderResult.paySign,
- success: res => {
- wx.hideLoading()
- that.sendMessage()
- that.toPayResult(1)
- },
- fail: res => {
- wx.hideLoading()
- that.toPayResult(2)
- }
- })
- });
- },
-
- sendMessage() {
- const message = {
- trxid: this.data.order.orderId,
- orderType: '支付'
- }
- api.request_sendMessage(message).then(res => {
- console.log("发送消息模板结果", res)
- }).catch(err => {
- console.log("发送消息模板失败", err)
- })
- },
-
- toPayResult(type){
- const that = this;
- setTimeout(() => {
- wx.navigateTo({
- url: '../payStatus/payStatus?id='+type+'&nozzleId='+that.data.nozzleId,
- success:function(res){
- res.eventChannel.emit('acceptDataFromAuthorization',that.data.order)
- }
- })
- },500)
- }
- })
|