front/src/views/h5/customer-center/components/H5RechargeSheet.vue
zzh 4a4171dbdf
All checks were successful
Build and Deploy Front / deploy (push) Successful in 4m24s
feat: 财务合同付款申请前端,并优化登录/品牌与 ICP 配置
补齐合同与付款申请页面;登录门户切换与圆角协议文案对齐;品牌文案支持备案号,顶栏与官网短名改为常规字重。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-21 15:52:00 +08:00

606 lines
14 KiB
Vue

<template>
<a-drawer
:visible="visible"
placement="bottom"
height="auto"
:footer="false"
:header="false"
unmount-on-close
:mask-closable="!submitting"
:drawer-style="drawerStyle"
popup-container="body"
class="h5-recharge-drawer"
@cancel="close"
>
<div class="h5-rc">
<div class="h5-rc__handle" aria-hidden="true" />
<header class="h5-rc__head">
<h3>{{ t('h5.recharge.title') }}</h3>
<button type="button" class="h5-rc__close" :disabled="submitting" @click="close">
<icon-close />
</button>
</header>
<div class="h5-rc__body">
<template v-if="step < 2">
<section class="h5-rc__card">
<p class="h5-rc__label">{{ t('h5.recharge.amount') }}</p>
<div class="h5-rc__amount-grid">
<button
v-for="amt in presets"
:key="amt"
type="button"
class="h5-rc__chip"
:class="{ 'is-active': amount === amt && !customMode }"
@click="selectAmount(amt)"
>
¥{{ amt }}
</button>
<button
type="button"
class="h5-rc__chip"
:class="{ 'is-active': customMode }"
@click="
customMode = true;
amount = 0;
"
>
{{ t('h5.recharge.custom') }}
</button>
</div>
<div v-if="customMode" class="h5-rc__amount-focus">
<span class="h5-rc__amount-prefix">¥</span>
<a-input-number
v-model="customAmount"
:min="1"
:precision="2"
:hide-button="true"
class="h5-rc__amount-input"
:placeholder="t('h5.recharge.customPlaceholder')"
/>
</div>
<div v-else class="h5-rc__amount-preview">
<span>{{ t('h5.recharge.amount') }}</span>
<strong>¥{{ amount }}</strong>
</div>
</section>
<section class="h5-rc__card">
<p class="h5-rc__label">{{ t('h5.recharge.payType') }}</p>
<div class="h5-rc__pay-types">
<button
type="button"
class="h5-rc__seg"
:class="{ 'is-active': payType === 'wx' }"
@click="payType = 'wx'"
>
{{ t('h5.recharge.wechat') }}
</button>
<button
type="button"
class="h5-rc__seg"
:class="{ 'is-active': payType === 'zfb' }"
@click="payType = 'zfb'"
>
{{ t('h5.recharge.alipay') }}
</button>
</div>
<div class="h5-rc__qr">
<img v-if="currentQrDisplay" :src="currentQrDisplay" alt="qrcode" />
<p v-else class="h5-rc__qr-empty">{{ t('h5.recharge.qrEmpty') }}</p>
<p v-if="currentQrDisplay">{{ t('h5.recharge.qrTip') }}</p>
</div>
</section>
<section class="h5-rc__card">
<p class="h5-rc__label">{{ t('h5.recharge.voucher') }}</p>
<a-upload
:file-list="fileList"
:custom-request="handleUpload"
:limit="1"
accept="image/*"
list-type="picture-card"
class="h5-rc__uploader"
@change="handleFileChange"
>
<template #upload-button>
<div class="h5-rc__upload">
<icon-plus />
<div>{{ t('h5.recharge.upload') }}</div>
</div>
</template>
</a-upload>
</section>
</template>
<div v-else class="h5-rc__success">
<a-result status="success" :title="t('h5.recharge.success')" />
</div>
</div>
<footer class="h5-rc__foot">
<button
v-if="step < 2"
type="button"
class="h5-rc__submit"
:disabled="submitting"
@click="submit"
>
<span v-if="submitting" class="h5-rc__loading" aria-hidden="true" />
{{ t('h5.recharge.submit') }}
</button>
<button v-else type="button" class="h5-rc__submit" @click="close">
{{ t('h5.recharge.done') }}
</button>
</footer>
</div>
</a-drawer>
</template>
<script lang="ts" setup>
import { computed, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import { Message } from '@arco-design/web-vue';
import { IconClose, IconPlus } from '@arco-design/web-vue/es/icon';
import { submitRechargeApplication } from '@/api/recharge/rechargeRecord';
import { loadPaymentReceiveQrUrls } from '@/utils/paymentReceiveQr';
defineOptions({ name: 'H5RechargeSheet' });
const props = defineProps<{
visible: boolean;
}>();
const emit = defineEmits<{
'update:visible': [value: boolean];
success: [];
}>();
const { t } = useI18n();
const zfbQrDisplay = ref('');
const wxQrDisplay = ref('');
const presets = [500, 1000, 1500, 3000];
const amount = ref(500);
const customMode = ref(false);
const customAmount = ref<number | undefined>();
const payType = ref<'wx' | 'zfb'>('wx');
const fileList = ref<any[]>([]);
const screenshotFile = ref<File | null>(null);
const submitting = ref(false);
const step = ref(0);
const drawerStyle = {
borderRadius: '20px 20px 0 0',
overflow: 'hidden',
maxHeight: 'min(92vh, 780px)',
};
const finalAmount = computed(() =>
customMode.value ? Number(customAmount.value || 0) : amount.value,
);
const currentQrDisplay = computed(() =>
payType.value === 'wx' ? wxQrDisplay.value : zfbQrDisplay.value,
);
function resetForm() {
amount.value = 500;
customMode.value = false;
customAmount.value = undefined;
payType.value = 'wx';
fileList.value = [];
screenshotFile.value = null;
submitting.value = false;
step.value = 0;
}
function close() {
if (submitting.value) return;
emit('update:visible', false);
}
function selectAmount(amt: number) {
customMode.value = false;
amount.value = amt;
}
function handleUpload(options: any) {
const file = options?.fileItem?.file ?? options?.file;
if (!file) {
options?.onError?.(new Error('no file'));
return;
}
screenshotFile.value = file as File;
const url = URL.createObjectURL(file as File);
fileList.value = [{ uid: String(Date.now()), name: (file as File).name, url }];
options?.onSuccess?.(file);
}
function handleFileChange(files: any) {
fileList.value = files;
if (!files?.length) screenshotFile.value = null;
}
async function submit() {
if (finalAmount.value < 0.01) {
Message.warning(t('h5.recharge.needAmount'));
return;
}
submitting.value = true;
try {
const result: any = await submitRechargeApplication({
rechargeAmount: Number(finalAmount.value),
payType: payType.value === 'zfb' ? 2 : 1,
screenshotFile: screenshotFile.value ?? undefined,
});
const decision = String(result?.decision ?? result?.Decision ?? '').trim();
const approvalNo = String(
result?.approvalInstanceNo ?? result?.ApprovalInstanceNo ?? '',
).trim();
if (decision === 'PendingApproval') {
Message.info(
approvalNo
? t('user.recharge.deposit.message.pendingApproval', { no: approvalNo })
: t('user.recharge.deposit.message.pendingApprovalFallback'),
);
} else if (decision === 'Bypass') {
Message.success(t('user.recharge.deposit.message.bypassed'));
} else {
Message.success(t('h5.recharge.success'));
}
step.value = 2;
emit('success');
} catch (e: any) {
Message.error(e?.message || t('h5.recharge.failed'));
} finally {
submitting.value = false;
}
}
watch(
() => props.visible,
async (visible) => {
if (!visible) return;
resetForm();
const urls = await loadPaymentReceiveQrUrls();
zfbQrDisplay.value = urls.alipay;
wxQrDisplay.value = urls.wechat;
},
{ immediate: true },
);
</script>
<style lang="less">
.h5-recharge-drawer {
.arco-drawer-content {
border-radius: 20px 20px 0 0;
overflow: hidden;
max-height: min(92vh, 780px);
}
.arco-drawer-body {
padding: 0;
display: flex;
flex-direction: column;
max-height: min(92vh, 780px);
}
}
</style>
<style lang="less" scoped>
.h5-rc {
display: flex;
flex-direction: column;
max-height: min(92vh, 780px);
padding-bottom: env(safe-area-inset-bottom, 0px);
background: #f5f7f8;
}
.h5-rc__handle {
width: 36px;
height: 4px;
margin: 10px auto 0;
border-radius: 999px;
background: #c9cdd4;
flex-shrink: 0;
}
.h5-rc__head {
display: flex;
align-items: center;
justify-content: center;
position: relative;
height: 48px;
flex-shrink: 0;
h3 {
margin: 0;
font-size: 16px;
font-weight: 600;
color: #1d2129;
}
}
.h5-rc__close {
position: absolute;
right: 12px;
top: 50%;
transform: translateY(-50%);
width: 36px;
height: 36px;
border: none;
border-radius: 10px;
background: transparent;
color: #86909c;
font-size: 18px;
display: inline-flex;
align-items: center;
justify-content: center;
cursor: pointer;
&:disabled {
opacity: 0.5;
}
}
.h5-rc__body {
flex: 1;
min-height: 0;
overflow: auto;
padding: 0 16px 12px;
}
.h5-rc__card {
background: #fff;
border-radius: 16px;
padding: 16px;
margin-bottom: 12px;
box-shadow: 0 4px 16px rgba(15, 23, 42, 0.04);
}
.h5-rc__label {
margin: 0 0 10px;
font-size: 13px;
color: #4e5969;
}
.h5-rc__amount-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.h5-rc__chip {
height: 40px;
border: none;
border-radius: 12px;
background: #f2f3f5;
color: #4e5969;
font-size: 14px;
font-weight: 600;
cursor: pointer;
&.is-active {
color: #fff;
background: var(--app-primary-color);
box-shadow: 0 6px 14px color-mix(in srgb, var(--app-primary-color) 28%, transparent);
}
}
.h5-rc__amount-preview {
display: flex;
align-items: baseline;
justify-content: space-between;
margin-top: 14px;
padding: 14px 16px;
border-radius: 14px;
background: color-mix(in srgb, var(--app-primary-color) 8%, #fff);
span {
font-size: 13px;
color: #4e5969;
}
strong {
font-size: 28px;
font-weight: 700;
color: var(--app-primary-color);
font-variant-numeric: tabular-nums;
letter-spacing: -0.02em;
}
}
.h5-rc__amount-focus {
display: flex;
align-items: center;
gap: 4px;
min-height: 64px;
margin-top: 14px;
padding: 8px 16px;
border-radius: 14px;
background: color-mix(in srgb, var(--app-primary-color) 8%, #fff);
}
.h5-rc__amount-prefix {
font-size: 24px;
font-weight: 700;
color: var(--app-primary-color);
line-height: 1;
}
.h5-rc__amount-input {
flex: 1;
width: 100%;
:deep(.arco-input-wrapper) {
background: transparent !important;
border: none !important;
box-shadow: none !important;
padding: 0;
}
:deep(.arco-input) {
font-size: 28px;
font-weight: 700;
color: #1d2129;
font-variant-numeric: tabular-nums;
height: 40px;
line-height: 40px;
}
:deep(.arco-input::placeholder) {
color: #c9cdd4;
font-size: 16px;
font-weight: 600;
}
}
.h5-rc__pay-types {
display: flex;
gap: 4px;
padding: 3px;
border-radius: 12px;
background: #eef0f3;
}
.h5-rc__seg {
flex: 1;
height: 36px;
border: none;
border-radius: 10px;
background: transparent;
font-size: 13px;
font-weight: 500;
color: #86909c;
cursor: pointer;
&.is-active {
background: #fff;
color: #1d2129;
font-weight: 600;
box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
}
}
.h5-rc__qr {
margin-top: 16px;
text-align: center;
img {
width: 160px;
height: 160px;
object-fit: contain;
padding: 12px;
border-radius: 16px;
background: #f7f8fa;
}
p {
margin: 10px 0 0;
font-size: 12px;
color: #86909c;
}
.h5-rc__qr-empty {
margin: 0;
padding: 48px 16px;
border-radius: 16px;
background: #f7f8fa;
color: #86909c;
font-size: 13px;
line-height: 1.5;
}
}
.h5-rc__uploader {
:deep(.arco-upload-picture-card) {
width: 96px;
height: 96px;
margin: 0;
border: none;
border-radius: 14px;
background: #f7f8fa;
}
:deep(.arco-upload-list-picture-card .arco-upload-list-item) {
width: 96px;
height: 96px;
margin: 0;
border: none;
border-radius: 14px;
overflow: hidden;
}
}
.h5-rc__upload {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 6px;
color: #86909c;
font-size: 12px;
font-weight: 500;
:deep(.arco-icon) {
font-size: 20px;
color: var(--app-primary-color);
}
}
.h5-rc__success {
padding: 32px 8px 16px;
background: #fff;
border-radius: 16px;
box-shadow: 0 4px 16px rgba(15, 23, 42, 0.04);
}
.h5-rc__foot {
flex-shrink: 0;
padding: 12px 16px calc(14px + env(safe-area-inset-bottom, 0px));
background: #fff;
box-shadow: 0 -6px 20px rgba(15, 23, 42, 0.04);
}
.h5-rc__submit {
width: 100%;
height: 48px;
border: none;
border-radius: 12px;
background: var(--app-primary-color);
color: #fff;
font-size: 15px;
font-weight: 600;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
cursor: pointer;
box-shadow: 0 8px 18px color-mix(in srgb, var(--app-primary-color) 28%, transparent);
&:disabled {
opacity: 0.7;
box-shadow: none;
}
}
.h5-rc__loading {
width: 16px;
height: 16px;
border: 2px solid rgba(255, 255, 255, 0.35);
border-top-color: #fff;
border-radius: 50%;
animation: h5-rc-spin 0.7s linear infinite;
}
@keyframes h5-rc-spin {
to {
transform: rotate(360deg);
}
}
</style>