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.

0 lines
16 KiB

1 month ago
  1. {"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