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, onMounted, computed } from 'vue';\nimport { useRouter } from 'vue-router';\nimport { ElMessage } from 'element-plus';\nimport { Search } from '@element-plus/icons-vue';\nimport { getAllOrders, getOrderById } from '@/api/order';\nimport store from '@/store';\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 orderList = ref([]);\n const currentPage = ref(1);\n const pageSize = ref(10);\n const total = ref(0);\n const searchForm = reactive({\n customerId: '',\n orderId: ''\n });\n const isValidCustomerId = computed(() => {\n if (!searchForm.customerId) return true; // 空值是有效的\n const num = Number(searchForm.customerId);\n return Number.isInteger(num) && num > 0; // 必须是正整数\n });\n const validateCustomerId = val => {\n if (val === '') {\n // 允许清空\n searchForm.customerId = '';\n return;\n }\n if (!isValidCustomerId.value) {\n ElMessage.warning('客户ID必须是正整数');\n searchForm.customerId = '';\n }\n };\n const getStatusText = status => {\n const orderStatus = Number(status);\n switch (orderStatus) {\n case 0:\n return '待处理';\n case 1:\n return '已接单';\n case 2:\n return '运输中';\n case 3:\n return '已完成';\n case 4:\n return '已取消';\n default:\n return '未知状态';\n }\n };\n const getStatusType = status => {\n const orderStatus = Number(status);\n switch (orderStatus) {\n case 0:\n return 'info';\n // 蓝色,表示待处理\n case 1:\n return 'warning';\n // 黄色,表示进行中\n case 2:\n return 'warning';\n // 黄色,表示进行中\n case 3:\n return 'success';\n // 绿色,表示已完成\n case 4:\n return 'danger';\n // 红色,表示已取消\n default:\n return '';\n }\n };\n const hasPermission = computed(() => {\n const userRole = store.state.userInfo.role;\n return ['ROLE_ADMIN', 'ROLE_LOGISTICS_ADMIN'].includes(userRole);\n });\n const loadOrders = async () => {\n loading.value = true;\n try {\n const params = {\n pageNum: currentPage.value,\n pageSize: pageSize.value\n };\n if (searchForm.customerId && searchForm.customerId.trim() !== '') {\n params.customerId = Number(searchForm.customerId);\n }\n const res = await getAllOrders(params);\n if (res.code === 200 && res.data) {\n orderList.value = res.data.records;\n total.value = res.data.total;\n pageSize.value = res.data.size;\n currentPage.value = res.data.current;\n } else {\n throw new Error(res.message || '获取订单列表失败');\n }\n } catch (error) {\n console.error('加载订单失败:', error);\n if (error.response?.status === 401) {\n ElMessage.error('登录已过期,请重新登录');\n router.push('/login');\n } else if (error.response?.status === 403) {\n ElMessage.error('没有权限访问');\n } else {\n ElMessage.error(error.message || '加载订单失败,请重试');\n }\n } finally {\n loading.value = false;\n }\n };\n const handleSizeChange = val => {\n pageSize.value = val;\n loadOrders();\n };\n const handleCurrentChange = val => {\n currentPage.value = val;\n loadOrders();\n };\n const handleSearch = () => {\n if (searchForm.customerId && !isValidCustomerId.value) {\n ElMessage.warning('请输入有效的客户ID');\n return;\n }\n currentPage.value = 1;\n loadOrders();\n };\n const
|