spring
2025-11-13 bfbea958be8afe7e0522dc19f8a468eb35a3f9b9
src/pages/production/twist/receive/steelCore/form.vue
@@ -1,6 +1,16 @@
<template>
  <wd-form ref="form" :model="model" class="relative form_box">
    <wd-cell-group :border="true">
      <wd-picker
        v-model="diskMaterialValue"
        :columns="diskMaterialOptions"
        label="芯线类型"
        label-width="100px"
        prop="diskMaterial"
        placeholder="请选择芯线类型"
        clearable
        @confirm="handleDiskMaterialChange"
      />
      <wd-input
        v-model="model.model"
        label="规格型号"
@@ -48,6 +58,7 @@
<script lang="ts" setup>
import useFormData from "@/hooks/useFormData";
import TwistApi from "@/api/product/twist";
import ManageApi from "@/api/product/manage";
import { useToast } from "wot-design-uni";
const props = defineProps({
@@ -59,6 +70,10 @@
    type: Object,
    default: null,
  },
  wireId: {
    type: [String, Number],
    default: undefined,
  },
});
const emits = defineEmits(["refresh"]);
@@ -67,6 +82,7 @@
const allListData = ref<any[]>([]); // 存储完整列表数据
const toast = useToast();
const { form: model } = useFormData({
  diskMaterial: undefined, // 芯线类型
  model: undefined, // 规格型号
  monofilamentNumber: undefined, // 样品编号
  amount: undefined, // 数量
@@ -75,11 +91,45 @@
  type: "钢芯",
});
// 芯线类型字典数据
const diskMaterialOptions = ref<Array<{ label: string; value: string }>>([]);
const diskMaterialValue = ref("");
// 加载芯线类型字典数据
const loadDiskMaterialDict = async () => {
  try {
    const res = await ManageApi.dictAPI("core_wire_type");
    if (res.data && Array.isArray(res.data)) {
      diskMaterialOptions.value = res.data.map((item: any) => ({
        label: item.dictLabel || "",
        value: item.dictValue || "",
      }));
    }
  } catch (error) {
    // 加载字典失败,静默处理
  }
};
// 处理芯线类型选择
const handleDiskMaterialChange = (val: any) => {
  model.diskMaterial = val.value;
};
// 监听 model.diskMaterial 变化,同步选择器显示
watch(
  () => model.diskMaterial,
  (newValue) => {
    diskMaterialValue.value = newValue || "";
  },
  { immediate: true }
);
// 新增提交
const submit = async () => {
  const currentWireId = props.wireId || paramsId.value;
  const { code } = await TwistApi.addStrandedWireDish([
    {
      wireId: paramsId.value,
      wireId: currentWireId,
      ...model,
    },
  ]);
@@ -107,6 +157,7 @@
      // 保留原有数据,然后更新修改的字段
      const updatedItem = {
        ...item, // 先保留原有的所有数据
        diskMaterial: model.diskMaterial,
        model: model.model,
        monofilamentNumber: model.monofilamentNumber,
        amount: model.amount,
@@ -133,7 +184,6 @@
const setFormData = (list: any[], currentEditId: number) => {
  // 安全检查:确保list是数组
  if (!Array.isArray(list)) {
    console.error("setFormData: list 参数不是数组", list);
    return;
  }
@@ -144,12 +194,15 @@
  // 找到当前编辑项并回显到表单
  const currentItem = list.find((item) => item.id === currentEditId);
  if (currentItem) {
    model.diskMaterial = currentItem.diskMaterial;
    model.model = currentItem.model;
    model.monofilamentNumber = currentItem.monofilamentNumber;
    model.amount = currentItem.amount;
    model.weight = currentItem.weight;
    model.supplier = currentItem.supplier;
    model.type = currentItem.type || "钢芯";
    // 设置芯线类型的回显值
    diskMaterialValue.value = currentItem.diskMaterial || "";
  }
};
@@ -158,12 +211,14 @@
  () => props.editData,
  (newData) => {
    if (newData && props.mode === "edit") {
      model.diskMaterial = newData.diskMaterial || "";
      model.model = newData.model || "";
      model.monofilamentNumber = newData.monofilamentNumber || "";
      model.amount = newData.amount || "";
      model.weight = newData.weight || "";
      model.supplier = newData.supplier || "";
      model.type = newData.type || "钢芯";
      diskMaterialValue.value = newData.diskMaterial || "";
    }
  },
  { immediate: true, deep: true }
@@ -171,16 +226,36 @@
// 重置表单数据
const resetFormData = () => {
  model.diskMaterial = undefined;
  model.model = undefined;
  model.monofilamentNumber = undefined;
  model.amount = undefined;
  model.weight = undefined;
  model.supplier = undefined;
  model.type = "钢芯";
  diskMaterialValue.value = "";
};
// 填充表单数据(用于扫码后回显)
const fillFormData = (data: any) => {
  if (data) {
    model.diskMaterial = data.diskMaterial || "";
    model.model = data.model || "";
    model.monofilamentNumber = data.monofilamentNumber || "";
    model.amount = data.oneLength || data.amount || "";
    model.weight = data.weight || "";
    model.supplier = data.supplier || "";
    model.type = data.type || "钢芯";
    diskMaterialValue.value = data.diskMaterial || "";
  }
};
onLoad((options: any) => {
  paramsId.value = options.id;
});
onMounted(async () => {
  await loadDiskMaterialDict();
});
defineExpose({
@@ -188,6 +263,7 @@
  submitEdit,
  setFormData,
  resetFormData,
  fillFormData,
});
</script>