consumer模块完成度95%,安卓端大部分页面能正常获取数据,页面样式显示基本正常,逐渐完善;消费者端的积分、余额、评价、优惠券等小模块正在完善
This commit is contained in:
@@ -35,50 +35,142 @@
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import { supabaseService } from '@/utils/supabaseService.uts'
|
||||
|
||||
const orderId = ref('')
|
||||
const productImage = ref('/static/product1.jpg')
|
||||
const logisticsStatus = ref('运输中')
|
||||
const courierName = ref('顺丰速运')
|
||||
const courierPhone = ref('95338')
|
||||
const trackingNo = ref('SF1234567890')
|
||||
const logisticsStatus = ref('暂无物流信息')
|
||||
const courierName = ref('')
|
||||
const courierPhone = ref('')
|
||||
const trackingNo = ref('')
|
||||
|
||||
type TrackItem = {
|
||||
desc: string
|
||||
desc: string,
|
||||
time: string
|
||||
}
|
||||
|
||||
const trackList = ref<TrackItem[]>([
|
||||
{
|
||||
desc: '【深圳市】快件已到达 深圳南山集散中心',
|
||||
time: '2024-01-26 14:30:00'
|
||||
},
|
||||
{
|
||||
desc: '【广州市】快件已从 广州转运中心 发出,准备发往 深圳南山集散中心',
|
||||
time: '2024-01-26 09:20:00'
|
||||
},
|
||||
{
|
||||
desc: '【广州市】快件已到达 广州转运中心',
|
||||
time: '2024-01-25 22:15:00'
|
||||
},
|
||||
{
|
||||
desc: '【杭州市】商家已发货',
|
||||
time: '2024-01-25 18:00:00'
|
||||
}
|
||||
])
|
||||
const trackList = ref<TrackItem[]>([])
|
||||
|
||||
// 加载物流信息函数 - 必须在 onLoad 之前定义
|
||||
const loadLogisticsInfo = async () => {
|
||||
if (orderId.value == '') return
|
||||
|
||||
try {
|
||||
console.log('[logistics] 开始加载物流信息, orderId:', orderId.value)
|
||||
const order = await supabaseService.getOrderDetail(orderId.value)
|
||||
console.log('[logistics] 获取订单结果:', order != null ? '成功' : '失败')
|
||||
|
||||
if (order != null) {
|
||||
const orderStr = JSON.stringify(order)
|
||||
console.log('[logistics] 订单JSON:', orderStr)
|
||||
const orderParsed = JSON.parse(orderStr)
|
||||
if (orderParsed == null) {
|
||||
console.error('[logistics] 解析订单数据失败')
|
||||
return
|
||||
}
|
||||
const orderObj = orderParsed as UTSJSONObject
|
||||
|
||||
// 获取物流信息
|
||||
const trackingNoVal = orderObj.getString('tracking_no')
|
||||
const carrierNameVal = orderObj.getString('carrier_name')
|
||||
const shippingStatus = orderObj.getNumber('shipping_status')
|
||||
|
||||
console.log('[logistics] tracking_no:', trackingNoVal)
|
||||
console.log('[logistics] carrier_name:', carrierNameVal)
|
||||
console.log('[logistics] shipping_status:', shippingStatus)
|
||||
|
||||
if (trackingNoVal != null && trackingNoVal != '') {
|
||||
trackingNo.value = trackingNoVal
|
||||
} else {
|
||||
console.log('[logistics] 物流单号为空,订单可能未发货')
|
||||
// 物流单号为空时显示提示
|
||||
trackingNo.value = '暂无物流单号'
|
||||
logisticsStatus.value = '商家未填写物流信息'
|
||||
}
|
||||
|
||||
if (carrierNameVal != null && carrierNameVal != '') {
|
||||
courierName.value = carrierNameVal
|
||||
// 根据快递公司设置电话
|
||||
if (carrierNameVal.includes('顺丰')) {
|
||||
courierPhone.value = '95338'
|
||||
} else if (carrierNameVal.includes('中通')) {
|
||||
courierPhone.value = '95311'
|
||||
} else if (carrierNameVal.includes('圆通')) {
|
||||
courierPhone.value = '95554'
|
||||
} else if (carrierNameVal.includes('韵达')) {
|
||||
courierPhone.value = '95546'
|
||||
} else if (carrierNameVal.includes('申通')) {
|
||||
courierPhone.value = '95543'
|
||||
} else {
|
||||
courierPhone.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
// 根据发货状态设置物流状态
|
||||
if (shippingStatus == 2) {
|
||||
logisticsStatus.value = '已签收'
|
||||
} else if (shippingStatus == 1) {
|
||||
logisticsStatus.value = '运输中'
|
||||
} else {
|
||||
logisticsStatus.value = '待发货'
|
||||
}
|
||||
|
||||
// 获取商品图片
|
||||
const itemsRaw = orderObj.get('ml_order_items')
|
||||
if (itemsRaw != null && Array.isArray(itemsRaw)) {
|
||||
const items = itemsRaw as any[]
|
||||
if (items.length > 0) {
|
||||
const firstItem = items[0]
|
||||
const itemStr = JSON.stringify(firstItem)
|
||||
const itemParsed = JSON.parse(itemStr)
|
||||
if (itemParsed != null) {
|
||||
const itemObj = itemParsed as UTSJSONObject
|
||||
const imgUrl = itemObj.getString('image_url')
|
||||
if (imgUrl != null && imgUrl != '') {
|
||||
productImage.value = imgUrl
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 构建物流轨迹(如果有发货时间)
|
||||
const shippedAt = orderObj.getString('shipped_at')
|
||||
if (shippedAt != null && shippedAt != '') {
|
||||
const trackItem: TrackItem = {
|
||||
desc: '商家已发货,等待快递揽收',
|
||||
time: shippedAt
|
||||
}
|
||||
trackList.value.push(trackItem)
|
||||
}
|
||||
|
||||
// 如果已签收,添加签收信息
|
||||
const deliveredAt = orderObj.getString('delivered_at')
|
||||
if (deliveredAt != null && deliveredAt != '') {
|
||||
const trackItem: TrackItem = {
|
||||
desc: '快件已签收',
|
||||
time: deliveredAt
|
||||
}
|
||||
trackList.value.unshift(trackItem)
|
||||
logisticsStatus.value = '已签收'
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('加载物流信息失败:', e)
|
||||
}
|
||||
}
|
||||
|
||||
onLoad((options) => {
|
||||
if (options == null) return
|
||||
const orderIdValue = options['orderId']
|
||||
if (orderIdValue != null) {
|
||||
orderId.value = orderIdValue as string
|
||||
loadLogisticsInfo()
|
||||
}
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
const pages = getCurrentPages()
|
||||
const currentPage = pages[pages.length - 1]
|
||||
const options = currentPage.options
|
||||
if (options != null) {
|
||||
const optionsObj = options as UTSJSONObject
|
||||
const orderIdValue = optionsObj.getString('orderId')
|
||||
if (orderIdValue != null) {
|
||||
orderId.value = orderIdValue
|
||||
// 这里可以根据orderId去请求真实的物流信息
|
||||
}
|
||||
}
|
||||
// 逻辑已移到 onLoad
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user