import { defineStore } from 'pinia' export const useOrderStore = defineStore('order', { state: () => ({ currentOrder: null, orderList: [], orderStatus: { 0: '待支付', 1: '已支付', 2: '制作中', 3: '已完成', 4: '已取消' } }), getters: { /** * 获取订单状态文本 */ getOrderStatusText: (state) => (status) => { return state.orderStatus[status] || '未知状态' }, /** * 待支付订单数量 */ pendingCount: (state) => { return state.orderList.filter((order) => order.status === 0).length } }, actions: { /** * 设置当前订单 */ setCurrentOrder(order) { this.currentOrder = order }, /** * 设置订单列表 */ setOrderList(list) { this.orderList = list }, /** * 添加订单 */ addOrder(order) { this.orderList.unshift(order) }, /** * 更新订单状态 */ updateOrderStatus(orderId, status) { const order = this.orderList.find((o) => o.id === orderId) if (order) { order.status = status } if (this.currentOrder && this.currentOrder.id === orderId) { this.currentOrder.status = status } }, /** * 清除订单数据 */ clearOrders() { this.currentOrder = null this.orderList = [] } } })