94 lines
2.2 KiB
Vue
94 lines
2.2 KiB
Vue
<template>
|
|
<view class="page">
|
|
<credit-header title="押金"></credit-header>
|
|
|
|
<view v-if="order" class="info-section">
|
|
<rental-info
|
|
:item-name="order.itemName"
|
|
:deposit-amount="order.depositAmount"
|
|
:credit-free="order.depositMode === 'CREDIT'"
|
|
></rental-info>
|
|
</view>
|
|
<view v-else class="empty">暂无押金订单</view>
|
|
|
|
<view class="bottom-bar">
|
|
<button class="btn-primary" :disabled="releasing || !order" @tap="handleRelease">
|
|
{{ releasing ? '处理中...' : '解除信用授权/退还押金' }}
|
|
</button>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { ref } from 'vue'
|
|
import { onLoad } from '@dcloudio/uni-app'
|
|
import { getOrder, getLatestOrder, releaseCreditOrder } from '@/api/order'
|
|
|
|
const orderId = ref('')
|
|
const order = ref(null)
|
|
const releasing = ref(false)
|
|
|
|
onLoad((query) => {
|
|
orderId.value = (query && query.orderId) || ''
|
|
loadOrder()
|
|
})
|
|
|
|
async function loadOrder() {
|
|
try {
|
|
order.value = orderId.value ? await getOrder(orderId.value) : await getLatestOrder()
|
|
} catch (error) {
|
|
order.value = null
|
|
}
|
|
}
|
|
|
|
function handleRelease() {
|
|
if (!order.value || releasing.value) return
|
|
uni.showModal({
|
|
title: '解除信用授权',
|
|
content: '解除后本次免押将不再有效,押金按租赁规则处理,确认继续?',
|
|
confirmText: '确认解除',
|
|
confirmColor: '#1E6BFF',
|
|
success: (res) => {
|
|
if (res.confirm) doRelease()
|
|
}
|
|
})
|
|
}
|
|
|
|
async function doRelease() {
|
|
releasing.value = true
|
|
uni.showLoading({ title: '处理中', mask: true })
|
|
try {
|
|
await releaseCreditOrder(order.value.orderId)
|
|
uni.hideLoading()
|
|
uni.showToast({ title: '已解除信用授权', icon: 'success' })
|
|
setTimeout(() => {
|
|
uni.reLaunch({ url: '/pages/index/index' })
|
|
}, 1200)
|
|
} catch (error) {
|
|
uni.hideLoading()
|
|
uni.showToast({ title: error.message || '操作失败,请稍后重试', icon: 'none' })
|
|
} finally {
|
|
releasing.value = false
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
.page {
|
|
min-height: 100vh;
|
|
padding-bottom: 220rpx;
|
|
background: #ffffff;
|
|
}
|
|
|
|
.info-section {
|
|
margin-top: 24rpx;
|
|
}
|
|
|
|
.empty {
|
|
padding-top: 120rpx;
|
|
text-align: center;
|
|
font-size: 28rpx;
|
|
color: #999999;
|
|
}
|
|
</style>
|