diff --git a/src/pages/pay/scanPay.vue b/src/pages/pay/scanPay.vue
index e386eb0..f92c016 100644
--- a/src/pages/pay/scanPay.vue
+++ b/src/pages/pay/scanPay.vue
@@ -7,9 +7,6 @@
¥
{{ displayAmount }}
-
- 扫码信息:{{ JSON.stringify(scanData) }}
-
支付
@@ -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()
}
}
diff --git a/src/pages/tabbar/my.vue b/src/pages/tabbar/my.vue
index 9e8f570..d0ee1a6 100644
--- a/src/pages/tabbar/my.vue
+++ b/src/pages/tabbar/my.vue
@@ -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) {