This commit is contained in:
2026-09-29 15:17:13 +08:00
commit 69e6ed8c59
113 changed files with 36564 additions and 0 deletions
+768
View File
@@ -0,0 +1,768 @@
<template>
<view class="checkout-page">
<view class="page-hero">
<AppNavbar class="page-navbar" title="订单结算" show-back/>
</view>
<view class="card block">
<view class="section-title">收货信息</view>
<view class="address" @tap="openAddressPopup">
<view>
<view class="addr-name">
<text v-if="selectedAddress">{{ selectedAddress.name }} {{ selectedAddress.phone }}</text>
<text v-else>请选择收货地址</text>
</view>
<view class="addr-detail">
<text v-if="selectedAddress">{{ getFullAddress(selectedAddress) }}</text>
<text v-else>点击选择或新增收货地址</text>
</view>
</view>
<view class="address-actions">
<view v-if="defaultSelected" class="chip">默认</view>
<view class="choose">更换</view>
</view>
</view>
</view>
<view class="card block">
<view class="section-title">商品信息</view>
<view class="item" v-for="(item, index) in goodsList" :key="index">
<view class="flex justify-start items-start">
<u-image :src="item.image" width="80rpx" height="80rpx" radius="15rpx"/>
<view class="ml-15">
<view class="item-name">{{ item.goodsName }}</view>
<view class="item-meta">x {{ item.num }}</view>
</view>
</view>
<view class="item-price">¥{{ (item.num * item.salePrice).toFixed(2) }}</view>
</view>
<!-- <view class="vendor-sum">小计:¥{{ vendor.subtotal.toFixed(2) }}</view>-->
</view>
<view class="card block">
<view class="section-title">优惠</view>
<view class="row">
<view>优惠券</view>
<view class="coupon" @tap="openCoupon">{{ couponText }}</view>
</view>
<!-- <view class="row">-->
<!-- <view>发票</view>-->
<!-- <switch :checked="invoice" color="#2563eb" @change="invoice = $event.detail.value"/>-->
<!-- </view>-->
</view>
<view class="card block">
<view class="section-title">费用明细</view>
<view class="row">
<view>商品金额</view>
<view>¥{{ goodsTotal }}</view>
</view>
<!-- <view class="row">-->
<!-- <view>运费</view>-->
<!-- <view>¥{{ freightTotal }}</view>-->
<!-- </view>-->
<view class="row">
<view>优惠</view>
<view>-¥{{ discount }}</view>
</view>
<view class="row total">
<view>应付总额</view>
<view class="pay">¥{{ payTotal }}</view>
</view>
</view>
<view class="action-bar">
<view class="sum">合计:¥{{ payTotal }}</view>
<view class="primary-btn submit" @tap="submitOrder">提交订单</view>
</view>
<view v-if="showAddressPopup" class="address-popup-mask" @tap="closeAddressPopup"></view>
<view v-if="showAddressPopup" class="address-popup card" @tap.stop>
<view class="popup-head">
<view class="section-title">选择收货地址</view>
<view class="close-btn" @tap="closeAddressPopup">关闭</view>
</view>
<view v-if="addressLoading" class="popup-empty">加载中...</view>
<view v-else-if="addressList.length === 0" class="popup-empty">
<view class="popup-empty-text">暂无地址</view>
<u-button type="primary" shape="circle" size="mini" @tap="goAddAddress">去新增</u-button>
</view>
<view v-else class="popup-list">
<view
v-for="item in addressList"
:key="item.id"
class="popup-item"
:class="{ active: isSelectedAddress(item) }"
@tap="selectAddress(item)"
>
<view class="popup-item-head">
<view class="addr-name">{{ item.name }} {{ item.phone }}</view>
<view v-if="isDefaultAddress(item)" class="chip">默认</view>
</view>
<view class="addr-detail">{{ getFullAddress(item) }}</view>
</view>
</view>
</view>
<view v-if="showCouponPopup" class="address-popup-mask" @tap="closeCouponPopup"></view>
<view v-if="showCouponPopup" class="coupon-popup card" @tap.stop>
<view class="popup-head">
<view class="section-title">选择优惠券</view>
<view class="close-btn" @tap="closeCouponPopup">关闭</view>
</view>
<view v-if="couponLoading" class="popup-empty">加载中...</view>
<view v-else-if="couponList.length === 0" class="popup-empty">
<view class="popup-empty-text">暂无可用优惠券</view>
</view>
<view v-else class="coupon-list">
<view
v-for="item in couponList"
:key="item.id"
class="coupon-item"
:class="{ active: isSelectedCoupon(item), disabled: !item.available }"
@tap="selectCoupon(item)"
>
<view class="coupon-item-main">
<!-- <view class="coupon-amount">¥{{ item.amount }}</view>-->
<view class="coupon-info">
<view class="coupon-title">{{ item.title }}</view>
<!-- <view class="coupon-desc">{{ item.desc }}</view>-->
<view class="coupon-expire">
有效期:{{ item.expireType === 1 ? item.expireEndDate : `领取后${item.expireDay}天过期` }}
</view>
</view>
</view>
<view class="coupon-right">
<view v-if="!item.available" class="coupon-status">{{ item.statusText }}</view>
<view v-else-if="isSelectedCoupon(item)" class="chip">已选</view>
</view>
</view>
</view>
<view class="coupon-footer">
<view class="text-btn" @tap="clearCoupon">不使用优惠券</view>
</view>
</view>
</view>
</template>
<script>
import {goodsListByIdsReq, orderAddReq} from "@/api/goods";
import {userAddressListReq} from "@/api/address";
import {userCouponListReq} from "@/api/coupon";
import AppNavbar from "@/components/AppNavbar.vue";
export default {
components: {AppNavbar},
data() {
return {
vendors: [],
goodsList: [],
goodsDataList: [],
invoice: false,
addressList: [],
addressLoading: false,
showAddressPopup: false,
selectedAddress: null,
couponSourceList: [],
couponList: [],
couponLoading: false,
showCouponPopup: false,
selectedCoupon: null
}
},
computed: {
goodsTotal() {
return this.goodsList.reduce((sum, v) => sum + parseFloat(v.num * v.salePrice), 0).toFixed(2)
},
freightTotal() {
return 0
},
orderAmountValue() {
return parseFloat(this.goodsTotal) + parseFloat(this.freightTotal)
},
payTotal() {
return (parseFloat(this.goodsTotal) + parseFloat(this.freightTotal) - parseFloat(this.discount)).toFixed(2)
},
defaultSelected() {
return this.selectedAddress ? this.isDefaultAddress(this.selectedAddress) : false
},
discount() {
if (!this.selectedCoupon || !this.selectedCoupon.available) return '0.00'
const orderAmount = this.orderAmountValue
const typeValue = Number(this.selectedCoupon.type)
let discountAmount = 0
if (typeValue === 1) {
let rateValue = Number(this.selectedCoupon.reduceRate || 0)
if (rateValue > 1) {
rateValue = rateValue > 10 ? rateValue / 100 : rateValue / 10
}
rateValue = Math.max(0, Math.min(rateValue, 1))
discountAmount = orderAmount * (1 - rateValue)
} else {
discountAmount = Number(this.selectedCoupon.reduceAmount || 0)
}
const maxDiscount = Math.min(discountAmount, orderAmount)
return maxDiscount.toFixed(2)
},
couponText() {
if (!this.selectedCoupon) return '选择优惠券'
const title = this.selectedCoupon.title || '优惠券'
return `${title} -¥${this.discount}`
}
},
watch: {
orderAmountValue() {
this.refreshCouponList()
}
},
async onLoad(options) {
const rawGoods = options.goodsDataList ? decodeURIComponent(options.goodsDataList) : '[]'
try {
this.goodsDataList = JSON.parse(rawGoods)
} catch (err) {
this.goodsDataList = []
}
await this.getGoodsList()
await this.loadAddressList()
},
methods: {
async getGoodsList() {
if (!this.goodsDataList.length) {
this.vendors = []
return
}
const {data} = await goodsListByIdsReq({
ids: this.goodsDataList.map(item => item.goodsId).join()
})
this.goodsList = data.map(item => {
const goodsData = this.goodsDataList.find(goodsData => goodsData.goodsId === item.goodsId || goodsData.goodsId === item.id)
return {
num: goodsData.num,
...item,
}
})
this.$forceUpdate()
console.log(this.goodsList)
},
async loadAddressList() {
this.addressLoading = true
try {
const {data} = await userAddressListReq()
const list = Array.isArray(data) ? data : (data && data.list ? data.list : [])
this.addressList = list
const defaultItem = list.find(item => this.isDefaultAddress(item))
this.selectedAddress = defaultItem || list[0] || null
} catch (err) {
uni.showToast({
title: '地址加载失败',
icon: 'none'
})
} finally {
this.addressLoading = false
}
},
isDefaultAddress(item) {
return Number(item.isDefault) === 1 || Number(item.is_default) === 1 || item.is_default === true
},
openAddressPopup() {
this.showAddressPopup = true
if (!this.addressList.length) {
this.loadAddressList()
}
},
closeAddressPopup() {
this.showAddressPopup = false
},
selectAddress(item) {
this.selectedAddress = item
this.showAddressPopup = false
},
goAddAddress() {
this.showAddressPopup = false
uni.navigateTo({
url: '/packageUser/address/index'
})
},
isSelectedAddress(item) {
if (!this.selectedAddress) return false
const selectedId = this.selectedAddress.id || this.selectedAddress.addressId || this.selectedAddress.full_address
const itemId = item.id || item.addressId || item.full_address
return selectedId && itemId ? selectedId === itemId : this.getFullAddress(item) === this.getFullAddress(this.selectedAddress)
},
getFullAddress(item) {
if (!item) return ''
return item.fullAddress || item.full_address || `${item.province || ''}${item.city || ''}${item.region || ''}${item.address || ''}`
},
async loadCouponList() {
this.couponLoading = true
try {
const {data} = await userCouponListReq()
const list = Array.isArray(data) ? data : (data && data.list ? data.list : [])
this.couponSourceList = list
this.refreshCouponList()
} catch (err) {
uni.showToast({
title: '优惠券加载失败',
icon: 'none'
})
} finally {
this.couponLoading = false
}
},
openCoupon() {
this.showCouponPopup = true
this.loadCouponList()
},
closeCouponPopup() {
this.showCouponPopup = false
},
selectCoupon(item) {
if (!item.available) {
uni.showToast({
title: '该优惠券不可用',
icon: 'none'
})
return
}
this.selectedCoupon = item
this.showCouponPopup = false
},
clearCoupon() {
this.selectedCoupon = null
this.showCouponPopup = false
},
isSelectedCoupon(item) {
return this.selectedCoupon && item.id && this.selectedCoupon.id === item.id
},
refreshCouponList() {
if (!this.couponSourceList.length) return
this.couponList = this.couponSourceList.map(this.normalizeUserCoupon)
if (this.selectedCoupon) {
const matched = this.couponList.find(item => item.id === this.selectedCoupon.id)
this.selectedCoupon = matched && matched.available ? matched : null
}
},
normalizeUserCoupon(item) {
const coupon = item.coupon || {}
const amount = Number(coupon.amount || item.amount || item.faceValue || item.money || 0)
const statusValue = Number(item.used || item.status)
let available = true
let statusText = '可用'
if (statusValue === 1) {
available = false
statusText = '已使用'
}
if (statusValue === 2) {
available = false
statusText = '已过期'
}
if (!Number.isFinite(statusValue)) {
statusText = '可用'
available = true
}
const startAmount = Number(coupon.startAmount || item.startAmount || 0)
const orderAmount = this.orderAmountValue
if (available && orderAmount < startAmount) {
available = false
statusText = '未满足门槛'
}
return {
id: item.id || item.userCouponId || item.couponId || item.coupon_id,
amount: amount.toFixed(2),
title: coupon.title || item.title || item.name || '优惠券',
desc: item.desc || item.description || item.useRule || '无门槛使用',
expire: item.expire || item.expireTime || item.endTime || '-',
available,
statusText,
expireType: coupon.expireType,
expireEndDate: coupon.expireEndDate,
expireDay: coupon.expireDay,
startAmount,
type: coupon.type || item.type || 0,
reduceAmount: coupon.reduceAmount || item.reduceAmount || 0,
reduceRate: coupon.reduceRate || item.reduceRate || 0
}
},
async submitOrder() {
if (!this.selectedAddress) {
uni.showToast({
title: '请先选择收货地址',
icon: 'none'
})
return
}
uni.showLoading()
const payload = {
goodsList: this.goodsDataList,
name: this.selectedAddress.name,
phone: this.selectedAddress.phone,
address: this.getFullAddress(this.selectedAddress),
}
if (this.selectedCoupon && this.selectedCoupon.id) {
payload.couponId = this.selectedCoupon.id
}
const res = await orderAddReq(payload).catch(err => {
uni.hideLoading()
})
if (res) {
console.log(res)
uni.hideLoading()
uni.requestPayment({
provider: res.data.provider, // 服务提供商
timeStamp: res.data.timeStamp, // 时间戳
nonceStr: res.data.nonceStr, // 随机字符串
package: res.data.package,
signType: res.data.signType, // 签名算法
paySign: res.data.paySign, // 签名
success: function (res) {
uni.showToast({
title: '支付成功',
icon: 'success'
});
setTimeout(function () {
uni.navigateTo({
url: '/pages/order/list'
});
}, 500);
},
fail: function (err) {
console.log('支付失败', err);
uni.navigateTo({
url: '/pages/order/list'
});
}
})
}
}
}
}
</script>
<style lang="scss" scoped>
.checkout-page {
min-height: 100vh;
//padding: 0 20rpx 100rpx;
background: #f5f5f5;
}
.page-hero {
//padding: 30rpx 6rpx 18rpx;
background: url('https://yaodongxiao.oss-cn-guangzhou.aliyuncs.com/20260126/462bfa04cf0eff8698884c38b9d17519.png') no-repeat top center / 100% auto;
}
.page-navbar {
padding: 0 6rpx;
}
.intro-card {
margin-top: 18rpx;
padding: 20rpx 18rpx;
border-radius: 20rpx;
background: rgba(255, 255, 255, 0.9);
box-shadow: 0 10rpx 20rpx rgba(0, 0, 0, 0.08);
}
.card-title {
display: flex;
align-items: center;
gap: 12rpx;
font-size: 28rpx;
font-weight: 700;
color: #1f2937;
}
.title-bar {
width: 6rpx;
height: 30rpx;
border-radius: 999rpx;
background: #2fc6a7;
}
.block {
margin: 18rpx;
}
.address {
display: flex;
justify-content: space-between;
align-items: center;
}
.addr-name {
font-weight: 700;
color: var(--text-main);
}
.addr-detail {
color: var(--text-sub);
font-size: 24rpx;
margin-top: 4rpx;
}
.address-actions {
display: flex;
align-items: center;
gap: 12rpx;
}
.choose {
color: var(--brand-primary);
font-size: 24rpx;
}
.vendor-head {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 6rpx;
}
.vendor-name {
font-weight: 700;
}
.freight {
color: var(--text-sub);
font-size: 24rpx;
}
.item {
display: flex;
justify-content: space-between;
padding: 10rpx 0;
border-bottom: 1rpx solid #edf1f7;
}
.item:last-child {
border-bottom: none;
}
.item-name {
font-weight: 700;
color: var(--text-main);
}
.item-meta {
color: var(--text-sub);
font-size: 24rpx;
margin-top: 4rpx;
}
.item-price {
color: var(--brand-primary);
font-weight: 700;
}
.vendor-sum {
text-align: right;
color: var(--text-main);
font-weight: 700;
margin-top: 8rpx;
}
.row {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10rpx 0;
border-bottom: 1rpx solid #edf1f7;
}
.row:last-child {
border-bottom: none;
}
.coupon {
color: #ff8354;
}
.total {
font-weight: 800;
}
.pay {
color: #ff3b30;
font-size: 32rpx;
}
.action-bar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
display: flex;
align-items: center;
justify-content: space-between;
padding: 12rpx 24rpx;
background: #ffffff;
box-shadow: 0 -6rpx 16rpx rgba(31, 111, 232, 0.08);
}
.address-popup-mask {
position: fixed;
left: 0;
right: 0;
top: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.45);
z-index: 30;
}
.address-popup {
position: fixed;
left: 50%;
bottom: 40rpx;
transform: translateX(-50%);
width: 88%;
max-height: 70vh;
overflow: auto;
z-index: 40;
}
.popup-head {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 12rpx;
}
.popup-empty {
color: var(--text-sub);
text-align: center;
padding: 16rpx 0;
}
.popup-empty-text {
margin-bottom: 12rpx;
}
.popup-empty-btn {
display: inline-flex;
padding: 10rpx 20rpx;
height: 52rpx;
font-size: 24rpx;
}
.popup-list {
display: flex;
flex-direction: column;
gap: 12rpx;
}
.popup-item {
border: 1rpx solid #e7eef8;
border-radius: 14rpx;
padding: 12rpx;
}
.popup-item.active {
border-color: var(--brand-primary);
box-shadow: 0 8rpx 18rpx rgba(31, 111, 232, 0.1);
}
.popup-item-head {
display: flex;
justify-content: space-between;
align-items: center;
}
.coupon-popup {
position: fixed;
left: 50%;
bottom: 40rpx;
transform: translateX(-50%);
width: 88%;
max-height: 70vh;
overflow: auto;
z-index: 40;
}
.coupon-list {
display: flex;
flex-direction: column;
gap: 12rpx;
}
.coupon-item {
display: flex;
justify-content: space-between;
align-items: center;
border: 1rpx solid #e7eef8;
border-radius: 14rpx;
padding: 12rpx;
background: #ffffff;
}
.coupon-item.active {
border-color: var(--brand-primary);
box-shadow: 0 8rpx 18rpx rgba(31, 111, 232, 0.1);
}
.coupon-item.disabled {
opacity: 0.6;
}
.coupon-item-main {
display: flex;
align-items: center;
gap: 12rpx;
}
.coupon-amount {
font-size: 30rpx;
font-weight: 800;
color: #ff3b30;
min-width: 100rpx;
text-align: center;
}
.coupon-info {
flex: 1;
}
.coupon-title {
font-weight: 700;
color: var(--text-main);
}
.coupon-desc,
.coupon-expire {
color: var(--text-sub);
font-size: 24rpx;
margin-top: 2rpx;
}
.coupon-right {
min-width: 70rpx;
display: flex;
justify-content: flex-end;
}
.coupon-status {
color: var(--text-sub);
font-size: 24rpx;
}
.coupon-footer {
margin-top: 12rpx;
text-align: center;
}
.text-btn {
color: var(--brand-primary);
font-size: 24rpx;
}
.close-btn {
color: var(--text-sub);
font-size: 24rpx;
}
.sum {
color: var(--text-main);
font-weight: 800;
}
.submit {
padding: 14rpx 24rpx;
}
</style>
+256
View File
@@ -0,0 +1,256 @@
<template>
<view class="order-detail-page">
<view class="page-hero">
<AppNavbar title="订单详情" show-back/>
</view>
<view class="card block">
<view class="section-title">订单信息</view>
<view class="info-row">
<view>订单号</view>
<view>{{ getOrderNo(order) }}</view>
</view>
<view class="info-row">
<view>状态</view>
<view class="status">{{ statusLabel(order.status) }}</view>
</view>
<view v-if="order.createTime || order.createdAt" class="info-row">
<view>下单时间</view>
<view>{{ order.createTime || order.createdAt }}</view>
</view>
</view>
<view class="card block">
<view class="section-title">收货地址</view>
<view v-if="receiver.name" class="addr-name">{{ receiver.name }} {{ maskPhone(receiver.phone) }}</view>
<view class="addr-detail">{{ receiver.address }}</view>
</view>
<view class="card block">
<view class="section-title">商品清单</view>
<view v-if="items.length === 0" class="empty">暂无商品</view>
<view v-else class="items">
<view class="item" v-for="(item, idx) in items" :key="idx">
<view class="item-name">{{ item.goods.goodsName }}</view>
<view class="item-meta">x {{ item.num || item.qty || 1 }}</view>
<view class="item-price">¥{{ formatPrice(item.goods.salePrice || item.price || item.amount || 0) }}</view>
</view>
</view>
</view>
<view class="card block">
<view class="section-title">费用明细</view>
<view class="info-row">
<view>商品金额</view>
<view>¥{{ formatPrice(order.totalPrice || 0) }}</view>
</view>
<view class="info-row">
<view>运费</view>
<view>¥{{ formatPrice(order.freightAmount || order.freight || 0) }}</view>
</view>
<view class="info-row">
<view>优惠</view>
<view>-¥{{ formatPrice(order.discountAmount || order.discount || 0) }}</view>
</view>
<view class="info-row total">
<view>应付总额</view>
<view class="pay">¥{{ formatPrice(order.orderPrice || order.payPrice || order.amount || 0) }}</view>
</view>
</view>
</view>
</template>
<script>
import {orderInfoReq} from "@/api/goods";
import AppNavbar from "@/components/AppNavbar.vue";
export default {
components: {AppNavbar},
data() {
return {
order: {},
items: [],
receiver: {
name: '',
phone: '',
address: ''
}
}
},
async onLoad(options) {
const id = options.id
if (id) {
await this.fetchOrder(id)
}
},
methods: {
async fetchOrder(id) {
try {
const {data} = await orderInfoReq(id)
this.order = data || {}
this.items = this.order.goodsList || this.order.items || this.order.orderItems || []
this.receiver = this.getReceiverInfo(this.order)
} catch (err) {
uni.showToast({
title: '订单加载失败',
icon: 'none'
})
}
},
getReceiverInfo(order) {
const address = order.address || order.receiverAddress || order.shippingAddress || {}
const name = order.receiverName || order.name || address.name || ''
const phone = order.receiverPhone || order.phone || address.phone || ''
const fullAddress = order.full_address || order.fullAddress || address.full_address || address.fullAddress || ''
const mergedAddress = fullAddress || `${address.province || ''}${address.city || ''}${address.region || ''}${address.address || ''}`
return {
name,
phone,
address: mergedAddress || '暂无地址'
}
},
getOrderNo(order) {
return order.orderNo || order.order_no || order.no || order.id || ''
},
statusLabel(status) {
if (status === 0 || status === 'pending') return '待支付'
if (status === 1 || status === 'paid') return '待发货'
if (status === 2 || status === 'shipped') return '已发货'
if (status === 3 || status === 'completed') return '已完成'
if (status === 4 || status === 'canceled') return '已取消'
return status || '状态未知'
},
formatPrice(value) {
const num = Number(value || 0)
return num.toFixed(2)
},
maskPhone(phone) {
const value = String(phone || '')
if (value.length < 7) return value
return `${value.slice(0, 3)}****${value.slice(-4)}`
}
}
}
</script>
<style lang="scss" scoped>
.order-detail-page {
min-height: 100vh;
//padding: 0 20rpx 40rpx;
background: #f5f5f5;
}
.page-hero {
//padding: 0 6rpx 18rpx;
background: url('https://yaodongxiao.oss-cn-guangzhou.aliyuncs.com/20260126/462bfa04cf0eff8698884c38b9d17519.png') no-repeat
top center / 100% auto;
}
.page-navbar {
padding: 0 6rpx;
}
.intro-card {
margin-top: 18rpx;
padding: 20rpx 18rpx;
border-radius: 20rpx;
background: rgba(255, 255, 255, 0.9);
box-shadow: 0 10rpx 20rpx rgba(0, 0, 0, 0.08);
}
.card-title {
display: flex;
align-items: center;
gap: 12rpx;
font-size: 28rpx;
font-weight: 700;
color: #1f2937;
}
.title-bar {
width: 6rpx;
height: 30rpx;
border-radius: 999rpx;
background: #2fc6a7;
}
.intro-text {
margin-top: 12rpx;
font-size: 26rpx;
color: #6b7280;
line-height: 1.6;
}
.block {
margin: 18rpx;
}
.info-row {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10rpx 0;
border-bottom: 1rpx solid #edf1f7;
font-size: 26rpx;
}
.info-row:last-child {
border-bottom: none;
}
.status {
color: var(--brand-primary);
}
.total {
font-weight: 700;
}
.pay {
color: #ff3b30;
font-weight: 700;
}
.addr-name {
font-weight: 700;
color: var(--text-main);
}
.addr-detail {
margin-top: 6rpx;
color: var(--text-sub);
font-size: 24rpx;
}
.items {
display: flex;
flex-direction: column;
gap: 8rpx;
}
.item {
display: flex;
justify-content: space-between;
font-size: 24rpx;
}
.item-name {
color: var(--text-main);
flex: 1;
}
.item-meta {
color: var(--text-sub);
margin: 0 12rpx;
}
.item-price {
color: #ff3b30;
}
.empty {
color: var(--text-sub);
text-align: center;
padding: 16rpx 0;
}
</style>
+240
View File
@@ -0,0 +1,240 @@
<template>
<view class="order-list-page">
<view class="page-hero">
<AppNavbar title="订单列表" show-back/>
</view>
<view class="card block">
<view v-if="loading" class="empty">加载中...</view>
<view v-else-if="orders.length === 0" class="empty">暂无订单</view>
<view v-else class="order-list">
<view class="order-card" v-for="order in orders" :key="order.orderId">
<view class="order-head">
<view class="order-no">订单号:{{ getOrderNo(order) }}</view>
<view class="order-status">{{ statusLabel(order.orderStatus) }}</view>
</view>
<view v-if="order.createTime || order.createdAt" class="order-time">
下单时间:{{ order.createTime || order.createdAt }}
</view>
<view class="order-items">
<view class="order-item" v-for="(item, idx) in getOrderItems(order)" :key="idx">
<view class="item-name">{{ item.goodsName || item.name || item.title }}</view>
<view class="item-meta">x {{ item.num || item.qty || 1 }}</view>
<view class="item-price">¥{{ formatPrice(item.salePrice || item.price || item.amount || 0) }}</view>
</view>
</view>
<view class="order-footer">
<view class="order-total">合计:¥{{ formatPrice(order.totalAmount || order.amount || order.totalPrice || 0) }}</view>
<view class="ghost-btn" @tap="goDetail(order)">查看详情</view>
</view>
</view>
</view>
</view>
</view>
</template>
<script>
import {orderListReq} from "@/api/goods";
import AppNavbar from "@/components/AppNavbar.vue";
export default {
components: {AppNavbar},
data() {
return {
orders: [],
loading: false
}
},
onShow() {
this.fetchOrders()
},
methods: {
async fetchOrders() {
this.loading = true
try {
const {data} = await orderListReq()
this.orders = Array.isArray(data) ? data : (data && data.list ? data.list : [])
} catch (err) {
uni.showToast({
title: '订单加载失败',
icon: 'none'
})
} finally {
this.loading = false
}
},
getOrderItems(order) {
return order.goodsList || order.items || order.orderItems || []
},
getOrderNo(order) {
return order.orderNo || order.order_no || order.no || order.id || ''
},
statusLabel(status) {
if (status === 1) return '待支付'
if (status === 2) return '待发货'
if (status === 3 ) return '已发货'
if (status === 4 ) return '已完成'
if (status === 5 ) return '退款中'
if (status === 6 ) return '退款成功'
if (status === 7 ) return '退款失败'
if (status === 0 ) return '已取消'
return status || '状态未知'
},
formatPrice(value) {
const num = Number(value || 0)
return num.toFixed(2)
},
goDetail(order) {
console.log(order.orderId)
uni.navigateTo({
url: `/pages/order/detail?id=${order.orderId}`
})
}
}
}
</script>
<style lang="scss" scoped>
.order-list-page {
min-height: 100vh;
//padding: 0 20rpx 40rpx;
background: #f5f5f5;
}
.page-hero {
//padding: 30rpx 6rpx 18rpx;
background: url('https://yaodongxiao.oss-cn-guangzhou.aliyuncs.com/20260126/462bfa04cf0eff8698884c38b9d17519.png') no-repeat
top center / 100% auto;
}
.page-navbar {
padding: 0 6rpx;
}
.intro-card {
margin: 18rpx 20rpx 0;
padding: 20rpx 18rpx;
border-radius: 20rpx;
background: rgba(255, 255, 255, 0.9);
box-shadow: 0 10rpx 20rpx rgba(0, 0, 0, 0.08);
}
.card-title {
display: flex;
align-items: center;
gap: 12rpx;
font-size: 28rpx;
font-weight: 700;
color: #1f2937;
}
.title-bar {
width: 6rpx;
height: 30rpx;
border-radius: 999rpx;
background: #2fc6a7;
}
.intro-text {
margin-top: 12rpx;
font-size: 26rpx;
color: #6b7280;
line-height: 1.6;
}
.block {
margin: 18rpx 20rpx 0;
}
.order-list {
display: flex;
flex-direction: column;
gap: 14rpx;
}
.order-card {
border: 1rpx solid #e7eef8;
border-radius: 16rpx;
padding: 16rpx;
background: #ffffff;
}
.order-head {
display: flex;
justify-content: space-between;
align-items: center;
}
.order-no {
color: var(--text-main);
font-weight: 700;
}
.order-status {
color: var(--brand-primary);
font-size: 24rpx;
}
.order-time {
margin-top: 6rpx;
color: var(--text-sub);
font-size: 24rpx;
}
.order-items {
margin-top: 12rpx;
border-top: 1rpx dashed #e7eef8;
padding-top: 12rpx;
}
.order-item {
display: flex;
justify-content: space-between;
margin-bottom: 6rpx;
font-size: 24rpx;
}
.order-item:last-child {
margin-bottom: 0;
}
.item-name {
color: var(--text-main);
flex: 1;
}
.item-meta {
color: var(--text-sub);
margin: 0 12rpx;
}
.item-price {
color: #ff3b30;
}
.order-footer {
margin-top: 12rpx;
display: flex;
justify-content: space-between;
align-items: center;
}
.order-total {
color: var(--text-main);
font-weight: 700;
}
.ghost-btn {
color: var(--brand-primary);
border: 1rpx solid var(--brand-primary);
padding: 6rpx 16rpx;
border-radius: 999rpx;
font-size: 24rpx;
}
.empty {
color: var(--text-sub);
text-align: center;
padding: 16rpx 0;
}
</style>