From 27c8277d717b34b55f3ea967027b53b067f77df3 Mon Sep 17 00:00:00 2001
From: xiaoyi <908147524@qq.com>
Date: 星期四, 20 八月 2026 16:58:49 +0800
Subject: [PATCH] feat 功能变更

---
 src/views/mes/pd/ctc-reel/modules/form.vue |  126 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 126 insertions(+), 0 deletions(-)

diff --git a/src/views/mes/pd/ctc-reel/modules/form.vue b/src/views/mes/pd/ctc-reel/modules/form.vue
new file mode 100644
index 0000000..970f400
--- /dev/null
+++ b/src/views/mes/pd/ctc-reel/modules/form.vue
@@ -0,0 +1,126 @@
+<script lang="ts" setup>
+  import type { FormType } from '../data';
+
+  import type { MesPdCtcReelApi } from '#/api/mes/pd/ctc-reel';
+
+  import { computed, ref } from 'vue';
+
+  import { useVbenModal } from '@vben/common-ui';
+  import { $t } from '@vben/locales';
+
+  import { Button, message } from 'ant-design-vue';
+
+  import { useVbenForm } from '#/adapter/form';
+  import {
+    createCtcReel,
+    getCtcReel,
+    updateCtcReel,
+  } from '#/api/mes/pd/ctc-reel';
+  import { CalcModal } from '#/views/mes/pd/ctc/modules';
+
+  import { useFormSchema } from '../data';
+
+  const emit = defineEmits(['success']);
+  const formType = ref<FormType>('create'); // 琛ㄥ崟妯″紡
+  const formData = ref<MesPdCtcReelApi.CtcReel>();
+  const isDetail = computed(() => formType.value === 'detail'); // 鏄惁鏌ョ湅妯″紡
+  const getTitle = computed(() => {
+    if (formType.value === 'detail') {
+      return '鏌ョ湅鐩樺叿璁$畻';
+    }
+    return formType.value === 'update' ? '淇敼鐩樺叿璁$畻' : '鏂板鐩樺叿璁$畻';
+  });
+
+  const [Form, formApi] = useVbenForm({
+    commonConfig: {
+      componentProps: {
+        class: 'w-full',
+      },
+      formItemClass: 'col-span-1',
+      labelWidth: 130,
+    },
+    wrapperClass: 'grid-cols-3',
+    layout: 'horizontal',
+    schema: [],
+    showDefaultActions: false,
+  });
+
+  const [CalcModal, calcModalApi] = useVbenModal({
+    connectedComponent: CalcModal,
+    destroyOnClose: true,
+  });
+
+  /** 鎵撳紑瀹归噺璁$畻宸ュ叿 */
+  function handleOpenCalc() {
+    calcModalApi.open();
+  }
+
+  /** 鍥炲~鏈�澶у閲忥紙km锛� */
+  function handleFillReel(value: { capacityKm: number }) {
+    formApi.setFieldValue('maxCapacity', value.capacityKm);
+  }
+
+  const [Modal, modalApi] = useVbenModal({
+    async onConfirm() {
+      if (isDetail.value) {
+        await modalApi.close();
+        return;
+      }
+      const { valid } = await formApi.validate();
+      if (!valid) {
+        return;
+      }
+      modalApi.lock();
+      // 鎻愪氦琛ㄥ崟
+      const data = (await formApi.getValues()) as MesPdCtcReelApi.CtcReel;
+      try {
+        await (data.id ? updateCtcReel(data) : createCtcReel(data));
+        // 鍏抽棴骞舵彁绀�
+        await modalApi.close();
+        emit('success');
+        message.success($t('ui.actionMessage.operationSuccess'));
+      } finally {
+        modalApi.unlock();
+      }
+    },
+    async onOpenChange(isOpen: boolean) {
+      if (!isOpen) {
+        formData.value = undefined;
+        return;
+      }
+      // 鍔犺浇鏁版嵁
+      const data = modalApi.getData<{ formType: FormType; id?: number }>();
+      formType.value = data.formType;
+      formApi.setState({ schema: useFormSchema() });
+      formApi.setDisabled(formType.value === 'detail');
+      modalApi.setState({ showConfirmButton: formType.value !== 'detail' });
+      if (!data?.id) {
+        return;
+      }
+      modalApi.lock();
+      try {
+        formData.value = await getCtcReel(data.id);
+        // 璁剧疆鍒� values
+        await formApi.setValues(formData.value);
+      } finally {
+        modalApi.unlock();
+      }
+    },
+  });
+</script>
+
+<template>
+  <Modal :title="getTitle" class="w-4/5">
+    <Form class="mx-4" />
+    <template #prepend-footer>
+      <Button
+        v-if="!isDetail"
+        type="default"
+        @click="handleOpenCalc"
+      >
+        瀹归噺璁$畻
+      </Button>
+    </template>
+    <CalcModal @reel="handleFillReel" />
+  </Modal>
+</template>

--
Gitblit v1.9.3