扫码支付修改

This commit is contained in:
weiwei committed 2025-05-08 11:11:41 +08:00
1 parent ecbdb04a05
commit d9133f2ced
5 files changed
+35 -25

No files matched your search

+26 -16
View File
@@ -1,7 +1,7 @@
<template>
<crud-layout bg="/static/page/blue-bg.png">
<view class="h-screen flex flex-col">
<view class="mx-auto text-34 py-2 h-80rpx">{{ scanData.name }}</view>
<view class="mx-auto text-34 py-2 h-80rpx">{{ scanCodeData.name }}</view>
<tm-sheet class="flex flex-row">
<span class="text-2xl text-[#333] mr-1 line-height-normal">¥</span>
@@ -36,8 +36,8 @@
</template>
<script setup lang="ts">
import { ref, computed } from "vue"
import { onShow } from "@dcloudio/uni-app"
import { ref, computed, reactive } from "vue"
import { onLoad, onShow } from "@dcloudio/uni-app"
import { usePayStore } from "@/sheep/stores/pay"
import payApi from "@@/api/pay"
import { storePrice } from "@/sheep/utils/formatMoney"
@@ -46,23 +46,33 @@ import { merchantApi, walletApi } from "@/sheep/api"
import numberKeyboard from "@/sheep/components/numberKeyboard.vue"
import { filePath } from "@/sheep/utils/file"
import { hooks } from "@@/index"
import { isEmpty } from "radash"
const amount = ref("")
const scanData = ref<{ id?: string; name?: string }>({})
const disabled = ref(false)
const scanCodeData = reactive({
id: "",
name: "",
})
const walletList = ref<any>([])
const curWalletId = ref("")
const disabled = ref(false)
const amount = ref("")
onLoad((options: any) => {
if (!isEmpty(options.id)) {
scanCodeData.id = options.id
} else {
uni.showToast({ title: "参数不存在", icon: "none" })
}
})
onShow(async () => {
uni.showLoading({ title: "加载中...", mask: true })
scanData.value.id = usePayStore().payData.id
if (scanData.value.id) {
const { data } = await merchantApi.detail({ id: scanData.value.id })
scanData.value.name = data.name
usePayStore().setPayData(scanData.value)
if (scanCodeData.id) {
const { data } = await merchantApi.detail({ id: scanCodeData.id })
scanCodeData.name = data.name
disabled.value = false
} else {
uni.showToast({ title: "扫码信息不存在", icon: "none" })
uni.showToast({ title: "参数不存在", icon: "none" })
disabled.value = true
}
@@ -88,7 +98,7 @@ const displayAmount = computed(() => {
// 点击支付
const handlePay = () => {
if (!scanData.value.id || !scanData.value.name) return uni.showToast({ title: "扫码信息不存在", icon: "none" })
if (!scanCodeData.id || !scanCodeData.name) return uni.showToast({ title: "扫码参数不存在", icon: "none" })
if (!amount.value) {
uni.showToast({ title: "请输入金额", icon: "none" })
return
@@ -112,7 +122,7 @@ const pay = async () => {
try {
uni.showLoading({ title: "支付中...", mask: true })
const res = await payApi.createQrCodeOrder({
merchantId: scanData.value.id,
merchantId: scanCodeData.id,
customPrice: storePrice(Number(amount.value)),
walletId: curWalletId.value,
})
@@ -120,11 +130,11 @@ const pay = async () => {
uni.showToast({ title: res.msg || "支付失败", icon: "error" })
} else {
uni.hideLoading()
usePayStore().setPayData({ ...scanData.value, customPrice: Number(amount.value).toFixed(2) })
usePayStore().setPayData({ id: scanCodeData.id, name: scanCodeData.name, customPrice: Number(amount.value).toFixed(2) })
router.jump("/pages/pay/payComplete", {}, 2)
}
} catch (error: any) {
uni.showToast({ title: "错误", icon: "error" })
uni.showToast({ title: "请求错误", icon: "error" })
uni.hideLoading()
}
}