614 lines
14 KiB
Vue
614 lines
14 KiB
Vue
<template>
|
||
<div class="transfer gradient-background-circles">
|
||
<MobileHeader title="Transfer" />
|
||
|
||
<div class="content">
|
||
<!-- 信息部分 -->
|
||
<div>
|
||
<div
|
||
style="
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
margin-bottom: 10px;
|
||
"
|
||
>
|
||
<div style="font-weight: 600">Information</div>
|
||
<div style="display: flex; align-items: center" @click="showDetails">
|
||
<div style="color: rgba(0, 0, 0, 0.4)">Details</div>
|
||
<img src="../assets/icon/arrow.png" alt="" width="16px" />
|
||
</div>
|
||
</div>
|
||
<div
|
||
style="
|
||
background-color: white;
|
||
padding: 16px;
|
||
border-radius: 12px;
|
||
margin-bottom: 12px;
|
||
box-shadow: 0 0 4px 0 rgba(0, 0, 0, 0.25);
|
||
"
|
||
>
|
||
<span style="font-weight: 510; font-size: 1em">Available salary: </span>
|
||
<span v-if="loading" class="loading-text">Loading...</span>
|
||
<span v-else style="font-weight: 700; color: #333; font-size: 1.1em">{{
|
||
availableSalary
|
||
}}</span>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 转账对象 -->
|
||
<div>
|
||
<div style="font-weight: 600; margin-bottom: 10px">Transfer to others</div>
|
||
<div
|
||
style="
|
||
background-color: white;
|
||
padding: 16px;
|
||
border-radius: 12px;
|
||
margin-bottom: 12px;
|
||
box-shadow: 0 0 4px 0 rgba(0, 0, 0, 0.25);
|
||
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
cursor: pointer;
|
||
"
|
||
>
|
||
<!-- 用户信息 -->
|
||
<div v-if="selectedPayee.id" style="width: 100%">
|
||
<!-- 头像信息 -->
|
||
<div style="display: flex; align-items: center; margin-bottom: 12px">
|
||
<!-- 头像 -->
|
||
<div
|
||
style="
|
||
position: relative;
|
||
width: 50px;
|
||
height: 50px;
|
||
border-radius: 25px;
|
||
background-color: #8b5cf6;
|
||
color: white;
|
||
|
||
margin-right: 12px;
|
||
overflow: hidden;
|
||
|
||
font-size: 20px;
|
||
font-weight: 600;
|
||
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
"
|
||
>
|
||
<img
|
||
v-if="selectedPayee.avatar"
|
||
:src="selectedPayee.avatar"
|
||
:alt="selectedPayee.name"
|
||
style="width: 100%; height: 100%; object-fit: cover; border-radius: 50%"
|
||
/>
|
||
<span v-else>{{ selectedPayee.name.charAt(0) }}</span>
|
||
</div>
|
||
<!-- 个人信息 -->
|
||
<div style="flex: 1">
|
||
<div style="margin: 0 0 4px 0; font-size: 16px; font-weight: 600; color: #333">
|
||
{{ selectedPayee.name }}
|
||
</div>
|
||
<div style="margin: 0; font-size: 14px; color: #666">
|
||
ID: {{ selectedPayee.account || selectedPayee.id }}
|
||
</div>
|
||
</div>
|
||
<!-- 换人按钮 -->
|
||
<button
|
||
style="
|
||
border-radius: 12px;
|
||
border: 1px solid #e6e6e6;
|
||
color: rgba(0, 0, 0, 0.4);
|
||
font-weight: 500;
|
||
padding: 2px 8px;
|
||
background: none;
|
||
"
|
||
@click="searchPayee"
|
||
>
|
||
Change
|
||
</button>
|
||
</div>
|
||
<!-- 身份 -->
|
||
<div style="margin-left: 62px; height: 20px; display: flex; gap: 5px">
|
||
<img v-if="selectedPayee.isHost" src="../assets/icon/host.png" alt="" height="100%" />
|
||
<img
|
||
v-if="selectedPayee.isAgency"
|
||
src="../assets/icon/agency.png"
|
||
alt=""
|
||
height="100%"
|
||
/>
|
||
<img
|
||
v-if="selectedPayee.hasSalary"
|
||
src="../assets/icon/RA.png"
|
||
alt=""
|
||
height="100%"
|
||
/>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 空状态 - 默认显示 -->
|
||
<div v-else style="display: flex; justify-content: center; align-items: center">
|
||
<div
|
||
style="
|
||
font-weight: 590;
|
||
color: rgba(0, 0, 0, 0.4);
|
||
padding: 16px;
|
||
border-radius: 12px;
|
||
box-shadow: 0 0 4px 0 rgba(0, 0, 0, 0.25);
|
||
"
|
||
@click="searchPayee"
|
||
>
|
||
Search
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 转账部分 -->
|
||
<div>
|
||
<div
|
||
style="
|
||
background-color: white;
|
||
padding: 16px;
|
||
border-radius: 12px;
|
||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||
"
|
||
>
|
||
<!-- 转账金额选择 -->
|
||
<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px">
|
||
<div
|
||
v-for="coin in coinOptions"
|
||
:key="coin.id"
|
||
@click="selectCoin(coin)"
|
||
:class="['coin-item', { selected: selectedCoin === coin.id }]"
|
||
>
|
||
<img src="../assets/icon/coin.png" alt="" style="width: 40%" />
|
||
<div style="font-weight: 500; color: #373232">{{ coin.amount }}</div>
|
||
<div style="font-weight: 500; color: #131111">${{ coin.price }}</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 转账按钮 -->
|
||
<div style="display: flex; justify-content: center; margin-top: 10px">
|
||
<button
|
||
style="border-radius: 32px"
|
||
class="transfer-btn"
|
||
@click="transfer"
|
||
:disabled="!selectedCoin || !selectedPayee.id"
|
||
>
|
||
Transfer
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { ref, reactive, onMounted } from 'vue'
|
||
import { useRouter } from 'vue-router'
|
||
import MobileHeader from '../components/MobileHeader.vue'
|
||
import { getBankBalance, userBankTransfer } from '../api/wallet.js'
|
||
import { getSelectedPayee, clearSelectedPayee } from '../utils/payeeStore.js'
|
||
import { showError, showSuccess } from '@/utils/toast.js'
|
||
|
||
const router = useRouter()
|
||
|
||
const availableSalary = ref('0')
|
||
const selectedCoin = ref(null)
|
||
const loading = ref(false)
|
||
|
||
// 选中的收款人
|
||
const selectedPayee = reactive({
|
||
id: null,
|
||
account: '',
|
||
name: '',
|
||
avatar: '',
|
||
type: '',
|
||
isHost: false,
|
||
isAgency: false,
|
||
hasSalary: false,
|
||
})
|
||
|
||
// 初始化收款人信息
|
||
const initializePayee = () => {
|
||
const savedPayee = getSelectedPayee()
|
||
if (savedPayee) {
|
||
Object.assign(selectedPayee, savedPayee)
|
||
}
|
||
}
|
||
|
||
// 金币选项
|
||
const coinOptions = reactive([
|
||
{ id: 1, amount: 10000, price: 1 },
|
||
{ id: 2, amount: 50000, price: 5 },
|
||
{ id: 3, amount: 100000, price: 10 },
|
||
{ id: 4, amount: 500000, price: 50 },
|
||
{ id: 5, amount: 1000000, price: 100 },
|
||
{ id: 6, amount: 2000000, price: 200 },
|
||
])
|
||
|
||
// 获取银行余额
|
||
const fetchBankBalance = async () => {
|
||
loading.value = true
|
||
|
||
try {
|
||
const response = await getBankBalance()
|
||
|
||
if (response.status && typeof response.body === 'number') {
|
||
// 格式化余额显示,保疙2位小数
|
||
availableSalary.value = response.body.toFixed(2)
|
||
} else {
|
||
availableSalary.value = '0.00'
|
||
}
|
||
} catch (error) {
|
||
console.error('Failed to fetch bank balance:', error)
|
||
availableSalary.value = '0.00'
|
||
// 可以显示错误提示
|
||
showError('Failed to load balance. Please try again.')
|
||
} finally {
|
||
loading.value = false
|
||
}
|
||
}
|
||
|
||
// 方法
|
||
const showDetails = () => {
|
||
router.push('/information-details')
|
||
}
|
||
|
||
const searchPayee = () => {
|
||
router.push('/search-payee')
|
||
}
|
||
|
||
// 清除当前选中的收款人
|
||
const clearPayee = () => {
|
||
Object.assign(selectedPayee, {
|
||
id: null,
|
||
account: '',
|
||
name: '',
|
||
avatar: '',
|
||
type: '',
|
||
isHost: false,
|
||
isAgency: false,
|
||
hasSalary: false,
|
||
})
|
||
clearSelectedPayee()
|
||
}
|
||
|
||
const selectCoin = (coin) => {
|
||
// 单选逻辑:如果已经选中相同的金币,则取消选择;否则选中新的金币
|
||
if (selectedCoin.value === coin.id) {
|
||
selectedCoin.value = null
|
||
} else {
|
||
selectedCoin.value = coin.id
|
||
}
|
||
}
|
||
|
||
const transfer = async () => {
|
||
if (!selectedCoin.value) {
|
||
showError('Please select an amount first')
|
||
return
|
||
}
|
||
|
||
if (!selectedPayee.id) {
|
||
showError('Please select a payee first')
|
||
return
|
||
}
|
||
|
||
const selectedCoinData = coinOptions.find((coin) => coin.id === selectedCoin.value)
|
||
|
||
// 获取支付密码
|
||
// const password = prompt('Please enter your payment password:')
|
||
// if (!password) {
|
||
// showError('Payment password is required')
|
||
// return
|
||
// }
|
||
|
||
// 构造请求参数
|
||
const transferData = {
|
||
amount: selectedCoinData.price,
|
||
acceptUserId: selectedPayee.id,
|
||
acceptMethod: 'BANK_TRANSFER',
|
||
// password: password
|
||
}
|
||
|
||
try {
|
||
// 调用转账接口
|
||
const response = await userBankTransfer(transferData)
|
||
if (response.status) {
|
||
showSuccess(`Successfully transferred $${selectedCoinData.price} to ${selectedPayee.name}`)
|
||
} else {
|
||
showError(`Failed to transfer $${selectedCoinData.price}`)
|
||
}
|
||
|
||
// 重置选择
|
||
selectedCoin.value = null
|
||
|
||
// 刷新银行余额
|
||
await fetchBankBalance()
|
||
} catch (error) {
|
||
// 错误处理
|
||
console.error('Transfer failed:', error)
|
||
|
||
if (error.errorCode === 5000) {
|
||
showError('Insufficient balance')
|
||
} else if (error.errorCode === 5010 || error.errorCode === 5009) {
|
||
showError('Payment password error')
|
||
} else {
|
||
showError('Transfer failed, please try again later')
|
||
}
|
||
}
|
||
}
|
||
|
||
// 页面加载时获取银行余额和初始化收款人
|
||
onMounted(() => {
|
||
fetchBankBalance()
|
||
initializePayee()
|
||
})
|
||
</script>
|
||
|
||
<style scoped>
|
||
* {
|
||
color: rgba(0, 0, 0, 0.8);
|
||
font-family: 'SF Pro Text';
|
||
}
|
||
|
||
.transfer {
|
||
font-family: -apple-system, BlinkMacSystemFont, sans-serif;
|
||
}
|
||
|
||
.content {
|
||
padding: 16px;
|
||
position: relative;
|
||
z-index: 2;
|
||
}
|
||
|
||
/* 信息部分 */
|
||
.info-section {
|
||
background-color: white;
|
||
padding: 16px;
|
||
border-radius: 12px;
|
||
margin-bottom: 16px;
|
||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||
}
|
||
|
||
.info-header {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
margin-bottom: 12px;
|
||
}
|
||
|
||
.info-header h3 {
|
||
margin: 0;
|
||
font-size: 16px;
|
||
font-weight: 600;
|
||
color: #333;
|
||
}
|
||
|
||
.details-btn {
|
||
background: none;
|
||
border: none;
|
||
color: #666;
|
||
font-size: 14px;
|
||
cursor: pointer;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 4px;
|
||
}
|
||
|
||
.available-salary {
|
||
font-size: 14px;
|
||
color: #666;
|
||
}
|
||
|
||
.available-salary .amount {
|
||
font-weight: 600;
|
||
color: #333;
|
||
}
|
||
|
||
.available-salary .loading-text {
|
||
font-weight: 500;
|
||
color: #8b5cf6;
|
||
font-style: italic;
|
||
}
|
||
|
||
/* 收款人信息 */
|
||
.payee-info {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
padding: 12px;
|
||
border: 1px solid #e0e0e0;
|
||
border-radius: 12px;
|
||
margin-bottom: 20px;
|
||
cursor: pointer;
|
||
transition: background-color 0.2s;
|
||
}
|
||
|
||
.payee-info:active {
|
||
background-color: #f9f9f9;
|
||
}
|
||
|
||
.payee-details {
|
||
display: flex;
|
||
align-items: center;
|
||
flex: 1;
|
||
}
|
||
|
||
.payee-avatar {
|
||
width: 40px;
|
||
height: 40px;
|
||
border-radius: 20px;
|
||
background-color: #8b5cf6;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
color: white;
|
||
font-size: 16px;
|
||
font-weight: 600;
|
||
margin-right: 12px;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.payee-avatar img {
|
||
width: 100%;
|
||
height: 100%;
|
||
object-fit: cover;
|
||
}
|
||
|
||
.payee-text h4 {
|
||
margin: 0 0 4px 0;
|
||
font-size: 14px;
|
||
font-weight: 600;
|
||
color: #333;
|
||
}
|
||
|
||
.payee-text p {
|
||
margin: 0 0 8px 0;
|
||
font-size: 12px;
|
||
color: #666;
|
||
}
|
||
|
||
.payee-tags {
|
||
display: flex;
|
||
gap: 4px;
|
||
}
|
||
|
||
.tag {
|
||
padding: 2px 8px;
|
||
border-radius: 12px;
|
||
font-size: 10px;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.host-tag {
|
||
background-color: #e0e7ff;
|
||
color: #5b21b6;
|
||
}
|
||
|
||
.agency-tag {
|
||
background-color: #dbeafe;
|
||
color: #1e40af;
|
||
}
|
||
|
||
.salary-tag {
|
||
background-color: #fef3c7;
|
||
color: #d97706;
|
||
}
|
||
|
||
.change-btn {
|
||
background-color: #8b5cf6;
|
||
color: white;
|
||
border: none;
|
||
padding: 6px 12px;
|
||
border-radius: 6px;
|
||
font-size: 12px;
|
||
font-weight: 600;
|
||
cursor: pointer;
|
||
}
|
||
|
||
.change-btn:active {
|
||
background-color: #7c3aed;
|
||
}
|
||
|
||
.search-placeholder {
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
gap: 8px;
|
||
color: #666;
|
||
}
|
||
|
||
.search-icon {
|
||
font-size: 24px;
|
||
}
|
||
|
||
.search-placeholder span {
|
||
font-size: 14px;
|
||
font-weight: 500;
|
||
}
|
||
|
||
/* 金币网格 */
|
||
|
||
.coin-item {
|
||
display: flex;
|
||
flex-direction: column;
|
||
justify-content: center;
|
||
align-items: center;
|
||
border: 2px solid #e5e7eb;
|
||
border-radius: 12px;
|
||
cursor: pointer;
|
||
transition: all 0.2s;
|
||
background-color: white;
|
||
aspect-ratio: 1/1;
|
||
}
|
||
|
||
.coin-item.selected {
|
||
border-color: #8b5cf6;
|
||
background-color: #f3f4f6;
|
||
}
|
||
|
||
.coin-item:active {
|
||
transform: scale(0.98);
|
||
}
|
||
|
||
.coin-icon {
|
||
font-size: 24px;
|
||
margin-bottom: 8px;
|
||
}
|
||
|
||
.coin-amount {
|
||
font-size: 14px;
|
||
font-weight: 600;
|
||
color: #333;
|
||
margin-bottom: 4px;
|
||
}
|
||
|
||
.coin-price {
|
||
font-size: 12px;
|
||
color: #666;
|
||
}
|
||
|
||
/* 转账按钮 */
|
||
.transfer-btn {
|
||
width: 70%;
|
||
|
||
padding: 12px;
|
||
background: linear-gradient(135deg, #bb92ff 2.82%, #8b45ff 99.15%);
|
||
color: white;
|
||
border: none;
|
||
border-radius: 12px;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.transfer-btn:disabled {
|
||
background: #ccc;
|
||
}
|
||
|
||
.transfer-btn:not(:disabled):active {
|
||
background: linear-gradient(135deg, #bb92ff 2.82%, #8b45ff 99.15%);
|
||
}
|
||
|
||
@media screen and (max-width: 360px) {
|
||
* {
|
||
font-size: 10px;
|
||
}
|
||
}
|
||
|
||
@media screen and (min-width: 360px) {
|
||
* {
|
||
font-size: 12px;
|
||
}
|
||
}
|
||
|
||
@media screen and (min-width: 768px) {
|
||
* {
|
||
font-size: 24px;
|
||
}
|
||
}
|
||
</style>
|