600 lines
16 KiB
Vue
600 lines
16 KiB
Vue
<template>
|
||
<s-pages :title="pageTitle" :pink_bg="true">
|
||
<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="amountPlaceholder"
|
||
placeholder-style="font-size: 64rpx;color:#C6C6C6;"
|
||
:inputBorder="false"
|
||
:min="0"
|
||
:clearSize="50"
|
||
@blur="onAmountBlur"
|
||
@confirm="submit"
|
||
/>
|
||
</view>
|
||
<view class="tip-text">{{ amountTipText }}</view>
|
||
</view>
|
||
|
||
<view class="card code-card">
|
||
<view class=" code-row--mobile">
|
||
<view class="code-label size28">手机号</view>
|
||
<uni-easyinput
|
||
v-model="smsMobile"
|
||
type="number"
|
||
placeholder="请输入手机号"
|
||
placeholder-style="font-size: 28rpx;color:#C6C6C6;"
|
||
:inputBorder="false"
|
||
:maxlength="11"
|
||
/>
|
||
</view>
|
||
<view
|
||
v-if="isHuaxiaType && showHuaxiaMobileTip"
|
||
:class="[
|
||
'huaxia-mobile-tip',
|
||
{ 'huaxia-mobile-tip--verified': isHuaxiaMobileVerified },
|
||
]"
|
||
>
|
||
{{ isHuaxiaMobileVerified ? '账户核验完成' : '请正确输入华夏手机号' }}
|
||
</view>
|
||
</view>
|
||
|
||
<view v-if="requireSmsCode" class="card code-card">
|
||
<view class="code-row">
|
||
<uni-easyinput
|
||
v-model="smsCode"
|
||
type="number"
|
||
placeholder="请输入验证码"
|
||
placeholder-style="font-size: 28rpx;color:#C6C6C6;"
|
||
:inputBorder="false"
|
||
:maxlength="6"
|
||
/>
|
||
<view class="code-btn" :class="{ disabled: smsCountdown > 0 }" @click="sendSmsCode">
|
||
{{ smsCountdown > 0 ? `${smsCountdown}s` : '获取验证码' }}
|
||
</view>
|
||
</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, watch, onBeforeUnmount } from 'vue';
|
||
import { onLoad, onShow } from '@dcloudio/uni-app';
|
||
import * as payApi from '@/sheep/api/home/pay';
|
||
import * as incrementApi from '@/sheep/api/increment';
|
||
import AuthUtil from '@/sheep/api/member/auth';
|
||
import sheep from '@/sheep';
|
||
|
||
const walletBalanceCents = ref(0);
|
||
const amount = ref('');
|
||
const smsCode = ref('');
|
||
const smsMobile = ref('');
|
||
const smsCountdown = ref(0);
|
||
const smsScene = 7;
|
||
let smsTimer = null;
|
||
const submitting = ref(false);
|
||
const liquidationType = ref(1);
|
||
const channelId = ref(null);
|
||
const pageTitle = computed(
|
||
() =>
|
||
({
|
||
1: '去变现',
|
||
2: '无双变现',
|
||
3: '华夏变现',
|
||
}[Number(liquidationType.value)] || '去变现'),
|
||
);
|
||
const integerOnly = computed(() => Number(liquidationType.value) === 2);
|
||
const isHuaxiaType = computed(() => Number(liquidationType.value) === 3);
|
||
const requireSmsCode = computed(() => !isHuaxiaType.value);
|
||
const amountPlaceholder = computed(() => (integerOnly.value ? '00' : '00.00'));
|
||
const amountTipText = computed(() =>
|
||
integerOnly.value ? '请输入整数变现金额' : isHuaxiaType.value ? '请输入变现金额' : '请输入去变现数量'
|
||
);
|
||
|
||
const huaxiaMobileRegistered = ref(null);
|
||
const checkingHuaxiaMobile = ref(false);
|
||
let huaxiaCheckTimer = null;
|
||
const isHuaxiaMobileVerified = computed(
|
||
() => huaxiaMobileRegistered.value === true,
|
||
);
|
||
const showHuaxiaMobileTip = computed(() => {
|
||
if (!isHuaxiaType.value) return false;
|
||
const mobile = String(smsMobile.value || '').trim();
|
||
if (!isMobileValid(mobile)) return false;
|
||
if (checkingHuaxiaMobile.value) return false;
|
||
return (
|
||
huaxiaMobileRegistered.value === false ||
|
||
huaxiaMobileRegistered.value === true
|
||
);
|
||
});
|
||
|
||
const isMobileValid = (val) => /^1\d{10}$/.test(String(val ?? '').trim());
|
||
|
||
const checkHuaxiaMobile = async (mobile) => {
|
||
if (!isHuaxiaType.value || !isMobileValid(mobile)) return;
|
||
checkingHuaxiaMobile.value = true;
|
||
try {
|
||
const params = { mobile };
|
||
if (channelId.value != null && channelId.value !== '') {
|
||
params.channelId = Number(channelId.value);
|
||
}
|
||
const res = await incrementApi
|
||
.checkHuaxiaMobile(params)
|
||
.catch(() => ({ code: -1, data: false }));
|
||
if (res?.code === 0) {
|
||
huaxiaMobileRegistered.value = !!res?.data;
|
||
} else {
|
||
huaxiaMobileRegistered.value = null;
|
||
}
|
||
} finally {
|
||
checkingHuaxiaMobile.value = false;
|
||
}
|
||
};
|
||
|
||
watch(
|
||
() => smsMobile.value,
|
||
(val) => {
|
||
huaxiaMobileRegistered.value = null;
|
||
if (huaxiaCheckTimer) {
|
||
clearTimeout(huaxiaCheckTimer);
|
||
huaxiaCheckTimer = null;
|
||
}
|
||
const mobile = String(val || '').trim();
|
||
if (!isHuaxiaType.value) return;
|
||
if (!isMobileValid(mobile)) return;
|
||
huaxiaCheckTimer = setTimeout(() => {
|
||
checkHuaxiaMobile(mobile);
|
||
}, 300);
|
||
},
|
||
);
|
||
|
||
const stopCountdown = () => {
|
||
if (smsTimer) {
|
||
clearInterval(smsTimer);
|
||
smsTimer = null;
|
||
}
|
||
};
|
||
|
||
const sanitizeAmountInput = (val) => {
|
||
let next = String(val ?? '').replace(integerOnly.value ? /[^\d]/g : /[^\d.]/g, '');
|
||
if (integerOnly.value) return next.replace(/^0+(\d)/, '$1');
|
||
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?.withdrawAmount ?? 0;
|
||
};
|
||
|
||
const onAmountBlur = () => {
|
||
if (amountNumber.value < 0) {
|
||
sheep.$helper.toast('请输入正确金额');
|
||
amount.value = '0';
|
||
return;
|
||
}
|
||
if (integerOnly.value && String(amount.value || '').includes('.')) {
|
||
amount.value = String(Math.floor(amountNumber.value || 0));
|
||
}
|
||
if (amountNumber.value > availableYuan.value) {
|
||
sheep.$helper.toast('变现金额不能大于钱包余额');
|
||
amount.value = availableYuan.value > 0
|
||
? integerOnly.value
|
||
? String(Math.floor(availableYuan.value))
|
||
: String(availableYuan.value.toFixed(2))
|
||
: '0';
|
||
}
|
||
};
|
||
|
||
const resolveMobile = () => {
|
||
const mobile = String(smsMobile.value || '').trim();
|
||
if (!isMobileValid(mobile)) {
|
||
sheep.$helper.toast('请输入正确手机号');
|
||
return '';
|
||
}
|
||
return mobile;
|
||
};
|
||
|
||
const sendSmsCode = async () => {
|
||
if (isHuaxiaType.value) return;
|
||
if (smsCountdown.value > 0) return;
|
||
const amt = amountNumber.value;
|
||
if (!amt) {
|
||
sheep.$helper.toast(integerOnly.value ? '请输入整数变现金额' : '请输入去变现数量');
|
||
return;
|
||
}
|
||
if (integerOnly.value && !Number.isInteger(amt)) {
|
||
sheep.$helper.toast('无双变现金额只能输入整数');
|
||
return;
|
||
}
|
||
if (amt > availableYuan.value) {
|
||
sheep.$helper.toast('变现金额不能大于钱包余额');
|
||
return;
|
||
}
|
||
const mobile = resolveMobile();
|
||
if (!mobile) return;
|
||
const res = await AuthUtil.sendSmsCode({ mobile, scene: smsScene }).catch(() => ({ code: -1 }));
|
||
if (res?.code !== 0) return;
|
||
smsCountdown.value = 60;
|
||
if (smsTimer) clearInterval(smsTimer);
|
||
smsTimer = setInterval(() => {
|
||
smsCountdown.value -= 1;
|
||
if (smsCountdown.value <= 0) {
|
||
clearInterval(smsTimer);
|
||
smsTimer = null;
|
||
smsCountdown.value = 0;
|
||
}
|
||
}, 1000);
|
||
};
|
||
|
||
const submit = async () => {
|
||
if (submitting.value) return;
|
||
const amt = amountNumber.value;
|
||
if (!amt) {
|
||
sheep.$helper.toast(integerOnly.value ? '请输入整数变现金额' : (isHuaxiaType.value ? '请输入变现金额' : '请输入去变现数量'));
|
||
return;
|
||
}
|
||
if (integerOnly.value && !Number.isInteger(amt)) {
|
||
sheep.$helper.toast('无双变现金额只能输入整数');
|
||
return;
|
||
}
|
||
if (amt > availableYuan.value) {
|
||
sheep.$helper.toast('变现金额不能大于钱包余额');
|
||
amount.value = availableYuan.value > 0
|
||
? integerOnly.value
|
||
? String(Math.floor(availableYuan.value))
|
||
: String(availableYuan.value.toFixed(2))
|
||
: '0';
|
||
return;
|
||
}
|
||
const mobile = resolveMobile();
|
||
if (!mobile) return;
|
||
if (isHuaxiaType.value) {
|
||
if (huaxiaMobileRegistered.value === null || checkingHuaxiaMobile.value) {
|
||
await checkHuaxiaMobile(mobile);
|
||
}
|
||
if (huaxiaMobileRegistered.value === false) {
|
||
sheep.$helper.toast('请正确输入华夏手机号');
|
||
return;
|
||
}
|
||
}
|
||
if (requireSmsCode.value) {
|
||
if (!String(smsCode.value || '').trim()) {
|
||
sheep.$helper.toast('请输入验证码');
|
||
return;
|
||
}
|
||
}
|
||
const money = Math.round(amt * 100);
|
||
const payload = { money, mobile, type: liquidationType.value };
|
||
if (requireSmsCode.value) {
|
||
payload.scene = smsScene;
|
||
payload.code = String(smsCode.value || '').trim();
|
||
}
|
||
if (channelId.value != null && channelId.value !== '') {
|
||
payload.channelId = Number(channelId.value);
|
||
}
|
||
submitting.value = true;
|
||
try {
|
||
const res = await incrementApi.walletLiquidation(payload).catch(() => ({ code: -1 }));
|
||
if (res?.code === 0) {
|
||
sheep.$helper.toast('变现成功,请等待审核');
|
||
amount.value = '';
|
||
smsCode.value = '';
|
||
refreshWallet();
|
||
return;
|
||
}
|
||
if (res?.code === 1006001000) {
|
||
uni.showModal({
|
||
title: '提示',
|
||
content: '您还未实名认证,是否前往实名认证?',
|
||
cancelText: '取消',
|
||
confirmText: '去认证',
|
||
success: (modalRes) => {
|
||
if (!modalRes?.confirm) return;
|
||
uni.navigateTo({
|
||
url: '/pages/public/realname',
|
||
});
|
||
},
|
||
});
|
||
} else if (res?.msg) {
|
||
sheep.$helper.toast(res.msg);
|
||
}
|
||
} finally {
|
||
submitting.value = false;
|
||
}
|
||
};
|
||
|
||
const goRecord = () => {
|
||
uni.navigateTo({
|
||
url: `/pages/home/liquidationRecord?type=${liquidationType.value}`,
|
||
});
|
||
};
|
||
|
||
onLoad((options) => {
|
||
const nextType = Number(options?.type || 1);
|
||
liquidationType.value = [1, 2, 3].includes(nextType) ? nextType : 1;
|
||
if (options?.channelId != null && options?.channelId !== '') {
|
||
channelId.value = Number(options.channelId);
|
||
}
|
||
try {
|
||
uni.setNavigationBarTitle({ title: pageTitle.value });
|
||
} catch (e) {}
|
||
});
|
||
|
||
watch(
|
||
() => liquidationType.value,
|
||
() => {
|
||
try {
|
||
uni.setNavigationBarTitle({ title: pageTitle.value });
|
||
} catch (e) {}
|
||
},
|
||
);
|
||
|
||
onShow(async () => {
|
||
refreshWallet();
|
||
const userStore = sheep.$store('user');
|
||
try {
|
||
await userStore.getInfo();
|
||
} catch (e) {}
|
||
const mobile = userStore?.userInfo?.mobile;
|
||
if (mobile && !smsMobile.value) smsMobile.value = mobile;
|
||
if (isHuaxiaType.value) {
|
||
const curMobile = String(smsMobile.value || '').trim();
|
||
if (isMobileValid(curMobile)) {
|
||
await checkHuaxiaMobile(curMobile);
|
||
}
|
||
}
|
||
});
|
||
|
||
onBeforeUnmount(() => {
|
||
stopCountdown();
|
||
if (huaxiaCheckTimer) {
|
||
clearTimeout(huaxiaCheckTimer);
|
||
huaxiaCheckTimer = null;
|
||
}
|
||
});
|
||
</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;
|
||
box-shadow: 0 10rpx 26rpx rgba(0, 0, 0, 0.08);
|
||
}
|
||
|
||
.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;
|
||
}
|
||
|
||
.code-card {
|
||
padding: 18rpx 22rpx;
|
||
margin: 20rpx 0;
|
||
}
|
||
|
||
.code-row {
|
||
display: flex;
|
||
align-items: center;
|
||
}
|
||
|
||
.code-row--mobile {
|
||
margin-bottom: 12rpx;
|
||
}
|
||
|
||
.code-btn {
|
||
margin-left: 18rpx;
|
||
min-width: 168rpx;
|
||
height: 68rpx;
|
||
padding: 0 18rpx;
|
||
border-radius: 16rpx;
|
||
background: rgba(54, 110, 238, 0.12);
|
||
color: #366eee;
|
||
font-size: 26rpx;
|
||
font-weight: 600;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
box-sizing: border-box;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.code-btn.disabled {
|
||
opacity: 0.6;
|
||
}
|
||
|
||
.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;
|
||
}
|
||
|
||
.huaxia-mobile-tip {
|
||
margin-top: 8rpx;
|
||
padding-left: 4rpx;
|
||
color: #ff4d4f;
|
||
font-size: 24rpx;
|
||
line-height: 36rpx;
|
||
|
||
&.huaxia-mobile-tip--verified {
|
||
color: #12b46b;
|
||
}
|
||
}
|
||
|
||
.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>
|