转账修改
This commit is contained in:
1 parent
03adc25ca2
commit
a84d9fe1cc
5 files changed
+105
-89
No files matched your search
@@ -1,56 +1,44 @@
|
||||
<template>
|
||||
<view class="bg-gray-100 flex-col min-h-screen">
|
||||
<view class="flex-row items-center justify-center my-2">
|
||||
<text class="text-lg font-bold">转入{{ state.targetWalletTypeName }}</text>
|
||||
<view class="bg-white p-4 card m-3 flex items-center justify-between active:bg-[#f0f0f0]" @click="targetWalletSelect">
|
||||
<view class="flex items-center">
|
||||
<image class="w-64 h-64 rounded-full mr-2" src="@/static/page/money-cny-circle-fill.svg" />
|
||||
<view>转入到</view>
|
||||
</view>
|
||||
<view class="flex items-center">
|
||||
<view class="second-text-28 mr-1">{{ state.targetWalletTypeName }}</view>
|
||||
<image class="w-38 h-38 rounded-full c-blueGray" src="@/static/page/arrow-right.svg" />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<tm-cell
|
||||
title="转入方式"
|
||||
icon="money-cny-circle-fill"
|
||||
icon-color="#0779FD"
|
||||
iconSize="64"
|
||||
:label="state.sourceWalletTypeName"
|
||||
labelColor="#7f7f7f"
|
||||
labelSize="30"
|
||||
@click="sourceWalletSelect"
|
||||
/>
|
||||
|
||||
<tm-sheet>
|
||||
<text class="text-gray-700 font-bold text-lg">转入金额</text>
|
||||
<view class="bg-white p-4 card m-3">
|
||||
<text class="text-gray-700 font-bold text-lg">转账金额</text>
|
||||
<view class="flex-row items-center">
|
||||
<text class="text-3xl text-[#333] mr-2">¥</text>
|
||||
<text v-if="!amount" class="text-xl text-gray-300">转入金额</text>
|
||||
<text v-if="!amount" class="text-xl text-gray-300">转账金额</text>
|
||||
<text v-else class="text-3xl">{{ formattedAmount }}</text>
|
||||
</view>
|
||||
</tm-sheet>
|
||||
<!-- 金额限制提示 -->
|
||||
<view class="h-30rpx">
|
||||
<view v-if="storePrice(amount) > curSourceWallet?.balance" class="text-xs c-red px-8">注:转账金额不能超过钱包余额</view>
|
||||
</view>
|
||||
<!-- 金额限制提示 -->
|
||||
<!-- <view class="h-30rpx">
|
||||
<view v-if="storePrice(amount) > curTargetWallet?.balance" class="text-xs c-red px-8">注:转账金额不能超过钱包余额</view>
|
||||
</view> -->
|
||||
|
||||
<view class="p-4 font-bold mt-10">
|
||||
<tm-button block @click="confirmTransfer">确定转入</tm-button>
|
||||
<view class="p-4 font-bold mt-4">
|
||||
<tm-button block @click="confirmTransfer" v-if="transferMoney.sourceWalletType.walletTypeId">确定转账</tm-button>
|
||||
</view>
|
||||
|
||||
<number-keyboard v-model="amount" />
|
||||
|
||||
<!-- 选择转入方式 -->
|
||||
<tm-drawer
|
||||
v-model:show="show"
|
||||
title="选择转入方式"
|
||||
size="50%"
|
||||
bg-color="#efefef"
|
||||
position="bottom"
|
||||
:show-footer="true"
|
||||
:showClose="true"
|
||||
>
|
||||
<tm-drawer v-model:show="show" title="选择钱包" size="50%" bg-color="#efefef" position="bottom" :show-footer="true" :showClose="true">
|
||||
<view class="m-4">
|
||||
<view
|
||||
v-for="(v, index) in state.walletList"
|
||||
:key="index"
|
||||
class="card mb-2 overflow-hidden relative border-4 border-solid border-white duration-200 flex justify-between items-center p-4"
|
||||
:class="{ 'border-4 border-solid border-blue!': state.sourceWalletTypeId == v.walletTypeId }"
|
||||
@click="state.sourceWalletTypeId = v.walletTypeId"
|
||||
:class="{ 'border-4 border-solid border-blue!': state.targetWalletTypeId == v.walletTypeId }"
|
||||
@click="state.targetWalletTypeId = v.walletTypeId"
|
||||
>
|
||||
<view class="flex items-center">
|
||||
<image class="w-70 h-70 mr-2" :src="filePath(v.walletTypeIcon)" />
|
||||
@@ -64,7 +52,9 @@
|
||||
</view>
|
||||
|
||||
<template #footer>
|
||||
<tm-button block @click="confirmSourceWallet" class="flex-1 font-bold">确定</tm-button>
|
||||
<view class="font-bold px-5">
|
||||
<tm-button block @click="confirmTargetWallet">确 定</tm-button>
|
||||
</view>
|
||||
</template>
|
||||
</tm-drawer>
|
||||
</view>
|
||||
@@ -78,48 +68,47 @@ 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"
|
||||
|
||||
const transferMoney = useTransferMoney()
|
||||
const amount = ref("")
|
||||
const show = ref(false)
|
||||
const state = reactive<any>({
|
||||
targetWalletTypeId: "",
|
||||
targetWalletTypeName: "",
|
||||
walletList: [],
|
||||
sourceWalletTypeId: "",
|
||||
sourceWalletTypeName: "",
|
||||
walletList: [],
|
||||
targetWalletTypeId: "",
|
||||
targetWalletTypeName: "",
|
||||
})
|
||||
const curSourceWallet = computed(() => {
|
||||
if (!state.sourceWalletTypeId) {
|
||||
state.sourceWalletTypeId = state.walletList[0]?.walletTypeId
|
||||
state.sourceWalletTypeName = state.walletList[0]?.walletTypeName
|
||||
return state.walletList[0]
|
||||
}
|
||||
return state.walletList.find((item: any) => item.walletTypeId == state.sourceWalletTypeId)
|
||||
})
|
||||
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 || "源钱包" })
|
||||
|
||||
onLoad(async (options) => {
|
||||
if (options?.walletTypeId) {
|
||||
state.targetWalletTypeId = options.walletTypeId
|
||||
state.targetWalletTypeName = options.walletTypeName
|
||||
} else {
|
||||
uni.showToast({ title: "钱包id不存在", icon: "none" })
|
||||
}
|
||||
const res = await walletApi.all()
|
||||
if (res.code == 0) {
|
||||
state.walletList = res.data.records.filter((item: any) => item.walletTypeId != state.targetWalletTypeId)
|
||||
state.walletList = res.data.records.filter((item: any) => item.walletTypeId != state.sourceWalletTypeId)
|
||||
}
|
||||
if (!curTargetWallet.value) {
|
||||
curTargetWallet.value = state.walletList[0]
|
||||
state.targetWalletTypeId = state.walletList[0]?.walletTypeId
|
||||
state.targetWalletTypeName = state.walletList[0]?.walletTypeName
|
||||
}
|
||||
})
|
||||
|
||||
// 源钱包选择
|
||||
const sourceWalletSelect = () => {
|
||||
state.sourceWalletTypeId = ""
|
||||
// 目标钱包选择
|
||||
const targetWalletSelect = () => {
|
||||
// state.sourceWalletTypeId = ""
|
||||
show.value = true
|
||||
}
|
||||
|
||||
// 确认源钱包
|
||||
const confirmSourceWallet = () => {
|
||||
// 确认目标钱包
|
||||
const confirmTargetWallet = () => {
|
||||
// state.sourceWalletTypeName = state.walletList.find((item: any) => item.walletTypeId != state.sourceWalletTypeId).walletTypeName
|
||||
show.value = false
|
||||
state.sourceWalletTypeName = state.walletList.find((item: any) => item.walletTypeId == state.sourceWalletTypeId).walletTypeName
|
||||
}
|
||||
|
||||
// 格式化金额显示
|
||||
@@ -144,47 +133,52 @@ const formattedAmount = computed(() => {
|
||||
return parts[0]
|
||||
})
|
||||
|
||||
const numAmount = computed(() => storePrice(parseFloat(amount.value.endsWith(".") ? amount.value.slice(0, -1) : amount.value)))
|
||||
|
||||
// 确认转账
|
||||
const confirmTransfer = async () => {
|
||||
if (!amount.value || amount.value === "0" || amount.value === "0." || parseFloat(amount.value) === 0) {
|
||||
return uni.showToast({ title: "金额不能为零", icon: "none" })
|
||||
}
|
||||
const numAmount = storePrice(parseFloat(amount.value.endsWith(".") ? amount.value.slice(0, -1) : amount.value))
|
||||
if (numAmount > curSourceWallet.value.balance) {
|
||||
return uni.showToast({ title: "转账金额不能超过钱包余额", icon: "none" })
|
||||
}
|
||||
// if (numAmount > curSourceWallet.value.balance) {
|
||||
// return uni.showToast({ title: "转账金额不能超过钱包余额", icon: "none" })
|
||||
// }
|
||||
|
||||
// console.log("state.sourceWalletTypeId", state.sourceWalletTypeId)
|
||||
// console.log("state.targetWalletTypeId", state.targetWalletTypeId)
|
||||
// console.log("金额", numAmount)
|
||||
console.log("state.sourceWalletTypeId", state.sourceWalletTypeId)
|
||||
console.log("state.targetWalletTypeId", state.targetWalletTypeId)
|
||||
console.log("金额", numAmount.value)
|
||||
|
||||
uni.showModal({
|
||||
title: "确定转入吗?",
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
try {
|
||||
uni.showLoading({ title: "正在转入...", mask: true })
|
||||
const res = await payApi.transferMoney({
|
||||
sourceWalletTypeId: state.sourceWalletTypeId,
|
||||
targetWalletTypeId: state.targetWalletTypeId,
|
||||
balance: numAmount,
|
||||
})
|
||||
if (res.code == 0) {
|
||||
uni.showToast({ title: "转账成功", icon: "success" })
|
||||
router.jump("/pages/wallet/list", {}, 2)
|
||||
} else {
|
||||
uni.showToast({ title: res.msg, icon: "none" })
|
||||
}
|
||||
} catch (error: any) {
|
||||
uni.showToast({
|
||||
title: error.message,
|
||||
icon: "none",
|
||||
})
|
||||
} finally {
|
||||
uni.hideLoading()
|
||||
}
|
||||
await confirmTransferAgain()
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
// 二次确认转账
|
||||
const confirmTransferAgain = async () => {
|
||||
try {
|
||||
uni.showLoading({ title: "正在转入...", mask: true })
|
||||
const res = await payApi.transferMoney({
|
||||
sourceWalletTypeId: state.sourceWalletTypeId,
|
||||
targetWalletTypeId: state.targetWalletTypeId,
|
||||
balance: numAmount.value,
|
||||
})
|
||||
if (res.code == 0) {
|
||||
uni.showToast({ title: "转账成功", icon: "success" })
|
||||
router.jump("/pages/wallet/list", {}, 2)
|
||||
} else {
|
||||
uni.showToast({ title: res.msg, icon: "none" })
|
||||
}
|
||||
} catch (error: any) {
|
||||
uni.showToast({
|
||||
title: error.message,
|
||||
icon: "none",
|
||||
})
|
||||
} finally {
|
||||
uni.hideLoading()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -8,6 +8,7 @@ import { hooks, router } from "@@/index"
|
||||
import { merchantApi, walletApi } from "@@/api"
|
||||
|
||||
import { filePath } from "@@/utils/file"
|
||||
import { useTransferMoney } from "@/sheep/stores/transferMoney"
|
||||
|
||||
const state = reactive<any>({
|
||||
showBindDialog: false,
|
||||
@@ -122,7 +123,12 @@ const doFreeze = async () => {
|
||||
|
||||
// 转账
|
||||
const doTransferMoney = (v: any) => {
|
||||
router.jump("/pages/pay/transferMoney", { walletTypeId: v.walletTypeId, walletTypeName: v.walletTypeName }, 2)
|
||||
if (v.walletTypeId) {
|
||||
useTransferMoney().setSourceWalletType(v)
|
||||
router.jump("/pages/pay/transferMoney")
|
||||
return
|
||||
}
|
||||
uni.showToast({ title: "钱包类型id不存在", icon: "none" })
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -178,7 +184,7 @@ const doTransferMoney = (v: any) => {
|
||||
</view>
|
||||
<view class="flex-row items-center justify-end space-x-20rpx m-t-10rpx">
|
||||
<!-- <view v-if="v.walletTypeUniqueCode == 1 && !v.cardNumber" class="botder_btn" @tap.stop="openBindDialog(v)">绑定</view> -->
|
||||
<view class="botder_btn" @tap.stop="doTransferMoney(v)">转入</view>
|
||||
<view v-if="v.isRule == '1'" class="botder_btn" @tap.stop="doTransferMoney(v)">转账</view>
|
||||
<view v-if="v.walletTypeUniqueCode == 1 && v.cardNumber && v.isFreeze != 1" class="botder_btn" @tap.stop="openFreezeDialog(v)">
|
||||
申请冻结
|
||||
</view>
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { defineStore } from "pinia"
|
||||
|
||||
export const useTransferMoney = defineStore("transferMoney", {
|
||||
state: (): any => {
|
||||
return {
|
||||
sourceWalletType: {},
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
setSourceWalletType(data: any) {
|
||||
this.sourceWalletType = data
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1 @@
|
||||
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1743643959336" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2508" xmlns:xlink="http://www.w3.org/1999/xlink" width="64" height="64"><path d="M334.08 192a47.36 47.36 0 0 0 0 64l256 256-256 256a47.36 47.36 0 1 0 64 64l288.64-288.64A50.56 50.56 0 0 0 704 512a47.36 47.36 0 0 0-14.08-33.28L401.28 192a47.36 47.36 0 0 0-67.2 0z" p-id="2509" fill="#C5BFBF"></path></svg>
|
||||
|
After Width: | Height: | Size: 554 B |
@@ -0,0 +1 @@
|
||||
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1743596095932" class="icon" viewBox="0 0 1042 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7038" width="65.125" height="64" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M515.657143 54.857143c-252.342857 0-457.142857 204.8-457.142857 457.142857s204.8 457.142857 457.142857 457.142857 457.142857-204.8 457.142857-457.142857S768 54.857143 515.657143 54.857143z m182.857143 442.514286h-146.285715v36.571428h146.285715v73.142857h-146.285715v109.714286h-73.142857v-109.714286h-146.285714v-73.142857h146.285714v-36.571428h-146.285714v-73.142858h91.428571l-65.828571-65.828571 51.2-51.2 104.228571 104.228571 104.228572-104.228571 51.2 51.2-65.828572 65.828571h91.428572v73.142858h3.657143z" fill="#0779FD" p-id="7039"></path></svg>
|
||||
|
After Width: | Height: | Size: 890 B |
Reference in new issue
Block a user