Commit 57d42869 by huangzhi

feat: 集成h5端收银台

parent 5013b8f8
...@@ -77,6 +77,7 @@ ...@@ -77,6 +77,7 @@
"flyio": "^0.6.2", "flyio": "^0.6.2",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"uview-ui": "^2.0.35", "uview-ui": "^2.0.35",
"decimal.js": "^10.4.3",
"vue": "^2.6.11", "vue": "^2.6.11",
"vuex": "^3.2.0" "vuex": "^3.2.0"
}, },
......
...@@ -208,15 +208,18 @@ export default { ...@@ -208,15 +208,18 @@ export default {
}, },
// 跳转订单 // 跳转订单
navigateToOrder() { navigateToOrder() {
if (!this.isLogin) {
this.handleLogin()
return
}
const url = `${hostPrefix}/h5-course/my/components/Buylist`
uni.navigateTo({ uni.navigateTo({
url: `/pages/web/web?title=已购订单&loadUrl=${encodeURIComponent(url)}`, url: `/pages/pay/pay?title=支付&id=${1123}`,
}) })
// if (!this.isLogin) {
// this.handleLogin()
// return
// }
// const url = `${hostPrefix}/h5-course/my/components/Buylist`
// uni.navigateTo({
// url: `/pages/web/web?title=已购订单&loadUrl=${encodeURIComponent(url)}`,
// })
}, },
}, },
} }
......
<template> <template>
<view class="pay-page"> <view class="pay-page">
<view class="order-info"> <div>正在支付中.12...</div>
<view class="info-item"> <div>正在支付中.22...</div>
<view class="label">倾诉服务</view> <div>正在支付中.32...</div>
<text class="value">{{ price }}</text>
</view>
<view class="info-item">
<view class="label">优惠</view>
<text class="value">{{ coupon > 0 ? `-¥${coupon}` : '暂无可用优惠' }}</text>
</view>
<view class="info-item">
<view class="label">可用余额</view>
<text class="value">{{ balance }}</text>
</view>
<view class="info-item">
<view class="label">还需支付</view>
<text class="value finally">{{ payAmount }}</text>
</view>
</view>
<view class="tips">
<view class="tips-content">付款保障</view>
<view class="tips-content">1.专业可信赖,国家认证团队,7*24小时在线</view>
<view class="tips-content">2.11指导,量身定制解决方案,服务客户300多万</view>
<view class="tips-content">3.安全保障,严格隐私保护,不满意100%退款</view>
</view>
<view class="footer">
<button
class="pay-button"
:loading="loading"
@click="onPay"
>
确认支付
</button>
</view>
</view> </view>
</template> </template>
<script> <script>
import { setTrackData } from '@/utils/util'
import { hostPrefix } from '@/config' import { hostPrefix } from '@/config'
import Decimal from 'decimal.js'
// 要付款的前 要付款totalAmount
// balance 可用余额
const computeAmountForCombination = (totalAmount, balance) => {
let payBalance = 0
let payAmount = 0
if (balance === 0) {
payAmount = totalAmount
} else if (balance > 0 && balance < totalAmount) {
payBalance = balance
const x = new Decimal(totalAmount)
const y = new Decimal(balance)
payAmount = Number(x.minus(y))
} else {
payBalance = totalAmount
}
// 真实要额外付款微信,从余额扣款
return { payAmount, payBalance }
}
export default { export default {
name: 'OrderPay', name: 'OrderPay',
data() { data() {
return { return {
price: '0', // 原价
coupon: '0', // 优惠金额
balance: '0', // 余额
orderId: '', // 订单id orderId: '', // 订单id
payId: '', // 支付id payType: 1, // 支付方式,1: 余额 5: 微信 7: 微信 + 余额
payAmount: 0, // 支付方式 还需支付(除去余额扣款后,微信需要支付)
payBalance: 0, // 从余额扣款
loading: false, loading: false,
from: '', // 来源页面
} }
}, },
computed: {
// 实际支付金额
payAmount() {
return Math.max(this.price - this.coupon - this.balance, 0).toFixed(2)
},
},
onLoad(options) { onLoad(options) {
// 赋值 // 赋值
const { price, coupon, balance, orderId, payId, from } = options const { orderId, payType, payAmount, payBalance } = options
this.price = price
this.coupon = coupon
this.balance = balance
this.orderId = orderId this.orderId = orderId
this.payId = payId this.payType = Number(payType)
this.from = from this.payAmount = Number(payAmount)
// 页面访问埋点 this.payBalance = Number(payBalance)
setTrackData({ // // 页面访问埋点
events: [ // setTrackData({
{ // events: [
event_id: 'page_visit', // {
event_custom_properties: { // event_id: 'page_visit',
part: 'order_middle_page', // event_custom_properties: {
position: '', // part: 'order_middle_page',
element: '', // position: '',
}, // element: '',
}, // },
], // },
}) // ],
// })
},
mounted() {
this.onPay()
}, },
methods: { methods: {
// 调用后端接口得到支付参数 // 调用后端接口得到支付参数
...@@ -89,9 +71,6 @@ export default { ...@@ -89,9 +71,6 @@ export default {
return return
} }
// todo
this.handleSuccess()
// setTrackData({ // setTrackData({
// events: [ // events: [
// { // {
...@@ -106,38 +85,34 @@ export default { ...@@ -106,38 +85,34 @@ export default {
// ], // ],
// }) // })
this.loading = true this.loading = true
const { uid, accessToken, openId } = this.$store.state.user
// 组合支付从余额里面扣除的金额 const { orderId, payType } = this
const payBalance = Math.min(Math.max(0, this.price - this.coupon), this.balance) // eslint-disable-next-line no-unused-vars
// 支付方式,1: 余额 5: 微信 7: 微信 + 余额 const { payAmount, payBalance } = computeAmountForCombination(this.totalAmount, this.balance)
const payType = this.payAmount > 0 ? (this.balance > 0 ? 7 : 5) : 1
try { try {
// todo 这是一个什么页面?,一定要传吗
const wxUrl = encodeURIComponent('http://m.ydl.com?backPayId=' + this.payId) const wxUrl = encodeURIComponent('http://m.ydl.com?backPayId=' + this.payId)
const res = await this.$request.post( const parmas = {
'/auth/cashierV2/unityPay', returnUrl: wxUrl, // 支付完成
{ quitUrl: wxUrl, // 中断支付
payId: this.payId, orderId,
orderId: this.orderId, payType,
payAmount: this.payAmount, // todo
openId: openId, payAmount: 0.01,
// todo // payAmount,
payType: 1, payBalance,
payBalance: 0.1, payChannel: 'WX_MINI_APP',
payChannel: 'WX_MINI_APP',
quitUrl: wxUrl, // appId: appId,??
returnUrl: wxUrl, }
uid: uid || '', console.log('请求parmas::', parmas)
accessToken: accessToken || '',
}, const res = await this.$request.post('/auth/cashierV2/unityPay', parmas, {
{ raw: true,
raw: true, })
},
)
this.loading = false this.loading = false
if (+res.code === 200) { if (+res.code === 200) {
// 金额为0,直接调用成功方法 // 金额为0,直接调用成功方法
if (+this.payAmount === 0) { if (+payAmount === 0) {
this.handleSuccess() this.handleSuccess()
return return
} }
...@@ -170,10 +145,12 @@ export default { ...@@ -170,10 +145,12 @@ export default {
signType, signType,
package: data.package, package: data.package,
paySign: paySign, paySign: paySign,
success: () => { success: r => {
console.log('------sucss', r)
this.handleSuccess() this.handleSuccess()
}, },
fail: () => { fail: e => {
console.log('------error--', e)
uni.showToast({ uni.showToast({
title: '支付失败', title: '支付失败',
icon: 'none', icon: 'none',
...@@ -220,56 +197,4 @@ export default { ...@@ -220,56 +197,4 @@ export default {
background: #f8f8f8; background: #f8f8f8;
overflow: auto; overflow: auto;
} }
.order-info {
margin: 0 16px;
border-radius: 8px;
background: #fff;
padding: 10px 16px;
.info-item {
display: flex;
align-items: center;
justify-content: space-between;
color: #666;
font-size: 13px;
line-height: 30px;
.value {
&.finally {
font-size: 18px;
color: red;
}
}
}
}
.tips {
margin: 16px;
.tips-content {
font-size: 13px;
line-height: 18px;
font-weight: 500;
color: #999;
margin-bottom: 8px;
}
}
.footer {
height: 99px;
position: fixed;
bottom: 0;
left: 0;
width: 100%;
box-sizing: border-box;
padding-top: 19px;
box-shadow: 0px -1px 0px 0px rgba(235, 235, 235, 1);
.pay-button {
background-color: #ff6b5d;
border: none;
color: #fff;
font-size: 17px;
font-weight: 500;
border-radius: 8px;
margin: 0 16px;
&:after {
border: none;
}
}
}
</style> </style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment