fix:修复bug
This commit is contained in:
+132
-150
@@ -26,11 +26,11 @@
|
||||
<view class="record-list">
|
||||
<view class="record-item" v-for="(item, index) in records" :key="index">
|
||||
<view class="record-info">
|
||||
<text class="record-type">{{ item.type }}</text>
|
||||
<text class="record-type">{{ item.typeText }}</text>
|
||||
<text class="record-time">{{ item.time }}</text>
|
||||
</view>
|
||||
<text class="record-amount" :class="item.type === '退还' ? 'refund' : ''">
|
||||
{{ item.type === '退还' ? '+' : '-' }}¥{{ item.amount }}
|
||||
<text class="record-amount" :class="item.type === 'refund' ? 'refund' : ''">
|
||||
{{ item.type === 'refund' ? '+' : '-' }}¥{{ item.amount }}
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
@@ -38,163 +38,145 @@
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { onShow } from '@dcloudio/uni-app'
|
||||
import { getUserInfo } from '../../util/index.js'
|
||||
import { withdrawDeposit } from '../../config/api/user.js'
|
||||
import { queryById } from '../../config/api/order.js'
|
||||
import { useI18n } from '@/utils/i18n.js'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
depositAmount: '0.00',
|
||||
orderNo: '',
|
||||
records: [],
|
||||
orderId:''
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
// 设置页面标题
|
||||
uni.setNavigationBarTitle({
|
||||
title: this.$t('deposit.title')
|
||||
})
|
||||
// this.loadUserInfo()
|
||||
},
|
||||
onShow() {
|
||||
this.loadUserInfo()
|
||||
},
|
||||
methods: {
|
||||
async loadUserInfo() {
|
||||
try {
|
||||
const res = await getUserInfo()
|
||||
console.log('loadUserInfo',res);
|
||||
if (res.code === 200) {
|
||||
this.depositAmount = res.data.balanceAmount || '0.00'
|
||||
this.orderNo = res.data.latestOrderNo || ''
|
||||
this.orderId = res.data.latestOrderId||''
|
||||
|
||||
// 如果存在余额,获取押金记录
|
||||
if (parseFloat(this.depositAmount) > 0 && this.orderNo) {
|
||||
this.records = [
|
||||
{
|
||||
type: '支付',
|
||||
time: this.formatDate(new Date()),
|
||||
amount: this.depositAmount
|
||||
}
|
||||
]
|
||||
} else {
|
||||
this.records = []
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取用户信息失败:', error)
|
||||
uni.showToast({
|
||||
title: this.$t('user.getUserInfoFailed'),
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
async handleWithdraw() {
|
||||
if (parseFloat(this.depositAmount) <= 0) {
|
||||
uni.showToast({
|
||||
title: this.$t('deposit.noBalance'),
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
if(this.orderId.length!=0||this.orderNo.length!=0){
|
||||
const res = await queryById(Number(this.orderId))
|
||||
console.log(res);
|
||||
}
|
||||
|
||||
// if(this.orderNo.length!=0){
|
||||
// uni.showToast({
|
||||
// title:'当前存在进行中的订单',
|
||||
// icon:'none'
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
const { t } = useI18n()
|
||||
|
||||
const depositAmount = ref('0.00')
|
||||
const orderNo = ref('')
|
||||
const orderId = ref('')
|
||||
const records = ref([])
|
||||
|
||||
onMounted(() => {
|
||||
uni.setNavigationBarTitle({
|
||||
title: t('deposit.title')
|
||||
})
|
||||
})
|
||||
|
||||
onShow(() => {
|
||||
loadUserInfo()
|
||||
})
|
||||
|
||||
const loadUserInfo = async () => {
|
||||
try {
|
||||
const res = await getUserInfo()
|
||||
if (res.code === 200) {
|
||||
depositAmount.value = res.data.balanceAmount || '0.00'
|
||||
orderNo.value = res.data.latestOrderNo || ''
|
||||
orderId.value = res.data.latestOrderId || ''
|
||||
|
||||
uni.showModal({
|
||||
title: this.$t('deposit.confirmWithdraw'),
|
||||
content: this.$t('deposit.withdrawDesc'),
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
uni.showLoading({
|
||||
title: this.$t('deposit.withdrawing')
|
||||
// 如果存在余额,获取押金记录
|
||||
if (parseFloat(depositAmount.value) > 0 && orderNo.value) {
|
||||
records.value = [
|
||||
{
|
||||
type: 'pay',
|
||||
typeText: t('deposit.payRecord'),
|
||||
time: formatDate(new Date()),
|
||||
amount: depositAmount.value
|
||||
}
|
||||
]
|
||||
} else {
|
||||
records.value = []
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
uni.showToast({
|
||||
title: t('user.getUserInfoFailed'),
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const handleWithdraw = async () => {
|
||||
if (parseFloat(depositAmount.value) <= 0) {
|
||||
uni.showToast({
|
||||
title: t('deposit.noBalance'),
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
uni.showModal({
|
||||
title: t('deposit.confirmWithdraw'),
|
||||
content: t('deposit.withdrawDesc'),
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
uni.showLoading({
|
||||
title: t('deposit.withdrawing')
|
||||
})
|
||||
|
||||
try {
|
||||
const result = await withdrawDeposit(orderNo.value)
|
||||
|
||||
if (result.code === 200) {
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: t('deposit.withdrawSubmitted'),
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
try {
|
||||
console.log('发起提现请求,订单号:', this.orderNo)
|
||||
const result = await withdrawDeposit(this.orderNo)
|
||||
console.log('提现响应:', result)
|
||||
|
||||
if (result.code === 200) {
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: this.$t('deposit.withdrawSubmitted'),
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
// 更新余额为0
|
||||
this.depositAmount = '0.00'
|
||||
this.records.push({
|
||||
type: '退还',
|
||||
time: this.formatDate(new Date()),
|
||||
amount: this.depositAmount
|
||||
})
|
||||
|
||||
// 重新加载用户信息
|
||||
setTimeout(() => {
|
||||
this.loadUserInfo()
|
||||
}, 1500)
|
||||
} else {
|
||||
throw new Error(result.msg || this.$t('deposit.withdrawFailed'))
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('提现失败:', error)
|
||||
uni.hideLoading()
|
||||
|
||||
// 更详细的错误处理
|
||||
let errorMessage = this.$t('deposit.withdrawFailed');
|
||||
|
||||
// 如果有具体错误信息,使用它
|
||||
if (error.message) {
|
||||
// 常见错误消息处理
|
||||
if (error.message.includes('尚未归还')) {
|
||||
errorMessage = this.$t('deposit.orderNotReturned');
|
||||
} else if (error.message.includes('已退还')) {
|
||||
errorMessage = this.$t('deposit.alreadyRefunded');
|
||||
} else if (error.message.includes('处理中')) {
|
||||
errorMessage = this.$t('deposit.refundProcessing');
|
||||
} else if (error.message.includes('余额为0')) {
|
||||
errorMessage = this.$t('deposit.noBalance');
|
||||
} else {
|
||||
// 使用后端返回的具体错误消息
|
||||
errorMessage = error.message;
|
||||
}
|
||||
}
|
||||
|
||||
// 显示错误提示
|
||||
uni.showModal({
|
||||
title: this.$t('deposit.withdrawFailed'),
|
||||
content: errorMessage,
|
||||
showCancel: false
|
||||
})
|
||||
// 更新记录
|
||||
records.value.push({
|
||||
type: 'refund',
|
||||
typeText: t('deposit.refundRecord'),
|
||||
time: formatDate(new Date()),
|
||||
amount: depositAmount.value
|
||||
})
|
||||
// 更新余额为0
|
||||
depositAmount.value = '0.00'
|
||||
|
||||
// 重新加载用户信息
|
||||
setTimeout(() => {
|
||||
loadUserInfo()
|
||||
}, 1500)
|
||||
} else {
|
||||
throw new Error(result.msg || t('deposit.withdrawFailed'))
|
||||
}
|
||||
} catch (error) {
|
||||
uni.hideLoading()
|
||||
|
||||
// 更详细的错误处理
|
||||
let errorMessage = t('deposit.withdrawFailed');
|
||||
|
||||
if (error.message) {
|
||||
if (error.message.includes('尚未归还')) {
|
||||
errorMessage = t('deposit.orderNotReturned');
|
||||
} else if (error.message.includes('已退还')) {
|
||||
errorMessage = t('deposit.alreadyRefunded');
|
||||
} else if (error.message.includes('处理中')) {
|
||||
errorMessage = t('deposit.refundProcessing');
|
||||
} else if (error.message.includes('余额为0')) {
|
||||
errorMessage = t('deposit.noBalance');
|
||||
} else {
|
||||
errorMessage = error.message;
|
||||
}
|
||||
}
|
||||
|
||||
uni.showModal({
|
||||
title: t('deposit.withdrawFailed'),
|
||||
content: errorMessage,
|
||||
showCancel: false
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
formatDate(date) {
|
||||
const year = date.getFullYear()
|
||||
const month = (date.getMonth() + 1).toString().padStart(2, '0')
|
||||
const day = date.getDate().toString().padStart(2, '0')
|
||||
const hours = date.getHours().toString().padStart(2, '0')
|
||||
const minutes = date.getMinutes().toString().padStart(2, '0')
|
||||
|
||||
return `${year}-${month}-${day} ${hours}:${minutes}`
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const formatDate = (date) => {
|
||||
const year = date.getFullYear()
|
||||
const month = (date.getMonth() + 1).toString().padStart(2, '0')
|
||||
const day = date.getDate().toString().padStart(2, '0')
|
||||
const hours = date.getHours().toString().padStart(2, '0')
|
||||
const minutes = date.getMinutes().toString().padStart(2, '0')
|
||||
|
||||
return `${year}-${month}-${day} ${hours}:${minutes}`
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -338,4 +320,4 @@ export default {
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
Reference in New Issue
Block a user