feat: 添加华夏变现、添加三方权限配置
This commit is contained in:
+217
-66
@@ -32,6 +32,7 @@
|
||||
</view>
|
||||
<view class="tip-text">{{ amountTipText }}</view>
|
||||
</view>
|
||||
|
||||
<view class="card code-card">
|
||||
<view class=" code-row--mobile">
|
||||
<view class="code-label size28">手机号</view>
|
||||
@@ -44,8 +45,18 @@
|
||||
:maxlength="11"
|
||||
/>
|
||||
</view>
|
||||
<view
|
||||
v-if="isHuaxiaType && showHuaxiaMobileTip"
|
||||
:class="[
|
||||
'huaxia-mobile-tip',
|
||||
{ 'huaxia-mobile-tip--verified': isHuaxiaMobileVerified },
|
||||
]"
|
||||
>
|
||||
{{ isHuaxiaMobileVerified ? '账户核验完成' : '请正确输入华夏手机号' }}
|
||||
</view>
|
||||
</view>
|
||||
<view class="card code-card">
|
||||
|
||||
<view v-if="requireSmsCode" class="card code-card">
|
||||
<view class="code-row">
|
||||
<uni-easyinput
|
||||
v-model="smsCode"
|
||||
@@ -78,7 +89,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref } from 'vue';
|
||||
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';
|
||||
@@ -94,10 +105,86 @@
|
||||
let smsTimer = null;
|
||||
const submitting = ref(false);
|
||||
const liquidationType = ref(1);
|
||||
const pageTitle = ref('去变现');
|
||||
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 ? '请输入整数变现金额' : '请输入去变现数量'));
|
||||
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, '');
|
||||
@@ -149,66 +236,9 @@
|
||||
}
|
||||
};
|
||||
|
||||
const submit = async () => {
|
||||
if (submitting.value) 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('变现金额不能大于钱包余额');
|
||||
amount.value = availableYuan.value > 0
|
||||
? integerOnly.value
|
||||
? String(Math.floor(availableYuan.value))
|
||||
: String(availableYuan.value.toFixed(2))
|
||||
: '0';
|
||||
return;
|
||||
}
|
||||
if (!String(smsCode.value || '').trim()) {
|
||||
sheep.$helper.toast('请输入验证码');
|
||||
return;
|
||||
}
|
||||
const mobile = resolveMobile();
|
||||
if (!mobile) return;
|
||||
const money = Math.round(amt * 100);
|
||||
const payload = { money, mobile, scene: smsScene, code: smsCode.value, type: liquidationType.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',
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
submitting.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const resolveMobile = () => {
|
||||
const mobile = String(smsMobile.value || '').trim();
|
||||
if (!/^1\d{10}$/.test(mobile)) {
|
||||
if (!isMobileValid(mobile)) {
|
||||
sheep.$helper.toast('请输入正确手机号');
|
||||
return '';
|
||||
}
|
||||
@@ -216,6 +246,7 @@
|
||||
};
|
||||
|
||||
const sendSmsCode = async () => {
|
||||
if (isHuaxiaType.value) return;
|
||||
if (smsCountdown.value > 0) return;
|
||||
const amt = amountNumber.value;
|
||||
if (!amt) {
|
||||
@@ -246,6 +277,83 @@
|
||||
}, 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}`,
|
||||
@@ -254,15 +362,46 @@
|
||||
|
||||
onLoad((options) => {
|
||||
const nextType = Number(options?.type || 1);
|
||||
liquidationType.value = nextType === 2 ? 2 : 1;
|
||||
pageTitle.value = liquidationType.value === 2 ? '无双变现' : String(options?.title || '去变现');
|
||||
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) {}
|
||||
});
|
||||
|
||||
onShow(() => {
|
||||
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 (!smsMobile.value && mobile) smsMobile.value = 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>
|
||||
|
||||
@@ -401,6 +540,18 @@
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user