From c985c084058120444a0968737c6e8588d76e7fc0 Mon Sep 17 00:00:00 2001 From: weiwei Date: Wed, 21 May 2025 10:16:09 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=AC=E8=B4=A6=E9=A1=B5=E9=9D=A2=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/pay/transferMoney.vue | 101 +++++++++++++----------------- src/sheep/stores/transferMoney.ts | 14 ----- 2 files changed, 42 insertions(+), 73 deletions(-) delete mode 100644 src/sheep/stores/transferMoney.ts diff --git a/src/pages/pay/transferMoney.vue b/src/pages/pay/transferMoney.vue index 80bbb7d..e60228e 100644 --- a/src/pages/pay/transferMoney.vue +++ b/src/pages/pay/transferMoney.vue @@ -2,22 +2,22 @@ - - {{ transferMoney.sourceWalletType.walletTypeName }} + + {{ payStore.sourceWalletData.walletTypeName }} 余额: - {{ hooks.useMoney(transferMoney.sourceWalletType.balance) + "元" }} + {{ hooks.useMoney(payStore.sourceWalletData.balance) + "元" }} - + 转入到 - {{ state.targetWalletTypeName }} + {{ targetWalletType.name }} @@ -32,26 +32,24 @@ - - 注:转账金额不能超过钱包余额 - + 注:转账金额不能超过钱包余额 - 确定转账 + 确定转账 - + @@ -63,12 +61,6 @@ 余额:{{ hooks.useMoney(v.balance) + "元" }} - - @@ -81,46 +73,44 @@ import { payApi, walletApi } from "@/sheep/api" import { hooks, router } from "@@/index" import { filePath } from "@/sheep/utils/file" import { storePrice } from "@/sheep/utils/formatMoney" -import { useTransferMoney } from "@/sheep/stores/transferMoney" +import { usePayStore } from "@/sheep/stores/pay" + +const payStore = usePayStore() -const transferMoney = useTransferMoney() const amount = ref("") const show = ref(false) -const state = reactive({ - sourceWalletTypeId: "", - sourceWalletTypeName: "", - walletList: [], - targetWalletTypeId: "", - targetWalletTypeName: "", +const sourceWalletType = reactive({ + id: "", + name: "", +}) +const targetWalletType = reactive({ + id: "", + name: "", +}) +const wallet = reactive({ + walletList: [], }) -const curTargetWallet = ref() onLoad(async () => { - if (!transferMoney.sourceWalletType.walletTypeId) return uni.showToast({ title: "钱包类型id不存在", icon: "none" }) - state.sourceWalletTypeId = transferMoney.sourceWalletType.walletTypeId - state.sourceWalletTypeName = transferMoney.sourceWalletType.walletTypeName - uni.setNavigationBarTitle({ title: state.sourceWalletTypeName || "源钱包" }) + if (!payStore.sourceWalletData.walletTypeId) return uni.showToast({ title: "钱包类型id不存在", icon: "none" }) + sourceWalletType.id = payStore.sourceWalletData.walletTypeId + sourceWalletType.name = payStore.sourceWalletData.walletTypeName + uni.setNavigationBarTitle({ title: sourceWalletType.name || "源钱包" }) const res = await walletApi.all() if (res.code == 0) { - state.walletList = res.data.records.filter((item: any) => item.walletTypeId != state.sourceWalletTypeId) + wallet.walletList = res.data.records.filter((item: any) => item.walletTypeId != sourceWalletType.id) } - if (!curTargetWallet.value) { - curTargetWallet.value = state.walletList[0] - state.targetWalletTypeId = state.walletList[0]?.walletTypeId - state.targetWalletTypeName = state.walletList[0]?.walletTypeName + if (wallet.walletList.length) { + targetWalletType.id = wallet.walletList[0]?.walletTypeId + targetWalletType.name = wallet.walletList[0]?.walletTypeName } }) -// 目标钱包选择 -const targetWalletSelect = () => { - // state.sourceWalletTypeId = "" - show.value = true -} - -// 确认目标钱包 -const confirmTargetWallet = () => { - // state.sourceWalletTypeName = state.walletList.find((item: any) => item.walletTypeId != state.sourceWalletTypeId).walletTypeName +// 选择目标钱包 +const selectTargetWalletType = (v: any) => { + targetWalletType.id = v.walletTypeId + targetWalletType.name = v.walletTypeName show.value = false } @@ -153,14 +143,10 @@ const confirmTransfer = async () => { if (!amount.value || amount.value === "0" || amount.value === "0." || parseFloat(amount.value) === 0) { return uni.showToast({ title: "金额不能为零", icon: "none" }) } - if (numAmount.value > transferMoney.sourceWalletType.balance) { + if (numAmount.value > payStore.sourceWalletData.balance) { return uni.showToast({ title: "转账金额不能超过钱包余额", icon: "none" }) } - // console.log("state.sourceWalletTypeId", state.sourceWalletTypeId) - // console.log("state.targetWalletTypeId", state.targetWalletTypeId) - // console.log("金额", numAmount.value) - uni.showModal({ title: "确定转入吗?", success: async (res) => { @@ -170,28 +156,25 @@ const confirmTransfer = async () => { }, }) } + // 二次确认转账 const confirmTransferAgain = async () => { try { uni.showLoading({ title: "正在转入...", mask: true }) const res = await payApi.transferMoney({ - sourceWalletTypeId: state.sourceWalletTypeId, - targetWalletTypeId: state.targetWalletTypeId, + sourceWalletTypeId: sourceWalletType.id, + targetWalletTypeId: targetWalletType.id, balance: numAmount.value, }) if (res.code == 0) { uni.showToast({ title: "转账成功", icon: "success" }) - transferMoney.setSourceWalletType({}) - // router.jump("/pages/wallet/list", {}, 2) + payStore.setSourceWalletData({}) router.back() } else { uni.showToast({ title: res.msg, icon: "none" }) } } catch (error: any) { - uni.showToast({ - title: error.message, - icon: "none", - }) + uni.showToast({ title: error.message, icon: "none" }) } finally { uni.hideLoading() } diff --git a/src/sheep/stores/transferMoney.ts b/src/sheep/stores/transferMoney.ts deleted file mode 100644 index a33f46a..0000000 --- a/src/sheep/stores/transferMoney.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { defineStore } from "pinia" - -export const useTransferMoney = defineStore("transferMoney", { - state: (): any => { - return { - sourceWalletType: {}, - } - }, - actions: { - setSourceWalletType(data: any) { - this.sourceWalletType = data - }, - }, -})