You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
{"ast":null,"code":"import { ref, reactive, computed } from 'vue';\nimport { useRouter } from 'vue-router';\nimport store from '@/store';\nimport { ElMessage, ElMessageBox } from 'element-plus';\nimport { getAllOrders, updateOrderStatus } from '@/api/order';\nexport default {\n __name: 'OrderManagement',\n setup(__props, {\n expose: __expose\n }) {\n __expose();\n const router = useRouter();\n const loading = ref(false);\n const updating = ref(false);\n const orderList = ref([]);\n const total = ref(0);\n const currentPage = ref(1);\n const pageSize = ref(10);\n const statusDialogVisible = ref(false);\n const currentOrder = ref(null);\n const searchForm = reactive({\n customerId: ''\n });\n const statusForm = reactive({\n status: ''\n });\n\n // 状态选项\n const statusOptions = computed(() => {\n const userRoles = store.state.userInfo?.roles || [];\n const currentStatus = currentOrder.value?.status;\n\n // 基础状态映射\n const baseOptions = {\n 0: '待处理',\n 1: '待发货',\n 2: '已发货',\n 3: '运输中',\n 4: '已送达',\n 5: '已完成',\n 6: '已取消'\n };\n\n // 系统管理员可以修改为任意状态\n if (userRoles.includes('ROLE_ADMIN')) {\n return baseOptions;\n }\n\n // 仓库管理员只能将订单从\"待处理\"改为\"待发货\"\n if (userRoles.includes('ROLE_WAREHOUSE_ADMIN')) {\n return currentStatus === 0 ? {\n 1: '待发货'\n } : {};\n }\n\n // 物流管理员的状态流转\n if (userRoles.includes('ROLE_LOGISTICS_ADMIN')) {\n switch (currentStatus) {\n case 1:\n return {\n 2: '已发货'\n };\n case 2:\n return {\n 3: '运输中'\n };\n case 3:\n return {\n 4: '已送达'\n };\n case 4:\n return {\n 5: '已完成'\n };\n default:\n return {};\n }\n }\n return {};\n });\n\n // 判断是否可以修改状态\n const canUpdateStatus = status => {\n const userRoles = store.state.userInfo?.roles || [];\n\n // 系统管理员可以修改任意状态\n if (userRoles.includes('ROLE_ADMIN')) {\n return status !== 5 && status !== 6; // 已完成和已取消的订单不能修改\n }\n\n // 仓库管理员只能修改待处理的订单\n if (userRoles.includes('ROLE_WAREHOUSE_ADMIN')) {\n return status === 0;\n }\n\n // 物流管理员可以修改的状态\n if (userRoles.includes('ROLE_LOGISTICS_ADMIN')) {\n return status >= 1 && status <= 4; // 可以修改待发货到已送达的订单\n }\n return false;\n };\n\n // 获取状态文本\n const getStatusText = status => {\n const statusMap = {\n 0: '待处理',\n 1: '待发货',\n 2: '已发货',\n 3: '运输中',\n 4: '已送达',\n 5: '已完成',\n 6: '已取消'\n };\n return statusMap[status] || '未知状态';\n };\n\n // 加载订单列表\n const loadOrders = async () => {\n loading.value = true;\n try {\n const res = await getAllOrders({\n pageNum: currentPage.value,\n pageSize: pageSize.value,\n customerId: searchForm.customerId || undefined\n });\n if (res.code === 200) {\n orderList.value = res.data.records;\n total.value = res.data.total;\n currentPage.value = res.data.current;\n pageSize.value = res.data.size;\n }\n } catch (error) {\n console.error('加载订单失败:', error);\n ElMessage.error(error.message || '加载订单失败');\n } finally {\n loading.value = false;\n }\n };\n\n // 查看订单详情\n const viewDetail = orderId => {\n router.push(`/orders/detail/${orderId}`);\n
|