扫码金额输入修改

This commit is contained in:
weiwei committed 2025-03-21 15:10:33 +08:00
1 parent 0484940502
commit d71430b9b3
2 files changed
+33 -19

No files matched your search

+30 -16
View File
@@ -7,9 +7,6 @@
<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>扫码信息:{{ 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">
@@ -101,10 +98,13 @@ onShow(() => {
})
const displayAmount = computed(() => {
if (!amount.value) return "0.00"
return Number(amount.value)
.toFixed(2)
.replace(/\B(?=(\d{3})+(?!\d))/g, ",")
if (!amount.value) return "0"
return (
amount.value
// .toString()
// .toFixed(2)
.replace(/\B(?=(\d{3})+(?!\d))/g, ",")
)
})
// 按下键盘
@@ -129,7 +129,7 @@ const handleDelete = () => {
}
// 点击支付
const handlePay = async () => {
const handlePay = () => {
if (!scanData.value.id || !scanData.value.name) return uni.showToast({ title: "扫码信息不存在", icon: "none" })
if (!amount.value) {
uni.showToast({ title: "请输入金额", icon: "none" })
@@ -139,22 +139,36 @@ const handlePay = async () => {
uni.showToast({ title: "金额不能为0", icon: "none" })
return
}
uni.showModal({
title: "确定支付吗?",
success: async (res) => {
if (res.confirm) {
await pay()
}
},
})
}
// handle pay
const pay = async () => {
try {
uni.showLoading({ title: "支付中...", mask: true })
const res = await payApi.createQrCodeOrder({
merchantId: 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" })
if (res.code != 0) {
throw new Error()
}
uni.showToast({ title: "支付成功", icon: "success" })
usePayStore().payData = {}
setTimeout(() => {
router.back()
uni.hideLoading()
}, 1000)
} catch (error: any) {
uni.showToast({ title: "错误", icon: "none" })
} finally {
uni.showToast({ title: "错误", icon: "error" })
uni.hideLoading()
}
}
+3 -3
View File
@@ -179,9 +179,9 @@ const doLogout = async () => {
const doScanCode = async () => {
usePayStore().setPayData({})
try {
const res: any = await (window as any).dd.scan({ type: "all", sourceType: ["camera"], scanType: ["cameraScan"] })
// const decodedString = decodeBase64("eyJpZCI6IjE4ODk0ODM5Mzg0ODQ1MzEyMDEiLCJuYW1lIjoi5rWL6K+V6LaF5biCIn0=")
const decodedString = decodeBase64(res.text)
// const res: any = await (window as any).dd.scan({ type: "all", sourceType: ["camera"], scanType: ["cameraScan"] })
const decodedString = decodeBase64("eyJpZCI6IjE4ODk0ODM5Mzg0ODQ1MzEyMDEiLCJuYW1lIjoi5rWL6K+V6LaF5biCIn0=")
// const decodedString = decodeBase64(res.text)
if (decodedString) {
const decodedJson = JSON.parse(decodedString)
if (decodedJson?.id && decodedJson?.name) {