扫二维码码支付
This commit is contained in:
1 parent
8dc692796c
commit
8bff006f5a
5 files changed
+154
-63
No files matched your search
@@ -7,7 +7,9 @@
|
||||
<span class="text-2xl text-[#333] mr-1 line-height-normal">¥</span>
|
||||
<span class="text-3xl font-medium text-[#333]">{{ displayAmount }}</span>
|
||||
</tm-sheet>
|
||||
<view>{{ scanData }}</view>
|
||||
|
||||
<view>扫码信息:{{ JSON.stringify(scanData) }}</view>
|
||||
|
||||
<tm-button class="mt-40" :block="true" @click="disabled ? '' : handlePay()" :disabled="disabled">支付</tm-button>
|
||||
|
||||
<view class="bg-[#f5f5f5] px-1 py-2 rounded-4 absolute bottom-0 w-full">
|
||||
@@ -75,6 +77,9 @@
|
||||
import { ref, computed } from "vue"
|
||||
import { onShow } from "@dcloudio/uni-app"
|
||||
import { usePayStore } from "@/sheep/stores/pay"
|
||||
import payApi from "@@/api/pay"
|
||||
import { storePrice } from "@/sheep/utils/formatMoney"
|
||||
import { router } from "@/sheep"
|
||||
|
||||
const amount = ref("")
|
||||
const keyboardLayout = ref([
|
||||
@@ -82,12 +87,12 @@ const keyboardLayout = ref([
|
||||
["4", "5", "6"],
|
||||
["7", "8", "9"],
|
||||
])
|
||||
const scanData = ref("")
|
||||
const scanData = ref<{ id?: string; name?: string }>({})
|
||||
const disabled = ref(false)
|
||||
|
||||
onShow(() => {
|
||||
scanData.value = usePayStore().payData
|
||||
if (scanData.value) {
|
||||
if (scanData.value.id && scanData.value.name) {
|
||||
disabled.value = false
|
||||
} else {
|
||||
uni.showToast({ title: "扫码信息不存在", icon: "none" })
|
||||
@@ -124,7 +129,7 @@ const handleDelete = () => {
|
||||
}
|
||||
|
||||
// 点击支付
|
||||
const handlePay = () => {
|
||||
const handlePay = async () => {
|
||||
if (!amount.value) {
|
||||
uni.showToast({ title: "请输入金额", icon: "none" })
|
||||
return
|
||||
@@ -133,7 +138,23 @@ const handlePay = () => {
|
||||
uni.showToast({ title: "金额不能为0", icon: "none" })
|
||||
return
|
||||
}
|
||||
uni.showToast({ title: "支付中。。。", icon: "none" })
|
||||
usePayStore().payData = ""
|
||||
try {
|
||||
uni.showLoading({ title: "支付中...", mask: true })
|
||||
const res = await payApi.createQrCodeOrder({
|
||||
id: scanData.value.id,
|
||||
customPrice: storePrice(Number(amount.value)),
|
||||
})
|
||||
if (res.code === 0) {
|
||||
uni.showToast({ title: "支付成功", icon: "none" })
|
||||
usePayStore().payData = {}
|
||||
router.back()
|
||||
} else {
|
||||
uni.showToast({ title: "支付失败", icon: "none" })
|
||||
}
|
||||
} catch (error: any) {
|
||||
uni.showToast({ title: "错误", icon: "none" })
|
||||
} finally {
|
||||
uni.hideLoading()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Reference in new issue
Block a user