完成consumer端同步
This commit is contained in:
@@ -110,6 +110,7 @@
|
||||
<script setup lang="uts">
|
||||
import { ref, onMounted, watch, computed, onUnmounted } from 'vue'
|
||||
import { supabaseService } from '@/utils/supabaseService.uts'
|
||||
import { goToLogin } from '@/utils/utils.uts'
|
||||
|
||||
type PaymentMethodType = {
|
||||
id: string
|
||||
@@ -119,6 +120,14 @@ type PaymentMethodType = {
|
||||
enabled: boolean
|
||||
}
|
||||
|
||||
const getOptionString = (options: UTSJSONObject, key: string): string => {
|
||||
const value = options.getString(key)
|
||||
if (value != null) {
|
||||
return value
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
const orderId = ref<string>('')
|
||||
const orderNo = ref<string>('')
|
||||
const amount = ref<number>(0)
|
||||
@@ -129,6 +138,18 @@ const isPaying = ref<boolean>(false)
|
||||
const showPassword = ref<boolean>(false)
|
||||
const password = ref<string>('')
|
||||
|
||||
const ensureLoggedIn = (): boolean => {
|
||||
const userId = supabaseService.getCurrentUserId()
|
||||
if (userId == null || userId === '') {
|
||||
const redirectUrl = orderId.value !== ''
|
||||
? `/pages/mall/consumer/payment?orderId=${orderId.value}&amount=${amount.value}`
|
||||
: '/pages/mall/consumer/payment'
|
||||
goToLogin(redirectUrl)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// 价格相关变量
|
||||
const productAmount = ref<number>(0) // 商品总价
|
||||
const deliveryFee = ref<number>(0) // 运费
|
||||
@@ -201,7 +222,7 @@ const updateOrderInStorage = (targetOrderId: string, status: number) => {
|
||||
try {
|
||||
// 尝试从 'orders' 读取 (checkout页面写入的key)
|
||||
const ordersStr = uni.getStorageSync('orders')
|
||||
let orders: Record<string, any>[] = []
|
||||
let orders: UTSJSONObject[] = []
|
||||
if (ordersStr != null && ordersStr !== '') {
|
||||
const parsed = JSON.parse(ordersStr as string)
|
||||
if (Array.isArray(parsed)) {
|
||||
@@ -210,7 +231,7 @@ const updateOrderInStorage = (targetOrderId: string, status: number) => {
|
||||
const itemStr = JSON.stringify(parsed[i])
|
||||
const itemParsed = JSON.parse(itemStr)
|
||||
if (itemParsed != null) {
|
||||
orders.push(itemParsed as Record<string, any>)
|
||||
orders.push(itemParsed as UTSJSONObject)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -330,34 +351,38 @@ const loadOrderInfo = async () => {
|
||||
|
||||
// 生命周期
|
||||
onLoad((options) => {
|
||||
if (!ensureLoggedIn()) {
|
||||
return
|
||||
}
|
||||
if (options != null) {
|
||||
const orderIdValue = options['orderId']
|
||||
if (orderIdValue != null) {
|
||||
orderId.value = orderIdValue as string
|
||||
const optionsObj = options as UTSJSONObject
|
||||
const orderIdValue = getOptionString(optionsObj, 'orderId')
|
||||
if (orderIdValue != '') {
|
||||
orderId.value = orderIdValue
|
||||
loadOrderInfo()
|
||||
}
|
||||
|
||||
const amountValue = options['amount']
|
||||
if (amountValue != null) {
|
||||
amount.value = parseFloat(amountValue.toString())
|
||||
const amountValue = getOptionString(optionsObj, 'amount')
|
||||
if (amountValue != '') {
|
||||
amount.value = parseFloat(amountValue)
|
||||
}
|
||||
|
||||
// 获取传递的价格详情
|
||||
const productAmountValue = options['productAmount']
|
||||
if (productAmountValue != null) {
|
||||
productAmount.value = parseFloat(productAmountValue.toString())
|
||||
const productAmountValue = getOptionString(optionsObj, 'productAmount')
|
||||
if (productAmountValue != '') {
|
||||
productAmount.value = parseFloat(productAmountValue)
|
||||
}
|
||||
const deliveryFeeValue = options['deliveryFee']
|
||||
if (deliveryFeeValue != null) {
|
||||
deliveryFee.value = parseFloat(deliveryFeeValue.toString())
|
||||
const deliveryFeeValue = getOptionString(optionsObj, 'deliveryFee')
|
||||
if (deliveryFeeValue != '') {
|
||||
deliveryFee.value = parseFloat(deliveryFeeValue)
|
||||
}
|
||||
const discountAmountValue = options['discountAmount']
|
||||
if (discountAmountValue != null) {
|
||||
discountAmount.value = parseFloat(discountAmountValue.toString())
|
||||
const discountAmountValue = getOptionString(optionsObj, 'discountAmount')
|
||||
if (discountAmountValue != '') {
|
||||
discountAmount.value = parseFloat(discountAmountValue)
|
||||
}
|
||||
|
||||
// 如果没有传详情,尝试根据总价估算(兼容旧逻辑,但优先使用传参)
|
||||
if (productAmountValue == null && amount.value > 0) {
|
||||
if (productAmountValue == '' && amount.value > 0) {
|
||||
calculatePriceDetails(amount.value)
|
||||
}
|
||||
|
||||
@@ -476,6 +501,7 @@ const getPayButtonText = (): string => {
|
||||
// 确认支付
|
||||
const confirmPayment = async () => {
|
||||
if (isPaying.value) return
|
||||
if (!ensureLoggedIn()) return
|
||||
|
||||
// 余额支付或银行卡支付检查密码
|
||||
if (selectedMethod.value === 'balance' || selectedMethod.value === 'bankcard') {
|
||||
|
||||
Reference in New Issue
Block a user