Files
dou_fire/pages/pay/pay.vue
唐明明 d81577bcac merge
2023-03-07 16:02:11 +08:00

395 lines
9.2 KiB
Vue

<template>
<view class="pay">
<!-- 支付金额 -->
<view class="header">
<view class="header-title">实付金额</view>
<view class="header-price"><text></text>{{total}}</view>
<view class="header-no">订单号:{{orderNo}}</view>
</view>
<!-- 选择支付方式 -->
<view class="choose">
<radio-group @change="payMethod = $event.detail.value" >
<label class="choose-item" v-if="payType != 'free'">
<view class="choose-text nowrap">
<image src="@/static/icons/pay_alipay.png" mode="aspectFill"></image>
火力值支付
</view>
<radio class="choose-radio" value="coin" :checked="payMethod == 'coin'"></radio>
</label>
<!-- <label class="choose-item nowrap">
<view class="choose-text">
<image src="@/static/icons/pay_code.png" mode="aspectFill"></image>
付款码支付
</view>
<radio class="choose-radio" value="code"></radio>
</label> -->
<label class="choose-item nowrap">
<view class="choose-text">
<image src="@/static/icons/pay_wechat.png" mode="aspectFill"></image>
微信支付
</view>
<radio class="choose-radio" value="wx" :checked="payMethod == 'wx'"></radio>
</label>
<label class="choose-item nowrap">
<view class="choose-text">
<image src="@/static/icons/pay_ali.png" mode="aspectFill"></image>
支付宝支付
</view>
<radio class="choose-radio" value="ali" :checked="payMethod == 'ali'"></radio>
</label>
</radio-group>
</view>
<!-- 确认支付 -->
<view class="payBtn">
<button size="default" @click="onPay">支付</button>
</view>
</view>
</template>
<script>
import { info } from '@/apis/interfaces/order.js'
import { coinPay, diffCoinPay, umsPay, umsState, diffUmsPay, umsFree, umsFreeInfo } from '@/apis/interfaces/pay.js'
export default {
data() {
return {
getState : false,
trade_id : '',
orderId : '',
diffId : '',
payMethod : 'coin',
payType : 'price',
total : '0.00',
orderNo : '',
};
},
onShow() {
if(this.getState && this.trade_id != ''){
// 查询支付状态
uni.showLoading({
title: '查询支付结果...',
mask : true
})
let outTime;
let resNumb = 0;
outTime = setInterval(() => {
if(resNumb >= 3){
clearInterval(outTime)
uni.showToast({
title: '暂未查询到你的支付订单',
icon : 'none'
})
return
}
umsState(this.trade_id).then(res => {
resNumb++
if(res.state === 'success'){
clearInterval(outTime)
wx.showModal({
title : '提示',
content : '支付成功',
showCancel : false,
confirmColor: '#446EFE',
success : () => {
this.onRrmoveItem()
}
})
}
}).catch(err => {
clearInterval(outTime)
uni.showToast({
title: err.message,
icon : 'none'
})
})
}, 2000)
}
},
created() {
uni.showLoading({
title: '获取订单信息...',
mask : true
})
if(this.$Route.query.paytype === 'free'){
this.payMethod = "wx"
umsFreeInfo(this.$Route.query.serviceId).then(res => {
let { order_id, price, order_no } = res;
this.orderId = order_id
this.total = price
this.orderNo = order_no
this.payType = this.$Route.query.paytype
uni.hideLoading()
}).catch(err => {
uni.showToast({
title: err.message,
icon : 'none'
})
})
return
}
info(this.$Route.query.orderId).then(res => {
let { total, order_no, business_order_id, diff_prices, diff } = res
this.orderId = business_order_id
this.diffId = diff.business_order_diff_price_id
this.payType = this.$Route.query.paytype
this.total = this.payType === 'diff' ? diff_prices: total
this.orderNo = order_no
uni.hideLoading()
}).catch(err => {
uni.showToast({
title: err.message,
icon : 'none'
})
})
},
methods: {
// 支付方式
onPay(){
switch(this.payMethod){
case 'coin':
if(this.payType == 'price') this.onCoinPay()
if(this.payType == 'diff') this.onDiffCoinPay()
break;
case 'code':
uni.showToast({
title: '付款码支付暂未开放,请敬期待',
icon : 'none'
})
break;
case 'wx':
if(this.payType == 'price') this.onUmsPay('mp')
if(this.payType == 'diff') this.onDiffUmsPay('mp')
if(this.payType == 'free') this.onFreePay('mp')
break;
case 'ali':
if(this.payType == 'price') this.onUmsPay('mp_alipay')
if(this.payType == 'diff') this.onDiffUmsPay('mp_alipay')
if(this.payType == 'free') this.onFreePay('mp_alipay')
break;
}
},
// 银联三方支付
onUmsPay(type){
uni.showLoading({
title: '加载中...',
mask : true
})
umsPay(this.orderId, { type }).then(res => {
uni.hideLoading()
this.getState = true
this.trade_id = res.trade_id
switch (type){
case 'mp':
this.onMiniWx()
break;
case 'mp_alipay':
plus.runtime.openURL(res.alipay)
break;
}
}).catch(err => {
uni.showToast({
title: err.message,
icon : 'none'
})
})
},
// 银联三方补差价支付
onDiffUmsPay(type){
uni.showLoading({
title: '加载中...',
mask : true
})
diffUmsPay(this.diffId, {type}).then(res => {
uni.hideLoading()
this.getState = true
this.trade_id = res.trade_id
switch (type){
case 'mp':
this.onMiniWx()
break;
case 'mp_alipay':
plus.runtime.openURL(res.alipay)
break;
}
}).catch(err => {
uni.showToast({
title: err.message,
icon : 'none'
})
})
},
// 银联三方自由服务包支付
onFreePay(type){
wx.showLoading({
title: '加载中...',
mask : true
})
umsFree(this.orderId, type).then(res => {
uni.hideLoading()
this.getState = true
this.trade_id = res.trade_id
switch (type){
case 'mp':
this.onMiniWx()
break;
case 'mp_alipay':
plus.runtime.openURL(res.alipay)
break;
}
}).catch(err => {
uni.showToast({
title: err.message,
icon : 'none'
})
})
},
// 火力值支付
onCoinPay(){
wx.showLoading({
title: '支付中...',
mask : true
})
coinPay(this.orderId).then(res => {
wx.showModal({
title : '提示',
content : '代缴费成功,请提醒用户尽快签约并完善资料',
showCancel : false,
confirmColor: '#446EFE',
success : () => {
this.onRrmoveItem()
}
})
}).catch(err => {
uni.showToast({
title: err.message,
icon : 'none'
})
})
},
// 火力值补差价支付
onDiffCoinPay(){
diffCoinPay(this.diffId).then(res => {
wx.showModal({
title : '提示',
content : '补缴差价成功',
showCancel : false,
confirmColor: '#446EFE',
success : () => {
this.onRrmoveItem()
}
})
}).catch(err => {
uni.showToast({
title: err.message,
icon : 'none'
})
})
},
// 打开微信小程序收银台
onMiniWx(){
let token = this.$store.getters.getToken
let tradeId = this.trade_id
plus.share.getServices(e => {
let wxIndex = e.findIndex(val => val.id == 'weixin')
let sweixin = null
if(wxIndex >= 0){
sweixin = e[wxIndex]
sweixin ? sweixin.launchMiniProgram({
id : 'gh_918c81628d6f',
path: 'pages/pay/pay?type=app&trade_id=' + tradeId + '&token=' + token,
}): uni.showToast({
title: '当前环境暂不支持微信支付',
icon : 'none'
})
}
})
},
// 更新订单列表
onRrmoveItem(){
this.$store.commit('setOrderId', this.orderId)
this.$Router.back()
}
}
}
</script>
<style lang="scss">
.pay{
background: #f8f8f8;
height: 100vh;
width: 100vw;
padding: 30rpx 30rpx 60rpx;
box-sizing: border-box;
.header{
padding: 80rpx 0 100rpx;
text-align: center;
.header-title{
font-size: 32rpx;
padding-bottom: 10rpx;
}
.header-price{
font-size: 68rpx;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
text{
font-size: 60%;
}
}
.header-no{
padding-top: 20rpx;
font-size: 28rpx;
color: gray;
}
}
// 选择支付方式
.choose{
background-color: white;
border-radius: 20rpx;
padding: 10rpx 30rpx;
.choose-item{
display: block;
padding: 20rpx 0;
display: flex;
justify-content: space-between;
align-items: center;
&:last-child{
border-bottom: none;
}
.choose-text{
line-height: 80rpx;
font-size: 32rpx;
padding-left: 80rpx;
position: relative;
image{
position: absolute;
left: 0;
top: 15rpx;
width: 50rpx;
height: 50rpx;
border-radius: 10rpx;
}
}
.choose-radio{
transform:scale(0.8)
}
}
}
// 按钮
.payBtn{
padding: 50rpx 0;
button[size="default"]{
height: 100rpx;
line-height: 100rpx;
padding: 0;
border-radius: 20rpx;
background-color: $main-color;
color: white;
font-size: 32rpx;
font-weight: bold;
&::after{
display: none;
}
}
}
}
</style>