| | |
| | | |
| | | const askModal = { |
| | | $modal: null, |
| | | _callback: null, |
| | | show(type, callback) { |
| | | this._callback = callback; |
| | | const that = this; |
| | | Taro.showModal({ |
| | | title: type === 'ask' ? '微信支付未响应?' : '微信支付仍未响应?', |
| | | content: type === 'ask' ? '微信支付未响应?' : '微信支付仍未响应?', |
| | | confirmColor: '#4a8aff', |
| | | confirmText: type === 'ask' ? '点击重试' : '重载页面', |
| | | success: res => { |
| | | // 点击重试,执行回调 |
| | | if (res.confirm) { |
| | | callback(true); |
| | | that._callback && that._callback(true); |
| | | } else if (res.cancel) { |
| | | callback(false); |
| | | that._callback && that._callback(false); |
| | | } |
| | | this.$modal = null; |
| | | }, |
| | | }); |
| | | setTimeout(() => { |
| | | this.$modal = $('.taro__modal'); |
| | | this.$modal.find('>div>div').css('textAlign', 'center'); |
| | | }, 10); |
| | | }, |
| | | cancel() { |
| | | this._callback = null; // 关闭回调,关闭弹窗不取消订单 |
| | | if (this.$modal) { |
| | | this.$modal.find('.taro-modal__foot > .taro-model__btn:eq(0)').trigger('click'); |
| | | this.$modal = null; |
| | |
| | | }; |
| | | } |
| | | |
| | | askModal = askModal; |
| | | |
| | | callWxPay(payParam, callback, type = 'webview') { |
| | | // 默认 webview 支付 |
| | | if (type === 'webview') { |
| | |
| | | // 2.2 秒后,如果 alreadyCall 未变为 true,跳出询问弹窗 |
| | | setTimeout(() => { |
| | | if (!this._data.alreadyCall) { |
| | | askModal.show('ask', next => { |
| | | this.askModal.show('ask', next => { |
| | | if (next) { |
| | | this.callWxPay(payParam, callback, 'webview2'); |
| | | } else { |
| | |
| | | // 2.2 秒后,如果 alreadyCall 未变为 true,跳出询问弹窗 |
| | | setTimeout(() => { |
| | | if (!this._data.alreadyCall) { |
| | | askModal.show('reload', next => { |
| | | this.askModal.show('reload', next => { |
| | | if (next) { |
| | | callback('fail', '页面重载中...'); |
| | | window._hmt.push(['_trackEvent', 'wx', 'wx-wxPay', 'wx-wxPay-pageReload', 0]); |
| | |
| | | window.location.href.split(/[#?]/)[0] + '?' + window.location.hash; |
| | | } |
| | | window.location.reload(); |
| | | }, 1000); |
| | | }, 1500); |
| | | } else { |
| | | callback('cancel', '支付已取消!(微信未响应)'); |
| | | window._hmt.push(['_trackEvent', 'wx', 'wx-wxPay', 'wx-wxPay-noResponse', 0]); |
| | |
| | | timestamp: sign.timeStamp, |
| | | complete: complete => { |
| | | // 关闭询问弹窗 |
| | | askModal.cancel(); |
| | | this.askModal.cancel(); |
| | | this._data.alreadyCall = true; |
| | | // 支付结果 |
| | | if (complete.errMsg === 'chooseWXPay:ok') { |
| | |
| | | const sign = JSON.parse(payParam); |
| | | WeixinJSBridge.invoke('getBrandWCPayRequest', sign, res => { |
| | | // 关闭询问弹窗 |
| | | askModal.cancel(); |
| | | this.askModal.cancel(); |
| | | this._data.alreadyCall = true; |
| | | // 支付结果 |
| | | if (res.err_msg === 'get_brand_wcpay_request:ok') { |