diff --git a/src/api/order.js b/src/api/order.js
index 0953ef0..1c63edd 100644
--- a/src/api/order.js
+++ b/src/api/order.js
@@ -53,6 +53,20 @@ export default {
return api.request(`/orders/${id}/refund`, 'PUT')
},
+ /**
+ * 更新订单状态
+ */
+ updateOrderStatus(id, status) {
+ return api.request(`/orders/${id}/status`, 'PUT', { status })
+ },
+
+ /**
+ * 更新订单(编辑)
+ */
+ updateOrder(id, data) {
+ return api.request(`/orders/${id}`, 'PUT', data)
+ },
+
/**
* 订单统计
*/
diff --git a/src/pages/order/create.vue b/src/pages/order/create.vue
index d58bde6..91047b1 100644
--- a/src/pages/order/create.vue
+++ b/src/pages/order/create.vue
@@ -164,13 +164,49 @@ export default {
// 其他
paymentMethod: 'cash',
- remark: ''
+ remark: '',
+
+ // 编辑模式
+ editingOrderId: null
}
},
- onLoad() {
+ onLoad(options) {
this.loadCustomers()
this.loadProducts()
+ if (options.orderId) {
+ this.editingOrderId = options.orderId
+ this.loadOrder(options.orderId)
+ }
},
+ methods: {
+ async loadOrder(orderId) {
+ try {
+ const detail = await orderApi.getOrderDetail(orderId)
+ const order = detail.order
+
+ // 设置订单信息
+ if (order.customerId) {
+ this.selectedCustomer = this.customers.find(c => c.customerId === order.customerId)
+ }
+
+ this.orderItems = (detail.items || []).map(item => ({
+ productId: item.productId,
+ productName: item.productName,
+ spec: item.productSpec,
+ unit: item.unit,
+ price: item.price,
+ quantity: item.quantity
+ }))
+
+ this.discountRate = order.discountRate
+ this.remark = order.remark || ''
+ this.paymentMethod = order.paymentMethod || 'cash'
+
+ this.calcAmount()
+ } catch (e) {
+ console.error(e)
+ }
+ },
methods: {
async loadCustomers() {
try {
@@ -248,19 +284,25 @@ export default {
}
try {
- const order = await orderApi.createOrder(data)
+ let order
+ if (this.editingOrderId) {
+ order = await orderApi.updateOrder(this.editingOrderId, data)
+ uni.showToast({ title: '订单更新成功', icon: 'success' })
+ } else {
+ order = await orderApi.createOrder(data)
+ uni.showToast({ title: '订单创建成功', icon: 'success' })
+ }
- uni.showToast({ title: '订单创建成功', icon: 'success' })
-
- // 跳转到订单详情或列表
+ // 跳转到订单列表(未完成)
setTimeout(() => {
- uni.navigateTo({
- url: `/pages/order/list`
+ uni.switchTab({
+ url: '/pages/order/list?status=0'
})
}, 1500)
} catch (e) {
console.error(e)
}
+ }
}
}
}
diff --git a/src/pages/order/list.vue b/src/pages/order/list.vue
index 5b73e2c..c798882 100644
--- a/src/pages/order/list.vue
+++ b/src/pages/order/list.vue
@@ -9,6 +9,13 @@
>
全部
+
+ 未完成
+
{{ formatTime(order.createdAt) }}
- {{ order.operatorName }}
+
+ 确认
+ 取消
+ 编辑
+
+ {{ order.operatorName }}
@@ -99,7 +111,10 @@ export default {
loading: false
}
},
- onLoad() {
+ onLoad(options) {
+ if (options.status) {
+ this.status = parseInt(options.status)
+ }
this.loadOrders()
},
onReachBottom() {
@@ -178,6 +193,7 @@ export default {
},
getStatusText(status) {
const map = {
+ 0: '未完成',
1: '已完成',
2: '已取消',
3: '退款中',
@@ -188,6 +204,45 @@ export default {
formatTime(time) {
if (!time) return '-'
return time.substring(0, 16).replace('T', ' ')
+ },
+ async confirmOrder(order) {
+ uni.showModal({
+ title: '确认订单',
+ content: '确认完成后订单将变为已完成状态',
+ success: async (res) => {
+ if (res.confirm) {
+ try {
+ await orderApi.updateOrderStatus(order.orderId, 1)
+ uni.showToast({ title: '已确认', icon: 'success' })
+ this.loadOrders()
+ } catch (e) {
+ uni.showToast({ title: '操作失败', icon: 'none' })
+ }
+ }
+ }
+ })
+ },
+ async cancelOrder(order) {
+ uni.showModal({
+ title: '取消订单',
+ content: '确定要取消该订单吗?',
+ success: async (res) => {
+ if (res.confirm) {
+ try {
+ await orderApi.cancelOrder(order.orderId)
+ uni.showToast({ title: '已取消', icon: 'success' })
+ this.loadOrders()
+ } catch (e) {
+ uni.showToast({ title: '操作失败', icon: 'none' })
+ }
+ }
+ }
+ })
+ },
+ editOrder(order) {
+ uni.navigateTo({
+ url: `/pages/order/create?orderId=${order.orderId}`
+ })
}
}
}
@@ -357,6 +412,32 @@ export default {
color: #999;
}
+.order-actions {
+ display: flex;
+ gap: 16rpx;
+}
+
+.action-btn {
+ font-size: 24rpx;
+ padding: 8rpx 16rpx;
+ border-radius: 4rpx;
+}
+
+.action-btn.confirm {
+ background: #3cc51f;
+ color: #fff;
+}
+
+.action-btn.cancel {
+ background: #fff1f0;
+ color: #ff4d4f;
+}
+
+.action-btn.edit {
+ background: #e6f7ff;
+ color: #1890ff;
+}
+
.empty {
padding: 100rpx;
text-align: center;