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/modules/form.vue |  134 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 134 insertions(+), 0 deletions(-)

diff --git a/src/views/mes/pd/ctc/modules/form.vue b/src/views/mes/pd/ctc/modules/form.vue
new file mode 100644
index 0000000..989abef
--- /dev/null
+++ b/src/views/mes/pd/ctc/modules/form.vue
@@ -0,0 +1,134 @@
+<script lang="ts" setup>
+  import type { FormType } from '../data';
+
+  import type { MesPdCtcApi } from '#/api/mes/pd/ctc';
+
+  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 {
+    createCtc,
+    getCtc,
+    updateCtc,
+  } from '#/api/mes/pd/ctc';
+
+  import { useFormSchema } from '../data';
+  import CalcModal from './calc-modal.vue';
+
+  const emit = defineEmits(['success']);
+  const formType = ref<FormType>('create'); // 琛ㄥ崟妯″紡
+  const formData = ref<MesPdCtcApi.Ctc>();
+  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();
+  }
+
+  /** 鍥炲~缁曞寘瑙掑害 */
+  function handleFillAngle(value: { wrappingAngle: number }) {
+    formApi.setFieldValue('wrappingAngle', value.wrappingAngle);
+  }
+
+  /** 鍥炲~鐩存祦鐢甸樆 */
+  function handleFillResistance(value: { resistance20c: number }) {
+    formApi.setFieldValue('resistance20c', value.resistance20c);
+  }
+
+  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 MesPdCtcApi.Ctc;
+      try {
+        await (data.id ? updateCtc(data) : createCtc(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 getCtc(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
+      @angle="handleFillAngle"
+      @resistance="handleFillResistance"
+    />
+  </Modal>
+</template>

--
Gitblit v1.9.3