182 lines
4.0 KiB
Vue
182 lines
4.0 KiB
Vue
<template>
|
||
<view class="page">
|
||
<credit-header title="信用免押金" :show-badge="true" curved></credit-header>
|
||
|
||
<view class="brand-card">
|
||
<image class="brand-logo" :src="brandLogo" mode="aspectFit"></image>
|
||
</view>
|
||
|
||
<view class="brand-name">{{ brandName }}</view>
|
||
|
||
<view class="info-section">
|
||
<rental-info :item-name="itemName" :deposit-amount="depositAmount" credit-free></rental-info>
|
||
</view>
|
||
|
||
<view class="agreement" @tap="toggleAgree">
|
||
<view class="checkbox" :class="{ checked: agreed }">
|
||
<view v-if="agreed" class="checkbox-check"></view>
|
||
</view>
|
||
<view class="agreement-text">
|
||
我已阅读并同意
|
||
<text class="agreement-link" @tap.stop="openAgreement">《芝麻信用协议及授权条款》</text>
|
||
</view>
|
||
</view>
|
||
|
||
<view class="tip">注:请记得归还物品哦,以免对你的信用产生影响</view>
|
||
|
||
<view class="bottom-bar">
|
||
<button class="btn-primary" :disabled="submitting" @tap="handleContinue">
|
||
{{ submitting ? '处理中...' : '继续' }}
|
||
</button>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { ref } from 'vue'
|
||
import config from '@/config'
|
||
import { createCreditOrder, syncOrderStatus } from '@/api/order'
|
||
import { authorizeCreditBorrow } from '@/utils/zhima'
|
||
|
||
const brandName = config.brandName
|
||
const brandLogo = config.brandLogo
|
||
const itemName = config.itemName
|
||
const depositAmount = config.depositAmount
|
||
|
||
const agreed = ref(false)
|
||
const submitting = ref(false)
|
||
|
||
function toggleAgree() {
|
||
agreed.value = !agreed.value
|
||
}
|
||
|
||
function openAgreement() {
|
||
uni.navigateTo({ url: config.agreements.credit })
|
||
}
|
||
|
||
async function handleContinue() {
|
||
if (submitting.value) return
|
||
if (!agreed.value) {
|
||
uni.showToast({ title: '请先阅读并同意协议', icon: 'none' })
|
||
return
|
||
}
|
||
|
||
submitting.value = true
|
||
try {
|
||
// 1. 服务端创建免押订单,同时向芝麻创建信用借还订单
|
||
uni.showLoading({ title: '创建订单中', mask: true })
|
||
const order = await createCreditOrder({
|
||
itemName,
|
||
depositAmount
|
||
})
|
||
|
||
// 2. 拉起支付宝原生授权页
|
||
uni.hideLoading()
|
||
await authorizeCreditBorrow(order)
|
||
|
||
// 3. 以服务端订单状态为准:真实环境靠芝麻异步通知回写
|
||
uni.showLoading({ title: '确认免押中', mask: true })
|
||
await syncOrderStatus(order.orderId)
|
||
uni.hideLoading()
|
||
|
||
uni.redirectTo({ url: `/pages/result/result?orderId=${order.orderId}` })
|
||
} catch (error) {
|
||
uni.hideLoading()
|
||
uni.showToast({ title: error.message || '免押开通失败,请重试', icon: 'none' })
|
||
} finally {
|
||
submitting.value = false
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style>
|
||
.page {
|
||
min-height: 100vh;
|
||
padding-bottom: 220rpx;
|
||
background: #ffffff;
|
||
}
|
||
|
||
/* 卡片压在蓝色头部与白色内容交界处,对应截图里的悬浮效果 */
|
||
.brand-card {
|
||
position: relative;
|
||
z-index: 2;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
width: 200rpx;
|
||
height: 200rpx;
|
||
margin: -120rpx auto 0;
|
||
border-radius: 32rpx;
|
||
background: #ffffff;
|
||
box-shadow: 0 12rpx 40rpx rgba(0, 0, 0, 0.12);
|
||
}
|
||
|
||
.brand-logo {
|
||
width: 140rpx;
|
||
height: 140rpx;
|
||
}
|
||
|
||
.brand-name {
|
||
margin-top: 32rpx;
|
||
text-align: center;
|
||
font-size: 36rpx;
|
||
font-weight: 600;
|
||
color: #1a1a1a;
|
||
}
|
||
|
||
.info-section {
|
||
margin-top: 72rpx;
|
||
}
|
||
|
||
.agreement {
|
||
display: flex;
|
||
align-items: flex-start;
|
||
margin: 48rpx 40rpx 0;
|
||
}
|
||
|
||
.checkbox {
|
||
flex-shrink: 0;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
width: 32rpx;
|
||
height: 32rpx;
|
||
margin-top: 4rpx;
|
||
border: 2rpx solid #c9cdd4;
|
||
border-radius: 50%;
|
||
background: #ffffff;
|
||
}
|
||
|
||
.checkbox.checked {
|
||
border-color: #1e6bff;
|
||
background: #1e6bff;
|
||
}
|
||
|
||
.checkbox-check {
|
||
width: 12rpx;
|
||
height: 6rpx;
|
||
margin-top: -4rpx;
|
||
border-left: 2rpx solid #ffffff;
|
||
border-bottom: 2rpx solid #ffffff;
|
||
transform: rotate(-45deg);
|
||
}
|
||
|
||
.agreement-text {
|
||
margin-left: 14rpx;
|
||
font-size: 26rpx;
|
||
line-height: 1.5;
|
||
color: #333333;
|
||
}
|
||
|
||
.agreement-link {
|
||
color: #1e6bff;
|
||
}
|
||
|
||
.tip {
|
||
margin: 20rpx 40rpx 0 86rpx;
|
||
font-size: 24rpx;
|
||
line-height: 1.6;
|
||
color: #999999;
|
||
}
|
||
</style>
|