diff --git a/apps/web-antd/src/views/ops/work-order/modules/cancel-form.vue b/apps/web-antd/src/views/ops/work-order/modules/cancel-form.vue index a62b95fe9..41328558c 100644 --- a/apps/web-antd/src/views/ops/work-order/modules/cancel-form.vue +++ b/apps/web-antd/src/views/ops/work-order/modules/cancel-form.vue @@ -4,120 +4,183 @@ import { ref } from 'vue'; import { useVbenModal } from '@vben/common-ui'; import { IconifyIcon } from '@vben/icons'; -import { Alert, message } from 'ant-design-vue'; +import { Alert, Input, message } from 'ant-design-vue'; -import { useVbenForm, z } from '#/adapter/form'; import { cancelOrder } from '#/api/ops/order-center'; defineOptions({ name: 'CancelOrderForm' }); const emit = defineEmits<{ success: [] }>(); +interface ModalData { + orderId: number; + orderCode: string; + title: string; +} + +const modalData = ref({ + orderId: 0, + orderCode: '', + title: '', +}); +const reason = ref(''); +const loading = ref(false); + const [Modal, modalApi] = useVbenModal({ onOpenChange: (isOpen) => { if (isOpen) { - const data = modalApi.getData<{ - orderCode: string; - orderId: number; - title: string; - }>(); + const data = modalApi.getData(); if (data) { - orderId.value = data.orderId; - orderCode.value = data.orderCode; - orderTitle.value = data.title; + modalData.value = data; } + reason.value = ''; } }, onConfirm: handleSubmit, }); -const orderId = ref(); -const orderCode = ref(''); -const orderTitle = ref(''); -const loading = ref(false); - -const [Form, formApi] = useVbenForm({ - schema: [ - { - fieldName: 'reason', - label: '取消原因', - component: 'Textarea', - componentProps: { - placeholder: '请输入取消工单的原因', - rows: 4, - maxLength: 200, - showCount: true, - }, - rules: z - .string() - .min(2, '原因至少2个字符') - .max(200, '原因不能超过200字符'), - }, - ], - showDefaultActions: false, -}); - /** 提交表单 */ async function handleSubmit() { - const { valid, values } = await formApi.validate(); - if (!valid) return; + const val = reason.value.trim(); + if (val.length < 2) { + message.warning('取消原因至少2个字符'); + return; + } + if (val.length > 200) { + message.warning('取消原因不能超过200字符'); + return; + } loading.value = true; + modalApi.setState({ confirmLoading: true }); try { await cancelOrder({ - id: orderId.value!, - reason: values.reason, + id: modalData.value.orderId, + reason: val, }); message.success('工单已取消'); modalApi.close(); emit('success'); } finally { loading.value = false; + modalApi.setState({ confirmLoading: false }); } } diff --git a/apps/web-antd/src/views/ops/work-order/modules/upgrade-priority-form.vue b/apps/web-antd/src/views/ops/work-order/modules/upgrade-priority-form.vue index 5f2813780..50f43a704 100644 --- a/apps/web-antd/src/views/ops/work-order/modules/upgrade-priority-form.vue +++ b/apps/web-antd/src/views/ops/work-order/modules/upgrade-priority-form.vue @@ -4,60 +4,41 @@ import { ref } from 'vue'; import { useVbenModal } from '@vben/common-ui'; import { IconifyIcon } from '@vben/icons'; -import { Alert, message } from 'ant-design-vue'; +import { Alert, Input, message } from 'ant-design-vue'; -import { useVbenForm, z } from '#/adapter/form'; import { upgradePriority } from '#/api/ops/cleaning'; defineOptions({ name: 'UpgradePriorityForm' }); const emit = defineEmits<{ success: [] }>(); +interface ModalData { + orderId: number; + orderCode: string; + currentPriority: number; +} + +const modalData = ref({ + orderId: 0, + orderCode: '', + currentPriority: 2, +}); +const reason = ref(''); +const loading = ref(false); + const [Modal, modalApi] = useVbenModal({ onOpenChange: (isOpen) => { if (isOpen) { - const data = modalApi.getData<{ - currentPriority: number; - orderCode: string; - orderId: number; - }>(); + const data = modalApi.getData(); if (data) { - orderId.value = data.orderId; - orderCode.value = data.orderCode; - currentPriority.value = data.currentPriority; + modalData.value = data; } + reason.value = ''; } }, onConfirm: handleSubmit, }); -const orderId = ref(); -const orderCode = ref(''); -const currentPriority = ref(2); -const loading = ref(false); - -const [Form, formApi] = useVbenForm({ - schema: [ - { - fieldName: 'reason', - label: '升级原因', - component: 'Textarea', - componentProps: { - placeholder: - '请输入升级为P0紧急工单的原因,例如:领导临时检查、VIP客户投诉等', - rows: 4, - maxLength: 200, - showCount: true, - }, - rules: z - .string() - .min(5, '原因至少5个字符') - .max(200, '原因不能超过200字符'), - }, - ], - showDefaultActions: false, -}); - /** 获取优先级文本 */ function getPriorityText(priority: number) { const map: Record = { @@ -70,67 +51,162 @@ function getPriorityText(priority: number) { /** 提交表单 */ async function handleSubmit() { - const { valid, values } = await formApi.validate(); - if (!valid || !values) return; + const val = reason.value.trim(); + if (val.length < 5) { + message.warning('升级原因至少5个字符'); + return; + } + if (val.length > 200) { + message.warning('升级原因不能超过200字符'); + return; + } loading.value = true; + modalApi.setState({ confirmLoading: true }); try { await upgradePriority({ - orderId: orderId.value!, - reason: values.reason, + orderId: modalData.value.orderId, + reason: val, }); message.success('已升级为P0紧急工单'); modalApi.close(); emit('success'); } finally { loading.value = false; + modalApi.setState({ confirmLoading: false }); } }