Merge remote-tracking branch 'origin/cyh666666/consumer'
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
<template>
|
||||
<template>
|
||||
<view class="apply-refund-page">
|
||||
<view class="section">
|
||||
<view class="section-title">退款类型</view>
|
||||
<radio-group @change="handleTypeChange" class="type-group">
|
||||
<label class="type-item">
|
||||
<radio value="1" :checked="refundType === 1" color="#ff4444" />
|
||||
<radio value="1" :checked="refundType === 1" color="#ff5000" class="type-radio" />
|
||||
<text>仅退款</text>
|
||||
</label>
|
||||
<label class="type-item">
|
||||
<radio value="2" :checked="refundType === 2" color="#ff4444" />
|
||||
<radio value="2" :checked="refundType === 2" color="#ff5000" class="type-radio" />
|
||||
<text>退货退款</text>
|
||||
</label>
|
||||
</radio-group>
|
||||
@@ -56,8 +56,9 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
// import supa from '@/components/supadb/aksupainstance.uts'
|
||||
import { ref } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import { supabaseService } from '@/utils/supabaseService.uts'
|
||||
|
||||
const orderId = ref('')
|
||||
const orderItemId = ref('') // Optional, if refunding specific item
|
||||
@@ -79,106 +80,106 @@ const reasonList = [
|
||||
'其他'
|
||||
]
|
||||
|
||||
onMounted(() => {
|
||||
const pages = getCurrentPages()
|
||||
const currentPage = pages[pages.length - 1]
|
||||
const options = currentPage.options as any
|
||||
|
||||
if (options.orderId) {
|
||||
orderId.value = options.orderId
|
||||
loadOrderInfo()
|
||||
}
|
||||
})
|
||||
|
||||
const loadOrderInfo = async () => {
|
||||
try {
|
||||
const { data, error } = await supa
|
||||
.from('orders')
|
||||
.select('actual_amount, delivery_fee')
|
||||
.eq('id', orderId.value)
|
||||
.single()
|
||||
const orderData = await supabaseService.getOrderDetail(orderId.value)
|
||||
|
||||
if (error == null && data != null) {
|
||||
maxAmount.value = data['actual_amount'] as number
|
||||
deliveryFee.value = data['delivery_fee'] as number
|
||||
if (orderData != null) {
|
||||
// Cast to UTSJSONObject to access properties safely
|
||||
const order = orderData as UTSJSONObject
|
||||
const total = order.getNumber('total_amount') ?? 0
|
||||
const shipping = order.getNumber('shipping_fee') ?? 0
|
||||
|
||||
maxAmount.value = total
|
||||
deliveryFee.value = shipping
|
||||
refundAmount.value = maxAmount.value.toString()
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('加载订单信息失败', err)
|
||||
uni.showToast({
|
||||
title: '加载订单失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
onLoad((options) => {
|
||||
if (options['orderId'] != null) {
|
||||
orderId.value = options['orderId'] as string
|
||||
loadOrderInfo()
|
||||
}
|
||||
})
|
||||
|
||||
const handleTypeChange = (e: any) => {
|
||||
refundType.value = parseInt(e.detail.value)
|
||||
// Use bracket notation to access detail property safely on 'any' type in UTS
|
||||
// The structure is e -> detail -> value
|
||||
// We need to cast e to UTSJSONObject first if we want to use bracket notation,
|
||||
// OR we can use JSON.parse/stringify trick if simple casting fails,
|
||||
// BUT the most standard way for UTS 'any' which is actually a Map/JSONObject at runtime:
|
||||
|
||||
const target = e as UTSJSONObject
|
||||
const detail = target['detail'] as UTSJSONObject
|
||||
const value = detail['value'] as string
|
||||
refundType.value = parseInt(value)
|
||||
}
|
||||
|
||||
const handleReasonChange = (e: any) => {
|
||||
const index = e.detail.value as number
|
||||
// Use bracket notation to access detail property safely on 'any' type in UTS
|
||||
const target = e as UTSJSONObject
|
||||
const detail = target['detail'] as UTSJSONObject
|
||||
const value = detail['value'] as number
|
||||
const index = value
|
||||
refundReason.value = reasonList[index]
|
||||
}
|
||||
|
||||
const submitRefund = async () => {
|
||||
if (!refundReason.value) {
|
||||
console.log('=== 提交退款 ===')
|
||||
console.log('refundReason:', refundReason.value)
|
||||
console.log('refundAmount:', refundAmount.value)
|
||||
console.log('maxAmount:', maxAmount.value)
|
||||
|
||||
if (refundReason.value == '') {
|
||||
uni.showToast({ title: '请选择退款原因', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
const amount = parseFloat(refundAmount.value)
|
||||
console.log('解析后金额:', amount)
|
||||
|
||||
if (isNaN(amount) || amount <= 0 || amount > maxAmount.value) {
|
||||
uni.showToast({ title: '请输入有效的退款金额', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
submitting.value = true
|
||||
uni.showLoading({ title: '提交中...' })
|
||||
|
||||
try {
|
||||
const userStore = uni.getStorageSync('userInfo')
|
||||
const userId = userStore?.id
|
||||
console.log('调用 createRefund, orderId:', orderId.value)
|
||||
const result = await supabaseService.createRefund({
|
||||
order_id: orderId.value,
|
||||
refund_type: refundType.value,
|
||||
refund_reason: refundReason.value,
|
||||
refund_amount: amount,
|
||||
description: description.value
|
||||
})
|
||||
|
||||
// 1. Create Refund Record
|
||||
/* const { data, error } = await supa
|
||||
.from('refunds')
|
||||
.insert({
|
||||
user_id: userId,
|
||||
order_id: orderId.value,
|
||||
refund_no: 'REF' + Date.now(),
|
||||
refund_type: refundType.value,
|
||||
refund_reason: refundReason.value,
|
||||
refund_amount: amount,
|
||||
description: description.value,
|
||||
status: 1, // 待处理
|
||||
status_history: [{
|
||||
status: 1,
|
||||
remark: '用户提交申请',
|
||||
created_at: new Date().toISOString()
|
||||
}]
|
||||
})
|
||||
|
||||
if (error != null) throw error */
|
||||
|
||||
// MOCK SUBMIT
|
||||
await new Promise(resolve => setTimeout(resolve, 1000))
|
||||
|
||||
// 2. Update Order Status (Optional, e.g. to "After-sales")
|
||||
// Assuming status 6 is "After-sales/Refund"
|
||||
/*
|
||||
await supa
|
||||
.from('orders')
|
||||
.update({ status: 6 })
|
||||
.eq('id', orderId.value)
|
||||
*/
|
||||
|
||||
uni.showToast({ title: '提交成功', icon: 'success' })
|
||||
|
||||
setTimeout(() => {
|
||||
uni.redirectTo({
|
||||
url: '/pages/mall/consumer/refund'
|
||||
})
|
||||
}, 1500)
|
||||
console.log('createRefund 结果:', JSON.stringify(result))
|
||||
uni.hideLoading()
|
||||
|
||||
if (result.success) {
|
||||
uni.showToast({ title: '提交成功', icon: 'success' })
|
||||
|
||||
setTimeout(() => {
|
||||
uni.navigateBack()
|
||||
}, 1500)
|
||||
} else {
|
||||
uni.showToast({ title: result.message, icon: 'none' })
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('提交退款失败', err)
|
||||
uni.showToast({ title: '提交失败,请重试', icon: 'none' })
|
||||
uni.hideLoading()
|
||||
uni.showToast({ title: '提交异常', icon: 'none' })
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
@@ -187,7 +188,7 @@ const submitRefund = async () => {
|
||||
|
||||
<style scoped>
|
||||
.apply-refund-page {
|
||||
min-height: 100vh;
|
||||
flex: 1;
|
||||
background-color: #f5f5f5;
|
||||
padding: 15px;
|
||||
padding-bottom: 80px;
|
||||
@@ -210,16 +211,19 @@ const submitRefund = async () => {
|
||||
.type-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.type-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-bottom: 15px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.type-radio {
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.picker-content {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
@@ -284,10 +288,11 @@ const submitRefund = async () => {
|
||||
}
|
||||
|
||||
.submit-btn {
|
||||
background-color: #ff4444;
|
||||
background-color: #ff5000;
|
||||
color: #ffffff;
|
||||
border-radius: 22px;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user