280 lines
6.4 KiB
Vue
280 lines
6.4 KiB
Vue
<template>
|
||
<s-pages title="去变现">
|
||
<view class="liquidation">
|
||
<view class="top_bar">
|
||
<view class="record_link" @click="goRecord">变现记录</view>
|
||
</view>
|
||
|
||
<view class="container">
|
||
<view class="card balance-card">
|
||
<view class="balance-label">当前钱包余额</view>
|
||
<view class="balance-value">{{ $fen2yuan(walletBalanceCents || 0) }}</view>
|
||
</view>
|
||
|
||
<view class="section-row">
|
||
<view class="section-title">转出资产</view>
|
||
</view>
|
||
|
||
<view class="card input-card">
|
||
<view class="amount-row">
|
||
<view class="amount-prefix">¥</view>
|
||
<uni-easyinput
|
||
v-model="amountInput"
|
||
type="digit"
|
||
placeholder="00.00"
|
||
placeholder-style="font-size: 64rpx;color:#C6C6C6;"
|
||
:inputBorder="false"
|
||
:min="0"
|
||
:clearSize="50"
|
||
@blur="onAmountBlur"
|
||
@confirm="submit"
|
||
/>
|
||
</view>
|
||
<view class="tip-text">请输入去变现数量</view>
|
||
</view>
|
||
|
||
<view class="card tip-card">
|
||
<view class="tip-header">
|
||
<view class="tip-title">兑换提示</view>
|
||
<uni-icons type="info" color="#C6C6C6" size="22" />
|
||
</view>
|
||
<view class="tip-text">请慎重考虑,一经兑换,不可撤销</view>
|
||
</view>
|
||
</view>
|
||
|
||
<view class="bottom-bar">
|
||
<view class="confirm-btn" @click="submit">确定</view>
|
||
</view>
|
||
</view>
|
||
</s-pages>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { computed, ref } from 'vue';
|
||
import { onShow } from '@dcloudio/uni-app';
|
||
import * as payApi from '@/sheep/api/home/pay';
|
||
import * as incrementApi from '@/sheep/api/increment';
|
||
import sheep from '@/sheep';
|
||
|
||
const walletBalanceCents = ref(0);
|
||
const amount = ref('');
|
||
|
||
const sanitizeAmountInput = (val) => {
|
||
let next = String(val ?? '').replace(/[^\d.]/g, '');
|
||
const firstDot = next.indexOf('.');
|
||
if (firstDot !== -1) {
|
||
next = next.slice(0, firstDot + 1) + next.slice(firstDot + 1).replace(/\./g, '');
|
||
const [a, b = ''] = next.split('.');
|
||
next = `${a}.${b.slice(0, 2)}`;
|
||
}
|
||
return next;
|
||
};
|
||
|
||
const amountInput = computed({
|
||
get: () => String(amount.value ?? ''),
|
||
set: (v) => {
|
||
amount.value = sanitizeAmountInput(v);
|
||
},
|
||
});
|
||
|
||
const amountNumber = computed(() => {
|
||
const n = Number(amount.value);
|
||
return Number.isFinite(n) ? n : 0;
|
||
});
|
||
|
||
const availableYuan = computed(() => Number(walletBalanceCents.value || 0) / 100);
|
||
|
||
const refreshWallet = async () => {
|
||
const res = await payApi.getWallet().catch(() => ({ code: -1 }));
|
||
if (res?.code === 0) walletBalanceCents.value = res?.data?.balance ?? 0;
|
||
};
|
||
|
||
const onAmountBlur = () => {
|
||
if (amountNumber.value < 0) {
|
||
sheep.$helper.toast('请输入正确金额');
|
||
amount.value = '0';
|
||
return;
|
||
}
|
||
if (amountNumber.value > availableYuan.value) {
|
||
sheep.$helper.toast('变现金额不能大于钱包余额');
|
||
amount.value = availableYuan.value > 0 ? String(availableYuan.value.toFixed(2)) : '0';
|
||
}
|
||
};
|
||
|
||
const submit = async () => {
|
||
const amt = amountNumber.value;
|
||
if (!amt) {
|
||
sheep.$helper.toast('请输入去变现数量');
|
||
return;
|
||
}
|
||
if (amt > availableYuan.value) {
|
||
sheep.$helper.toast('变现金额不能大于钱包余额');
|
||
amount.value = availableYuan.value > 0 ? String(availableYuan.value.toFixed(2)) : '0';
|
||
return;
|
||
}
|
||
const money = Math.round(amt * 100);
|
||
const res = await incrementApi.walletLiquidation({ money }).catch(() => ({ code: -1 }));
|
||
if (res?.code === 0) {
|
||
sheep.$helper.toast('提交成功');
|
||
amount.value = '';
|
||
refreshWallet();
|
||
}
|
||
};
|
||
|
||
const goRecord = () => {
|
||
uni.navigateTo({
|
||
url: '/pages/home/liquidationRecord',
|
||
});
|
||
};
|
||
|
||
onShow(() => {
|
||
refreshWallet();
|
||
});
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.liquidation {
|
||
min-height: 100vh;
|
||
}
|
||
|
||
.top_bar {
|
||
padding: 22rpx 40rpx 0;
|
||
display: flex;
|
||
justify-content: flex-end;
|
||
}
|
||
|
||
.record_link {
|
||
height: 60rpx;
|
||
padding: 0 22rpx;
|
||
border-radius: 30rpx;
|
||
border: 2rpx solid rgba(0, 0, 0, 0.08);
|
||
background: rgba(255, 255, 255, 0.75);
|
||
color: #333333;
|
||
font-size: 26rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.container {
|
||
padding: 32rpx 40rpx 200rpx;
|
||
}
|
||
|
||
.card {
|
||
background: #f4f8f2;
|
||
border-radius: 24rpx;
|
||
padding: 28rpx;
|
||
}
|
||
|
||
.balance-card {
|
||
margin-bottom: 28rpx;
|
||
}
|
||
|
||
.balance-label {
|
||
color: #333333;
|
||
font-size: 26rpx;
|
||
line-height: 36rpx;
|
||
}
|
||
|
||
.balance-value {
|
||
margin-top: 12rpx;
|
||
color: #111111;
|
||
font-size: 72rpx;
|
||
font-weight: 700;
|
||
line-height: 84rpx;
|
||
}
|
||
|
||
.section-row {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
padding: 4rpx 4rpx 18rpx;
|
||
}
|
||
|
||
.section-title {
|
||
font-size: 28rpx;
|
||
color: #111111;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.input-card {
|
||
padding: 24rpx 28rpx;
|
||
}
|
||
|
||
.amount-row {
|
||
display: flex;
|
||
align-items: center;
|
||
}
|
||
|
||
.amount-prefix {
|
||
color: #111111;
|
||
font-size: 40rpx;
|
||
font-weight: 600;
|
||
margin-right: 14rpx;
|
||
}
|
||
|
||
:deep(.uni-easyinput__content) {
|
||
background: transparent !important;
|
||
border: none !important;
|
||
}
|
||
|
||
:deep(.uni-easyinput__content-input) {
|
||
height: 84rpx !important;
|
||
font-size: 64rpx !important;
|
||
color: #9a9a9a !important;
|
||
font-weight: 600;
|
||
}
|
||
|
||
:deep(.uni-input-input) {
|
||
color: #111111 !important;
|
||
font-weight: 700;
|
||
}
|
||
|
||
.tip-card {
|
||
margin-top: 20rpx;
|
||
padding: 28rpx;
|
||
}
|
||
|
||
.tip-header {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
margin-bottom: 14rpx;
|
||
}
|
||
|
||
.tip-title {
|
||
font-size: 26rpx;
|
||
color: #111111;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.tip-text {
|
||
color: #8b8b8b;
|
||
font-size: 22rpx;
|
||
line-height: 32rpx;
|
||
}
|
||
|
||
.bottom-bar {
|
||
position: fixed;
|
||
left: 0;
|
||
right: 0;
|
||
bottom: 0;
|
||
padding: 22rpx 32rpx calc(22rpx + env(safe-area-inset-bottom));
|
||
background: #ffffff;
|
||
}
|
||
|
||
.confirm-btn {
|
||
height: 96rpx;
|
||
border-radius: 20rpx;
|
||
background: linear-gradient(90deg, #00a87a 0%, #02b06c 100%);
|
||
color: #ffffff;
|
||
font-size: 34rpx;
|
||
font-weight: 700;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
}
|
||
</style>
|
||
|