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 { useStore } from 'vuex';\nexport default {\n __name: 'OrderManagement',\n setup(__props, {\n expose: __expose\n }) {\n __expose();\n const router = useRouter();\n const store = useStore();\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 hasViewPermission = computed(() => {\n const role = store.state.userInfo.role;\n return ['ROLE_ADMIN', 'ROLE_LOGISTICS_ADMIN'].includes(role);\n });\n const loadOrders = async () => {\n loading.value = true;\n try {\n let res;\n if (searchForm.orderId) {\n res = await getOrderById(searchForm.orderId);\n if (res.code === 200) {\n orderList.value = res.data ? [res.data] : [];\n total.value = res.data ? 1 : 0;\n }\n } else {\n 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 }\n }\n } catch (error) {\n console.error('加载订单失败:', error);\n handleError(error);\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 handleReset = () => {\n searchForm.customerId = '';\n currentPage.value = 1;\n loadOrders();\n };\n onMounted(() => {\n if (!hasViewPermission.value) {\n ElMessage.error('没有权限访问此页面');\n router.push('/');\n return;\n }\n loadOrders();\n
|