123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369 |
- import {
- svipOrderCreateApi
- } from '@/api/activity.js';
- import {
- orderPayApi,
- orderExpressPayApi,
- orderSecondHandPayApi
- } from '@/api/order.js';
- import {
- ProductTypeEnum,
- } from "@/enums/productEnums";
- export default {
- data() {
- return {
- ProductTypeEnum: ProductTypeEnum,
- isBuy: false
- };
- },
- methods: {
-
- handleOrderPay(res,orderNo,productType,fromType,payType,payPrice){
- let jsConfig = res.data.jsConfig;
- let goPages = ''
- if(fromType==='svip'){
- goPages = `/pages/goods/order_pay_status/index?order_id=${orderNo}&payType=${payType}&payPrice=${payPrice}&fromType=${fromType}`;
- }else{
- if (fromType) {
- goPages = `/pages/goods/order_pay_status/index?order_id=${orderNo}&apiType=${fromType}`;
- } else {
- goPages = '/pages/goods/order_pay_status/index?order_id=' + orderNo;
- }
- }
- switch (res.data.payType) {
-
- case 'weixin':
- uni.hideLoading();
- this.weixinPay(jsConfig, orderNo, goPages,productType,fromType);
- break;
- case 'yue':
- uni.hideLoading();
- uni.reLaunch({
- url: goPages + '&status=1'
- });
- break;
- case 'h5':
- uni.hideLoading();
- setTimeout(() => {
- location.href = jsConfig.mwebUrl + '&redirect_url=' + window
- .location
- .protocol + '//' + window.location.host + goPages +
- '&status=1';
- }, 500)
- break;
- case 'alipay':
-
-
- uni.hideLoading();
- this.formContent = res.data.alipayRequest;
- this.$nextTick(() => {
- document.forms['punchout_form'].submit();
- })
- uni.setStorage({
- key: 'orderNo',
- data: orderNo
- });
- uni.setStorage({
- key: 'payResultfromType',
- data: fromType
- });
-
-
- let alipayRequest = res.data.alipayRequest;
- uni.requestPayment({
- provider: 'alipay',
- orderInfo: alipayRequest,
- success: (e) => {
- setTimeout(res => {
- uni.hideLoading();
- uni.navigateTo({
- url: `/pages/goods/alipay_return/alipay_return?out_trade_no=${orderNo}&payChannel=appAlipay&payPrice=${payPrice}&fromType=${fromType}`
- })
- }, 500)
- },
- fail: (e) => {
- uni.hideLoading();
- uni.showModal({
- content: "支付失败",
- showCancel: false,
- success: function(res) {
- if (res.confirm) {
-
- uni.navigateTo({
- url: '/pages/goods/alipay_return/alipay_return?out_trade_no=' +
- orderNo +
- '&payChannel=' +
- 'appAlipay'
- })
- }
- }
- })
- },
- complete: () => {
- uni.hideLoading();
- },
- });
-
- break;
- }
- },
-
- weixinPay(jsConfig, orderNo, goPages,productType,fromType) {
-
- if (productType === 'video') {
- uni.requestOrderPayment({
- timeStamp: jsConfig.timeStamp,
- nonceStr: jsConfig.nonceStr,
- package: jsConfig.packages,
- signType: jsConfig.signType,
- paySign: jsConfig.paySign,
- ticket: productType === 'normal' ? null : jsConfig.ticket,
- success: function(ress) {
- setTimeout(res => {
- uni.hideLoading();
- uni.reLaunch({
- url: goPages
- })
- }, 500);
- },
- fail: function(e) {
- uni.hideLoading();
- return this.$util.Tips({
- title: '取消支付'
- }, {
- tab: 5,
- url: goPages + '&status=2'
- });
- },
- complete: function(e) {
- uni.hideLoading();
-
- if (e.errMsg == 'requestPayment:cancel') return this.$util.Tips({
- title: '取消支付'
- }, {
- tab: 5,
- url: goPages + '&status=2'
- });
- },
- })
- } else {
- uni.requestPayment({
- timeStamp: jsConfig.timeStamp,
- nonceStr: jsConfig.nonceStr,
- package: jsConfig.packages,
- signType: jsConfig.signType,
- paySign: jsConfig.paySign,
- ticket: productType === 'normal' ? null : jsConfig.ticket,
- success: function(ress) {
- setTimeout(res => {
- uni.hideLoading();
- uni.reLaunch({
- url: goPages
- })
- }, 500);
- },
- fail: function(e) {
- uni.hideLoading();
- return this.$util.Tips({
- title: '取消支付'
- }, {
- tab: 5,
- url: goPages + '&status=2'
- });
- },
- complete: function(e) {
- uni.hideLoading();
-
- if (e.errMsg == 'requestPayment:cancel') return this.$util.Tips({
- title: '取消支付'
- }, {
- tab: 5,
- url: goPages + '&status=2'
- });
- },
- })
- }
-
-
- let data = {
- timestamp: jsConfig.timeStamp,
- nonceStr: jsConfig.nonceStr,
- package: jsConfig.packages,
- signType: jsConfig.signType,
- paySign: jsConfig.paySign
- };
- if (this.$wechat.isWeixin()) {
- this.$wechat.pay(data).then(res => {
- setTimeout(res => {
- uni.hideLoading();
- uni.redirectTo({
- url: goPages
- })
- }, 500);
- }).catch(res => {
- uni.hideLoading();
- return this.$util.Tips({
- title: '取消支付'
- }, {
- tab: 5,
- url: goPages + '&status=2'
- });
- });
- } else {
- setTimeout(() => {
- location.href = jsConfig.mwebUrl + '&redirect_url=' + window.location.protocol + '//' + window.location.host + goPages;
- }, 100)
- uni.hideLoading();
- }
-
-
- let mp_pay_name = ''
- if (uni.requestOrderPayment) {
- mp_pay_name = 'requestOrderPayment'
- } else {
- mp_pay_name = 'requestPayment'
- }
- uni[mp_pay_name]({
- provider: 'wxpay',
- orderInfo: {
- "appid": jsConfig.appId,
- "noncestr": jsConfig.nonceStr,
- "package": "Sign=WXPay",
- "partnerid": jsConfig.partnerid,
- "prepayid": jsConfig.packages,
- "timestamp": Number(jsConfig.timeStamp),
- "sign": this.systemPlatform === 'ios' ? 'MD5' : jsConfig.paySign
- },
- success: function(res) {
- uni.hideLoading();
- setTimeout(res => {
- uni.redirectTo({
- url: goPages
- })
- }, 500)
- },
- fail: function(err) {
- uni.hideLoading();
- uni.showModal({
- content: "支付失败",
- showCancel: false,
- success: function(res) {
- if (res.confirm) {
- uni.redirectTo({
- url: goPages + '&status=2'
- })
- }
- }
- })
- },
- complete: (err) => {
- uni.hideLoading();
- }
- });
-
- },
-
- svipOnCreateOrder(data, orderNo,payType,payPrice,fromType) {
- svipOrderCreateApi(data).then(res => {
- let jsConfig = res.data.jsConfig;
- let goPages = `/pages/goods/order_pay_status/index?order_id=${res.data.orderNo}&payType=${payType}&payPrice=${payPrice}&fromType=${fromType}`;
- this.weixinPay(jsConfig, res.data.orderNo, goPages,'normal',fromType)
- }).catch(err => {
- uni.hideLoading();
- return this.$util.Tips({
- title: err
- });
- });
- },
-
-
- getToPayment(secondType,data,fromType) {
- let url = `/pages/goods/order_payment/index?orderNo=${data.orderNo}&payPrice=${data.payPrice}&fromType=${fromType}`
-
-
-
-
-
-
- uni.redirectTo({
- url: url
- });
- },
-
-
- changeOrderPay(orderNo, payChannel, payType ,productType, fromType, payPrice) {
- let api = fromType == 'fast' ? orderExpressPayApi : fromType == 'secondHand' ? orderSecondHandPayApi : orderPayApi;
- api({
- orderNo: orderNo,
- payChannel: payChannel,
- payType: payType,
- scene: productType === 'normal' ? 0 : 1177
-
- }).then(res => {
- this.handleOrderPay(res, orderNo, productType, fromType, payType, payPrice)
- }).catch(err => {
- uni.hideLoading();
- this.isBuy = false;
- return this.$util.Tips({
- title: err
- });
- });
- },
-
-
- changeOrderExpressPay(orderNo, payChannel, payType ,productType, fromType, payPrice) {
- orderExpressPayApi({
- orderNo: orderNo,
- payChannel: payChannel,
- payType: payType,
- scene: productType === 'normal' ? 0 : 1177
-
- }).then(res => {
- this.handleOrderPay(res, orderNo, productType, fromType, payType, payPrice)
- }).catch(err => {
- uni.hideLoading();
- this.isBuy = false;
- return this.$util.Tips({
- title: err
- });
- });
- }
- }
- };
|