tmp: 部分代码与UnishopV5结合,但是代码有严重缺陷
This commit is contained in:
@@ -15,18 +15,20 @@
|
||||
<view class="payment-item" v-if="balanceDeduct > 0 && balanceUsable && balanceConfig == 1">
|
||||
<view class="iconfont icon-yue"></view>
|
||||
<view class="info-wrap">
|
||||
<text class="name">余额支付</text>
|
||||
<text class="name">余额抵扣</text>
|
||||
<view class="money">可用¥{{ balanceDeduct|moneyFormat }}</view>
|
||||
</view>
|
||||
<ns-switch class="balance-switch" @change="useBalance" :checked="isBalance == 1"></ns-switch>
|
||||
</view>
|
||||
<block v-if="payMoney > 0">
|
||||
<block v-if="payTypeList.length">
|
||||
<view class="payment-item" v-for="(item, index) in payTypeList" :key="index" @click="payIndex = index">
|
||||
<view class="iconfont" :class="item.icon"></view>
|
||||
<text class="name">{{ item.name }}</text>
|
||||
<text class="iconfont" :class="payIndex == index ? 'icon-yuan_checked color-base-text' : 'icon-checkboxblank'"></text>
|
||||
</view>
|
||||
<block v-for="(item, index) in payTypeList">
|
||||
<view v-if="offlineShow||item.type!='offlinepay'" class="payment-item" :key="index" @click="payIndex = index">
|
||||
<view class="iconfont" :class="item.icon"></view>
|
||||
<text class="name">{{ item.name }}</text>
|
||||
<text class="iconfont" :class="payIndex == index ? 'icon-yuan_checked color-base-text' : 'icon-checkboxblank'"></text>
|
||||
</view>
|
||||
</block>
|
||||
</block>
|
||||
<block v-else>
|
||||
<view class="empty">平台尚未配置支付方式!</view>
|
||||
@@ -63,47 +65,44 @@
|
||||
balanceUsable: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
}
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
payIndex: 0,
|
||||
// #ifdef H5
|
||||
payTypeList: [{
|
||||
payTypeList: [
|
||||
// #ifdef H5 || MP-ALIPAY
|
||||
{
|
||||
name: '支付宝支付',
|
||||
icon: 'icon-zhifubaozhifu-',
|
||||
type: 'alipay'
|
||||
},
|
||||
// #endif
|
||||
// #ifdef H5 || MP-WEIXIN
|
||||
{
|
||||
name: '微信支付',
|
||||
icon: 'icon-weixin1',
|
||||
type: 'wechatpay'
|
||||
}
|
||||
},
|
||||
// #endif
|
||||
{
|
||||
name: '线下支付',
|
||||
icon: 'icondiy icon-yuezhifu',
|
||||
type: 'offlinepay'
|
||||
},
|
||||
],
|
||||
// #ifdef H5
|
||||
timer: null,
|
||||
// #endif
|
||||
// #ifdef MP-WEIXIN
|
||||
payTypeList: [{
|
||||
name: '微信支付',
|
||||
provider: 'wxpay',
|
||||
icon: 'icon-weixin1',
|
||||
type: 'wechatpay'
|
||||
}],
|
||||
// #endif
|
||||
// #ifdef MP-ALIPAY
|
||||
payTypeList: [{
|
||||
name: '支付宝支付',
|
||||
icon: 'icon-zhifubaozhifu-',
|
||||
type: 'alipay',
|
||||
provider: 'alipay'
|
||||
}],
|
||||
// #endif
|
||||
// #endif
|
||||
payInfo: null,
|
||||
balanceConfig: 0,
|
||||
// 预售页面判断
|
||||
sale: true,
|
||||
isBalance: 0,
|
||||
balance: 0
|
||||
balance: 0,
|
||||
//重置是否已完成,没有完成不能调用api/pay/pay
|
||||
resetPayComplete:true,
|
||||
repeatFlag:false,
|
||||
};
|
||||
},
|
||||
created(e) {
|
||||
@@ -127,9 +126,32 @@
|
||||
}
|
||||
}
|
||||
return money;
|
||||
}
|
||||
},
|
||||
offlineShow(){
|
||||
// 获取当前页面栈实例数组
|
||||
const pages = getCurrentPages();
|
||||
const currentPage = pages[pages.length - 1];
|
||||
// 获取页面路由路径
|
||||
let routePath = currentPage.route;
|
||||
return this.$store.state.offlineWhiteList.length?this.$store.state.offlineWhiteList.includes(routePath):false
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* 父级页面onShow调用
|
||||
*/
|
||||
pageShow() {
|
||||
if(this.payInfo){
|
||||
let offlinepay = uni.getStorageSync('offlinepay');
|
||||
if(offlinepay){
|
||||
uni.removeStorageSync('offlinepay');
|
||||
this.close()
|
||||
}
|
||||
}else{
|
||||
uni.removeStorageSync('offlinepay');
|
||||
}
|
||||
|
||||
},
|
||||
close() {
|
||||
this.$emit('close');
|
||||
this.$refs.choosePaymentPopup.close();
|
||||
@@ -146,14 +168,22 @@
|
||||
});
|
||||
return;
|
||||
}
|
||||
if(this.resetPayComplete == false){
|
||||
this.$util.showToast({
|
||||
title: '支付取消中,请稍后再试!'
|
||||
});
|
||||
return;
|
||||
}
|
||||
uni.showLoading({
|
||||
title: '支付中...',
|
||||
mask: true
|
||||
});
|
||||
if(this.repeatFlag) return;
|
||||
this.repeatFlag = true;
|
||||
this.pay();
|
||||
uni.setStorageSync('pay_flag', 1);
|
||||
},
|
||||
getPayInfo(out_trade_no) {
|
||||
getPayInfo(out_trade_no, callback) {
|
||||
this.$api.sendRequest({
|
||||
url: '/api/pay/info',
|
||||
data: {
|
||||
@@ -165,6 +195,7 @@
|
||||
if (this.balanceConfig && this.balanceUsable) this.getMemberBalance();
|
||||
setTimeout(() => {
|
||||
this.$refs.choosePaymentPopup.open();
|
||||
if(typeof callback == 'function') callback();
|
||||
})
|
||||
} else {
|
||||
this.$util.showToast({
|
||||
@@ -178,7 +209,6 @@
|
||||
* 获取余额配置
|
||||
*/
|
||||
getBalanceConfig() {
|
||||
|
||||
this.$api.sendRequest({
|
||||
url: '/api/pay/getBalanceConfig',
|
||||
data: {},
|
||||
@@ -196,10 +226,6 @@
|
||||
success: res => {
|
||||
if (res.code == 0 && res.data) {
|
||||
this.balance = parseFloat(res.data.usable_balance);
|
||||
//余额不足以抵扣整个订单时不显示
|
||||
if(parseFloat(this.payMoney) > this.balance){
|
||||
this.balanceConfig = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -215,10 +241,8 @@
|
||||
if (res.data.pay_type == '') {
|
||||
this.payTypeList = [];
|
||||
} else {
|
||||
this.payTypeList.forEach((val, key) => {
|
||||
if (res.data.pay_type.indexOf(val.type) == -1) {
|
||||
this.payTypeList.splice(key, 1);
|
||||
}
|
||||
this.payTypeList = this.payTypeList.filter((val, key) => {
|
||||
return res.data.pay_type.indexOf(val.type) != -1
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -239,8 +263,7 @@
|
||||
data: {
|
||||
out_trade_no: this.payInfo.out_trade_no,
|
||||
pay_type: payType ? payType.type : '',
|
||||
return_url: encodeURIComponent(this.$config.h5Domain + return_url + this.payInfo
|
||||
.out_trade_no),
|
||||
return_url: encodeURIComponent(this.$config.h5Domain + return_url + this.payInfo.out_trade_no),
|
||||
is_balance: this.isBalance
|
||||
},
|
||||
success: res => {
|
||||
@@ -258,7 +281,9 @@
|
||||
wx_alipay: wx_alipay,
|
||||
out_trade_no: this.payInfo.out_trade_no
|
||||
}, '', 'redirectTo');
|
||||
this.repeatFlag = false;
|
||||
} else {
|
||||
this.repeatFlag = false;
|
||||
location.href = res.data.data;
|
||||
this.checkPayStatus();
|
||||
}
|
||||
@@ -290,12 +315,14 @@
|
||||
res => {
|
||||
if (res.errMsg == 'chooseWXPay:ok') {
|
||||
this.paySuccess();
|
||||
this.repeatFlag = false;
|
||||
} else {
|
||||
this.$util.showToast({
|
||||
title: res.errMsg
|
||||
});
|
||||
setTimeout(() => {
|
||||
this.close();
|
||||
this.repeatFlag = false;
|
||||
}, 1500)
|
||||
}
|
||||
},
|
||||
@@ -304,20 +331,30 @@
|
||||
title: '您已取消支付'
|
||||
});
|
||||
this.resetpay();
|
||||
this.repeatFlag = false;
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.repeatFlag = false;
|
||||
location.href = res.data.url;
|
||||
this.checkPayStatus();
|
||||
}
|
||||
break;
|
||||
case 'offlinepay':
|
||||
this.$util.redirectTo('/pages_tool/pay/offlinepay', {
|
||||
outTradeNo: this.payInfo.out_trade_no
|
||||
});
|
||||
this.repeatFlag = false;
|
||||
break;
|
||||
|
||||
}
|
||||
} else {
|
||||
this.$util.showToast({
|
||||
title: res.message
|
||||
});
|
||||
this.repeatFlag = false;
|
||||
}
|
||||
},
|
||||
fail: res => {
|
||||
@@ -325,6 +362,7 @@
|
||||
this.$util.showToast({
|
||||
title: 'request:fail'
|
||||
});
|
||||
this.repeatFlag = false;
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -365,72 +403,87 @@
|
||||
if (res.code >= 0) {
|
||||
if (res.data.pay_success) {
|
||||
this.paySuccess();
|
||||
this.repeatFlag = false;
|
||||
return;
|
||||
}
|
||||
var payData = res.data.data;
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
var scene = uni.getStorageSync('is_test') ? 1175 : wx.getLaunchOptionsSync().scene;
|
||||
if ([1175, 1176, 1177, 1191, 1195].indexOf(scene) != -1) {
|
||||
uni.requestOrderPayment({
|
||||
timeStamp: payData.timeStamp,
|
||||
nonceStr: payData.nonceStr,
|
||||
package: payData.package,
|
||||
signType: payData.signType,
|
||||
paySign: payData.paySign,
|
||||
success: res => {
|
||||
this.paySuccess();
|
||||
},
|
||||
fail: res => {
|
||||
this.flag = false;
|
||||
if (res.errMsg == 'requestOrderPayment:fail cancel') {
|
||||
this.$util.showToast({
|
||||
title: '您已取消支付'
|
||||
});
|
||||
this.resetpay();
|
||||
} else {
|
||||
uni.showModal({
|
||||
content: '支付失败,失败原因: ' + res.errMsg,
|
||||
showCancel: false
|
||||
});
|
||||
setTimeout(() => {
|
||||
this.close();
|
||||
}, 1500)
|
||||
}
|
||||
}
|
||||
});
|
||||
return
|
||||
}
|
||||
// #endif
|
||||
|
||||
uni.requestPayment({
|
||||
provider: payType.provider,
|
||||
...payData,
|
||||
success: res => {
|
||||
this.paySuccess();
|
||||
},
|
||||
fail: res => {
|
||||
this.flag = false;
|
||||
if (res.errMsg == 'requestPayment:fail cancel') {
|
||||
this.$util.showToast({
|
||||
title: '您已取消支付'
|
||||
});
|
||||
this.resetpay();
|
||||
} else {
|
||||
uni.showModal({
|
||||
content: '支付失败,失败原因: ' + res.errMsg,
|
||||
showCancel: false
|
||||
});
|
||||
setTimeout(() => {
|
||||
this.close();
|
||||
}, 1500)
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (payType.type=='offlinepay') {
|
||||
this.$util.redirectTo('/pages_tool/pay/offlinepay', {
|
||||
outTradeNo: this.payInfo.out_trade_no
|
||||
});
|
||||
this.repeatFlag = false;
|
||||
}else{
|
||||
var payData = res.data.data;
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
var scene = uni.getStorageSync('is_test') ? 1175 : wx.getLaunchOptionsSync().scene;
|
||||
if ([1175, 1176, 1177, 1191, 1195].indexOf(scene) != -1) {
|
||||
uni.requestOrderPayment({
|
||||
timeStamp: payData.timeStamp,
|
||||
nonceStr: payData.nonceStr,
|
||||
package: payData.package,
|
||||
signType: payData.signType,
|
||||
paySign: payData.paySign,
|
||||
success: res => {
|
||||
this.paySuccess();
|
||||
this.repeatFlag = false;
|
||||
},
|
||||
fail: res => {
|
||||
this.flag = false;
|
||||
if (res.errMsg == 'requestOrderPayment:fail cancel') {
|
||||
this.$util.showToast({
|
||||
title: '您已取消支付'
|
||||
});
|
||||
this.resetpay();
|
||||
this.repeatFlag = false;
|
||||
} else {
|
||||
uni.showModal({
|
||||
content: '支付失败,失败原因: ' + res.errMsg,
|
||||
showCancel: false
|
||||
});
|
||||
setTimeout(() => {
|
||||
this.close();
|
||||
this.repeatFlag = false;
|
||||
}, 1500)
|
||||
}
|
||||
}
|
||||
});
|
||||
return
|
||||
}
|
||||
// #endif
|
||||
|
||||
uni.requestPayment({
|
||||
provider: payType.provider,
|
||||
...payData,
|
||||
success: res => {
|
||||
this.paySuccess();
|
||||
this.repeatFlag = false;
|
||||
},
|
||||
fail: res => {
|
||||
this.flag = false;
|
||||
if (res.errMsg == 'requestPayment:fail cancel') {
|
||||
this.$util.showToast({
|
||||
title: '您已取消支付'
|
||||
});
|
||||
this.resetpay();
|
||||
this.repeatFlag = false;
|
||||
} else {
|
||||
uni.showModal({
|
||||
content: '支付失败,失败原因: ' + res.errMsg,
|
||||
showCancel: false
|
||||
});
|
||||
setTimeout(() => {
|
||||
this.close();
|
||||
this.repeatFlag = false;
|
||||
}, 1500)
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
this.$util.showToast({
|
||||
title: res.message
|
||||
});
|
||||
this.repeatFlag = false;
|
||||
}
|
||||
},
|
||||
fail: res => {
|
||||
@@ -438,6 +491,7 @@
|
||||
this.$util.showToast({
|
||||
title: 'request:fail'
|
||||
});
|
||||
this.repeatFlag = false;
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -463,14 +517,24 @@
|
||||
* 重置支付单据
|
||||
*/
|
||||
resetpay() {
|
||||
this.resetPayComplete = false;
|
||||
this.$api.sendRequest({
|
||||
url: '/api/pay/resetpay',
|
||||
data: {
|
||||
out_trade_no: this.payInfo.out_trade_no,
|
||||
},
|
||||
success: res => {
|
||||
if (res.code == 0) this.getPayInfo(res.data);
|
||||
}
|
||||
if (res.code == 0) {
|
||||
this.getPayInfo(res.data, ()=>{
|
||||
this.resetPayComplete = true;
|
||||
});
|
||||
}else{
|
||||
this.resetPayComplete = true;
|
||||
}
|
||||
},
|
||||
fail:res =>{
|
||||
this.resetPayComplete = true;
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
@@ -569,7 +633,9 @@
|
||||
.icon-weixin1 {
|
||||
color: #24af41;
|
||||
}
|
||||
|
||||
.icon-yuezhifu{
|
||||
color: #f9a647;
|
||||
}
|
||||
.icon-zhifubaozhifu- {
|
||||
color: #00a0e9;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user