gaoluyang
8 小时以前 07f9f8657d057a38792c3822acc9b08d83478967
src/views/productionManagement/processRoute/New.vue
@@ -1,14 +1,14 @@
<template>
  <div>
    <el-dialog
        v-model="isShow"
    <el-dialog v-model="isShow"
        title="新增工艺路线"
        width="400"
        @close="closeModal"
    >
      <el-form label-width="140px" :model="formState" label-position="top" ref="formRef">
        <el-form-item
            label="产品名称"
               @close="closeModal">
      <el-form label-width="140px"
               :model="formState"
               label-position="top"
               ref="formRef">
        <el-form-item label="产品名称"
            prop="productModelId"
            :rules="[
                {
@@ -16,17 +16,15 @@
                message: '请选择产品',
                trigger: 'change',
              }
            ]"
        >
          <el-button type="primary" @click="showProductSelectDialog = true">
            ]">
          <el-button type="primary"
                     @click="showProductSelectDialog = true">
            {{ formState.productName && formState.productModelName 
              ? `${formState.productName} - ${formState.productModelName}` 
              : '选择产品' }}
          </el-button>
        </el-form-item>
        <el-form-item
            label="BOM"
        <el-form-item label="BOM"
            prop="bomId"
            :rules="[
                {
@@ -34,38 +32,32 @@
                message: '请选择BOM',
                trigger: 'change',
              }
            ]"
        >
          <el-select
              v-model="formState.bomId"
            ]">
          <el-select v-model="formState.bomId"
              placeholder="请选择BOM"
              clearable
              :disabled="!formState.productModelId || bomOptions.length === 0"
              style="width: 100%"
          >
            <el-option
                v-for="item in bomOptions"
                     style="width: 100%">
            <el-option v-for="item in bomOptions"
                :key="item.id"
                :label="item.bomNo || `BOM-${item.id}`"
                :value="item.id"
            />
                       :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="description">
          <el-input v-model="formState.description" type="textarea" />
        <el-form-item label="备注"
                      prop="description">
          <el-input v-model="formState.description"
                    type="textarea" />
        </el-form-item>
      </el-form>
      <!-- 产品选择弹窗 -->
      <ProductSelectDialog
          v-model="showProductSelectDialog"
      <ProductSelectDialog v-model="showProductSelectDialog"
          @confirm="handleProductSelect"
          single
      />
                           single />
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="handleSubmit">确认</el-button>
          <el-button type="primary"
                     @click="handleSubmit">确认</el-button>
          <el-button @click="closeModal">取消</el-button>
        </div>
      </template>
@@ -86,7 +78,7 @@
  },
});
const emit = defineEmits(['update:visible', 'completed']);
  const emit = defineEmits(["update:visible", "completed"]);
// 响应式数据(替代选项式的 data)
const formState = ref({
@@ -95,7 +87,7 @@
  productName: "",
  productModelName: "",
  bomId: undefined,
  description: '',
    description: "",
});
const isShow = computed({
@@ -103,14 +95,14 @@
    return props.visible;
  },
  set(val) {
    emit('update:visible', val);
      emit("update:visible", val);
  },
});
const showProductSelectDialog = ref(false);
const bomOptions = ref([]);
let { proxy } = getCurrentInstance()
  let { proxy } = getCurrentInstance();
const closeModal = () => {
  // 重置表单数据
@@ -120,14 +112,14 @@
    productName: "",
    productModelName: "",
    bomId: undefined,
    description: '',
      description: "",
  };
  bomOptions.value = [];
  isShow.value = false;
};
// 产品选择处理
const handleProductSelect = async (products) => {
  const handleProductSelect = async products => {
  if (products && products.length > 0) {
    const product = products[0];
    // 先查询BOM列表(必选)
@@ -139,7 +131,7 @@
        bomList = res;
      } else if (res && res.data) {
        bomList = Array.isArray(res.data) ? res.data : [res.data];
      } else if (res && typeof res === 'object') {
        } else if (res && typeof res === "object") {
        bomList = [res];
      }
      
@@ -151,7 +143,7 @@
        bomOptions.value = bomList;
        showProductSelectDialog.value = false;
        // 触发表单验证更新
        proxy.$refs["formRef"]?.validateField('productModelId');
          proxy.$refs["formRef"]?.validateField("productModelId");
      } else {
        proxy.$modal.msgError("该产品没有BOM,请先创建BOM");
      }
@@ -174,17 +166,18 @@
        proxy.$modal.msgError("请选择BOM");
        return;
      }
        console.log(formState.value, "formState.value====");
      add(formState.value).then(res => {
        // 关闭模态框
        isShow.value = false;
        // 告知父组件已完成
        emit('completed');
          emit("completed");
        proxy.$modal.msgSuccess("提交成功");
      })
        });
    }
  })
    });
};
defineExpose({
  closeModal,