| | |
| | | import { BarcodeDetail } from "#/views/wls/barcode/components"; |
| | | |
| | | import { useFormSchema } from "../data"; |
| | | import PredictDelivery from "./ai/predict-delivery.vue"; |
| | | import PredictDuration from "./ai/predict-duration.vue"; |
| | | import PredictMaterial from "./ai/predict-material.vue"; |
| | | import PredictRisk from "./ai/predict-risk.vue"; |
| | | import ItemList from "./item-list.vue"; |
| | | import ProcessList from "./process-list.vue"; |
| | | |
| | |
| | | () => |
| | | formType.value === "update" && |
| | | formData.value?.status === MesProWorkOrderStatusEnum.PREPARE |
| | | ); |
| | | const canUseAi = computed( |
| | | () => |
| | | formData.value?.id && |
| | | (formData.value?.status === MesProWorkOrderStatusEnum.PREPARE || |
| | | formData.value?.status === MesProWorkOrderStatusEnum.CONFIRMED) |
| | | ); |
| | | const getTitle = computed(() => { |
| | | const isChild = !!formData.value?.parentId; |
| | |
| | | }); |
| | | |
| | | /** 重新挂载 schema 并按表单态控制底部按钮 */ |
| | | const mainActionText = computed(() => { |
| | | if (isConfirm.value) return '确认'; |
| | | if (isFinish.value) return '完成'; |
| | | return '提交'; |
| | | }); |
| | | |
| | | const showMainBtn = computed(() => isEditable.value || isConfirm.value || isFinish.value); |
| | | |
| | | function applySchema() { |
| | | formApi.setState({ schema: useFormSchema(formType.value, formApi) }); |
| | | const showBtn = isEditable.value || isConfirm.value || isFinish.value; |
| | | modalApi.setState({ |
| | | showConfirmButton: showBtn, |
| | | confirmText: isConfirm.value || canConfirm.value |
| | | ? '确认' |
| | | : isFinish.value |
| | | ? '完成' |
| | | : undefined, |
| | | }); |
| | | modalApi.setState({ showCancelButton: false, showConfirmButton: false }); |
| | | } |
| | | |
| | | /** 仅保存(不改变状态) */ |
| | | async function handleSave() { |
| | | const { valid } = await formApi.validate(); |
| | | if (!valid || !formData.value?.id) return; |
| | | modalApi.lock(); |
| | | try { |
| | | const data = (await formApi.getValues()) as MesProWorkOrderApi.WorkOrder; |
| | | await updateWorkOrder({ ...formData.value, ...data }); |
| | | if (tempProcessList.value.length > 0) { |
| | | const processList = tempProcessList.value.map(item => ({ |
| | | ...item, |
| | | workOrderId: formData.value!.id, |
| | | })); |
| | | await batchSaveWorkOrderProcess(processList); |
| | | } |
| | | formData.value = { ...formData.value, ...data }; |
| | | originalSnapshot.value = JSON.stringify(await formApi.getValues()); |
| | | emit('success'); |
| | | message.success($t('ui.actionMessage.operationSuccess')); |
| | | } finally { |
| | | modalApi.unlock(); |
| | | } |
| | | } |
| | | |
| | | /** 查看订单条码 */ |
| | |
| | | </Tabs> |
| | | </template> |
| | | <template #prepend-footer> |
| | | <Button v-if="formType === 'detail' && formData?.id" |
| | | @click="handleBarcode"> |
| | | 查看条码 |
| | | </Button> |
| | | <div class="flex flex-auto flex-col gap-2"> |
| | | <div v-if="canUseAi" class="flex items-center gap-2"> |
| | | <PredictMaterial :work-order-id="formData!.id" /> |
| | | <PredictDuration :work-order-id="formData!.id" /> |
| | | <PredictRisk :work-order-id="formData!.id" /> |
| | | <PredictDelivery :work-order-id="formData!.id" /> |
| | | </div> |
| | | <div v-if="canUseAi && showMainBtn" class="border-t border-gray-200" /> |
| | | <div class="flex items-center"> |
| | | <Button v-if="showMainBtn" |
| | | type="primary" |
| | | @click="modalApi.onConfirm()"> |
| | | {{ mainActionText }} |
| | | </Button> |
| | | </div> |
| | | </div> |
| | | </template> |
| | | <template #append-footer> |
| | | <div class="flex gap-2"> |
| | | <Button v-if="canConfirm" |
| | | @click="handleSave"> |
| | | 保存修改 |
| | | </Button> |
| | | <Button v-if="formType === 'detail' && formData?.id" |
| | | @click="handleBarcode"> |
| | | 查看条码 |
| | | </Button> |
| | | <Button @click="modalApi.close()">取消</Button> |
| | | </div> |
| | | </template> |
| | | </Modal> |
| | | <BarcodeDetail ref="barcodeDetailRef" /> |