refactor(backend): 重构动物相关 API 接口

- 更新了动物数据结构和相关类型定义
- 优化了动物列表、详情、创建、更新和删除接口
- 新增了更新动物状态接口
- 移除了与认领记录相关的接口
-调整了 API 响应结构
This commit is contained in:
ylweng
2025-08-31 00:45:46 +08:00
parent 0cad74b06f
commit 8e5295b572
111 changed files with 15290 additions and 1972 deletions

View File

@@ -39,20 +39,22 @@
</template>
<script>
import { userService, orderService } from '../../api/services.js'
export default {
data() {
return {
user: {
avatar: '/static/user/avatar.jpg',
nickname: '旅行爱好者',
memberLevel: '黄金会员'
nickname: '',
memberLevel: ''
},
orderStatus: [
{ type: 'all', text: '全部订单', count: 5 },
{ type: 'unpaid', text: '待付款', count: 1 },
{ type: 'undelivered', text: '待发货', count: 1 },
{ type: 'delivered', text: '待收货', count: 2 },
{ type: 'completed', text: '已完成', count: 1 }
{ type: 'all', text: '全部订单', count: 0 },
{ type: 'unpaid', text: '待付款', count: 0 },
{ type: 'undelivered', text: '待发货', count: 0 },
{ type: 'delivered', text: '待收货', count: 0 },
{ type: 'completed', text: '已完成', count: 0 }
],
functions: [
{ icon: 'heart', text: '我的认养', url: '/pages/user/adoptions' },
@@ -63,10 +65,45 @@ export default {
]
}
},
onShow() {
this.loadUserProfile()
this.loadOrderStats()
},
methods: {
async loadUserProfile() {
try {
const data = await userService.getProfile()
this.user = {
...this.user,
...data
}
} catch (error) {
console.error('获取用户信息失败:', error)
}
},
async loadOrderStats() {
try {
// 这里应该调用一个专门获取订单统计的接口
// 暂时使用模拟数据
/*
const stats = await orderService.getStats()
this.orderStatus = this.orderStatus.map(item => ({
...item,
count: stats[item.type] || 0
}))
*/
} catch (error) {
console.error('获取订单统计失败:', error)
}
},
navigateTo(url) {
uni.navigateTo({ url })
},
navigateToOrder(type) {
uni.navigateTo({ url: `/pages/user/orders?type=${type}` })
}
@@ -103,16 +140,13 @@ export default {
.username {
font-size: 36rpx;
font-weight: bold;
color: #333;
margin-bottom: 10rpx;
}
.member-level {
font-size: 24rpx;
color: #ff9500;
background-color: #fff8e6;
padding: 4rpx 16rpx;
border-radius: 20rpx;
align-self: flex-start;
font-size: 28rpx;
color: #ff6b35;
}
.order-status {
@@ -130,7 +164,8 @@ export default {
}
.count {
font-size: 32rpx;
font-size: 36rpx;
font-weight: bold;
color: #333;
margin-bottom: 10rpx;
}
@@ -148,13 +183,17 @@ export default {
display: flex;
align-items: center;
padding: 30rpx;
border-bottom: 1rpx solid #f5f5f5;
border-bottom: 1rpx solid #eee;
}
.function-item .text {
.function-item:last-child {
border-bottom: none;
}
.text {
flex: 1;
margin-left: 20rpx;
font-size: 28rpx;
font-size: 30rpx;
color: #333;
}
</style>

View File

@@ -11,7 +11,7 @@
>
<text>{{ tab.text }}</text>
</view>
</view>
</tab-bar>
<!-- 订单列表 -->
<scroll-view
@@ -49,256 +49,191 @@
</view>
</view>
<!-- 订单底部 -->
<view class="order-footer">
<text class="order-total">{{ order.count }}件商品 合计¥{{ order.price * order.count }}</text>
<view class="order-actions">
<button
v-if="order.status === 'unpaid'"
class="action-btn primary"
@click.stop="payOrder(order.id)"
>立即付款</button>
<button
v-if="order.status === 'delivered'"
class="action-btn primary"
@click.stop="confirmReceive(order.id)"
>确认收货</button>
<button
v-if="order.status === 'completed'"
class="action-btn"
@click.stop="reviewOrder(order.id)"
>评价</button>
<button
class="action-btn"
@click.stop="deleteOrder(order.id)"
>删除订单</button>
</view>
<!-- 订单操作 -->
<view class="order-actions">
<button
v-for="action in getAvailableActions(order.status)"
:key="action.type"
class="action-btn"
:class="action.type"
@click.stop="handleAction(action.type, order)"
>
{{ action.text }}
</button>
</view>
</view>
<!-- 加载更多 -->
<view v-if="loading" class="loading">
<!-- 加载更多提示 -->
<view class="load-more" v-if="loading">
<text>加载中...</text>
</view>
<view v-if="noMore && orders.length > 0" class="no-more">
<text>没有更多订单了</text>
<view class="load-more" v-else-if="hasMore">
<text>上拉加载更多</text>
</view>
<view class="load-more" v-else-if="orders.length > 0">
<text>没有更多了</text>
</view>
</scroll-view>
</view>
</template>
<script>
import { orderService } from '../../api/services.js'
export default {
data() {
return {
tabs: [
{ text: '全部', type: 'all' },
{ text: '待付款', type: 'unpaid' },
{ text: '待发货', type: 'undelivered' },
{ text: '待收货', type: 'delivered' },
{ text: '已完成', type: 'completed' }
],
currentTab: 0,
tabs: [
{ type: 'all', text: '全部' },
{ type: 'unpaid', text: '待付款' },
{ type: 'undelivered', text: '待发货' },
{ type: 'delivered', text: '待收货' },
{ type: 'completed', text: '已完成' }
],
orders: [],
page: 1,
loading: false,
noMore: false
hasMore: true,
page: 1,
pageSize: 10,
statusFilter: 'all'
}
},
onLoad(options) {
// 如果有传入类型参数,切换到对应选项卡
if (options.type) {
const index = this.tabs.findIndex(tab => tab.type === options.type)
if (index !== -1) {
this.currentTab = index
const tabIndex = this.tabs.findIndex(tab => tab.type === options.type)
if (tabIndex !== -1) {
this.currentTab = tabIndex
this.statusFilter = options.type
}
}
this.loadOrders()
},
methods: {
switchTab(index) {
if (this.currentTab === index) return
this.currentTab = index
this.page = 1
this.orders = []
this.noMore = false
this.loadOrders()
},
loadOrders() {
if (this.loading || this.noMore) return
async loadOrders() {
if (this.loading || !this.hasMore) return
this.loading = true
// 模拟API请求
setTimeout(() => {
const type = this.tabs[this.currentTab].type
const newOrders = this.getMockOrders(type, this.page)
try {
const params = {
page: this.page,
pageSize: this.pageSize
}
if (newOrders.length === 0) {
this.noMore = true
if (this.statusFilter !== 'all') {
params.status = this.statusFilter
}
const data = await orderService.getList(params)
const newOrders = data.orders || data
if (this.page === 1) {
this.orders = newOrders
} else {
this.orders = [...this.orders, ...newOrders]
this.page++
}
this.hasMore = newOrders.length === this.pageSize
this.page++
} catch (error) {
console.error('获取订单列表失败:', error)
uni.showToast({
title: '获取订单失败',
icon: 'none'
})
} finally {
this.loading = false
}, 1000)
}
},
loadMore() {
async loadMore() {
if (this.hasMore && !this.loading) {
this.loadOrders()
}
},
switchTab(index) {
this.currentTab = index
this.statusFilter = this.tabs[index].type
this.page = 1
this.orders = []
this.hasMore = true
this.loadOrders()
},
getMockOrders(type, page) {
// 模拟数据实际应从API获取
const allOrders = [
{
id: '1001',
type: 'travel',
status: 'unpaid',
title: '西藏旅行计划',
description: '10月1日-10月7日',
price: 5000,
count: 1,
image: '/static/travel/tibet.jpg'
},
{
id: '1002',
type: 'animal',
status: 'undelivered',
title: '小羊驼认养',
description: '认养期限1年',
price: 1000,
count: 1,
image: '/static/animals/alpaca.jpg'
},
{
id: '1003',
type: 'flower',
status: 'delivered',
title: '浪漫玫瑰花束',
description: '11朵红玫瑰',
price: 199,
count: 1,
image: '/static/flowers/rose.jpg'
},
{
id: '1004',
type: 'flower',
status: 'completed',
title: '向日葵花束',
description: '9朵向日葵',
price: 179,
count: 1,
image: '/static/flowers/sunflower.jpg'
}
]
// 根据类型筛选
let filteredOrders = allOrders
if (type !== 'all') {
filteredOrders = allOrders.filter(order => order.status === type)
}
// 分页
const pageSize = 5
const start = (page - 1) * pageSize
const end = page * pageSize
return filteredOrders.slice(start, end)
},
getOrderTypeName(type) {
const typeMap = {
const types = {
travel: '旅行计划',
animal: '动物认养',
flower: '送花服务'
}
return typeMap[type] || '订单'
return types[type] || '未知类型'
},
getStatusText(status) {
const statusMap = {
const statuses = {
unpaid: '待付款',
undelivered: '待发货',
delivered: '待收货',
completed: '已完成'
completed: '已完成',
cancelled: '已取消'
}
return statusMap[status] || '未知状态'
return statuses[status] || '未知状态'
},
getAvailableActions(status) {
const actions = {
unpaid: [
{ type: 'cancel', text: '取消订单' },
{ type: 'pay', text: '立即付款' }
],
undelivered: [
{ type: 'cancel', text: '取消订单' }
],
delivered: [
{ type: 'confirm', text: '确认收货' }
],
completed: [],
cancelled: []
}
return actions[status] || []
},
async handleAction(actionType, order) {
try {
switch (actionType) {
case 'cancel':
await orderService.cancel(order.id)
uni.showToast({ title: '订单已取消' })
break
case 'pay':
// 跳转到支付页面
uni.navigateTo({ url: `/pages/payment/index?orderId=${order.id}` })
return
case 'confirm':
await orderService.confirm(order.id)
uni.showToast({ title: '已确认收货' })
break
}
// 重新加载订单列表
this.page = 1
this.orders = []
this.hasMore = true
this.loadOrders()
} catch (error) {
console.error('操作失败:', error)
uni.showToast({
title: '操作失败',
icon: 'none'
})
}
},
navigateToDetail(id) {
uni.navigateTo({
url: `/pages/user/order-detail?id=${id}`
})
},
payOrder(id) {
uni.showModal({
title: '支付提示',
content: '确定要支付此订单吗?',
success: (res) => {
if (res.confirm) {
// 模拟支付流程
uni.showLoading({
title: '支付中...'
})
setTimeout(() => {
uni.hideLoading()
uni.showToast({
title: '支付成功',
icon: 'success'
})
// 更新订单状态
this.updateOrderStatus(id, 'undelivered')
}, 1500)
}
}
})
},
confirmReceive(id) {
uni.showModal({
title: '确认收货',
content: '确认已收到商品吗?',
success: (res) => {
if (res.confirm) {
uni.showToast({
title: '确认成功',
icon: 'success'
})
// 更新订单状态
this.updateOrderStatus(id, 'completed')
}
}
})
},
reviewOrder(id) {
uni.navigateTo({
url: `/pages/user/review?id=${id}`
})
},
deleteOrder(id) {
uni.showModal({
title: '删除订单',
content: '确定要删除此订单吗?',
success: (res) => {
if (res.confirm) {
// 从列表中移除
const index = this.orders.findIndex(order => order.id === id)
if (index !== -1) {
this.orders.splice(index, 1)
uni.showToast({
title: '删除成功',
icon: 'success'
})
}
}
}
})
},
updateOrderStatus(id, newStatus) {
const order = this.orders.find(order => order.id === id)
if (order) {
order.status = newStatus
}
uni.navigateTo({ url: `/pages/order/detail?id=${id}` })
}
}
}
@@ -306,101 +241,78 @@ export default {
<style scoped>
.container {
display: flex;
flex-direction: column;
height: 100vh;
background-color: #f8f9fa;
min-height: 100vh;
}
.tab-bar {
display: flex;
background-color: #fff;
border-bottom: 1rpx solid #eee;
position: sticky;
top: 0;
z-index: 10;
}
.tab-item {
flex: 1;
height: 80rpx;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
padding: 30rpx 0;
font-size: 28rpx;
color: #666;
position: relative;
}
.tab-item.active {
color: #007aff;
}
.tab-item.active::after {
content: '';
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
width: 40rpx;
height: 4rpx;
background-color: #007aff;
border-bottom: 4rpx solid #007aff;
}
.order-list {
flex: 1;
padding: 20rpx;
height: calc(100vh - 100rpx);
}
.empty-tip {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 100rpx 0;
}
.empty-image {
width: 200rpx;
height: 200rpx;
margin-bottom: 20rpx;
margin-bottom: 30rpx;
}
.order-item {
background-color: #fff;
margin: 20rpx;
border-radius: 10rpx;
margin-bottom: 20rpx;
overflow: hidden;
box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
}
.order-header {
display: flex;
justify-content: space-between;
padding: 20rpx;
border-bottom: 1rpx solid #f5f5f5;
padding: 20rpx 30rpx;
border-bottom: 1rpx solid #eee;
}
.order-type {
font-size: 28rpx;
font-weight: bold;
color: #333;
}
.order-status {
font-size: 28rpx;
color: #ff9500;
color: #ff6b35;
}
.order-content {
display: flex;
padding: 20rpx;
border-bottom: 1rpx solid #f5f5f5;
padding: 30rpx;
}
.order-image {
width: 160rpx;
height: 160rpx;
border-radius: 8rpx;
width: 150rpx;
height: 150rpx;
border-radius: 10rpx;
margin-right: 20rpx;
}
@@ -408,73 +320,65 @@ export default {
flex: 1;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.order-title {
font-size: 28rpx;
font-size: 30rpx;
font-weight: bold;
color: #333;
margin-bottom: 10rpx;
}
.order-desc {
font-size: 24rpx;
color: #999;
font-size: 24rpx;
margin-bottom: 10rpx;
}
.order-price-box {
display: flex;
justify-content: space-between;
margin-top: auto;
}
.order-price {
font-size: 28rpx;
color: #ff2d55;
color: #ff6b35;
font-weight: bold;
}
.order-count {
font-size: 24rpx;
color: #999;
}
.order-footer {
padding: 20rpx;
}
.order-total {
font-size: 24rpx;
color: #666;
text-align: right;
margin-bottom: 20rpx;
}
.order-actions {
display: flex;
justify-content: flex-end;
padding: 20rpx 30rpx;
border-top: 1rpx solid #eee;
}
.action-btn {
padding: 10rpx 20rpx;
margin-left: 20rpx;
font-size: 24rpx;
padding: 0 30rpx;
height: 60rpx;
line-height: 60rpx;
border-radius: 6rpx;
font-size: 26rpx;
border: 1rpx solid #ddd;
background-color: #fff;
color: #666;
}
.action-btn.primary {
background-color: #007aff;
color: #fff;
border: none;
.action-btn.cancel {
color: #ff3b30;
border-color: #ff3b30;
}
.loading, .no-more {
.action-btn.pay, .action-btn.confirm {
color: #007aff;
border-color: #007aff;
}
.load-more {
text-align: center;
padding: 20rpx 0;
font-size: 24rpx;
padding: 30rpx;
color: #999;
font-size: 26rpx;
}
</style>