spring
2025-11-13 bfbea958be8afe7e0522dc19f8a468eb35a3f9b9
fix: 钢芯领用添加芯线类型字段,添加扫码领用功能
已修改6个文件
191 ■■■■ 文件已修改
src/pages/production/twist/receive/index.vue 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/production/twist/receive/monofil.vue 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/production/twist/receive/steelCore/edit.vue 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/production/twist/receive/steelCore/form.vue 80 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/production/twist/receive/steelCore/index.vue 69 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/production/wire/attachment/index.vue 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/pages/production/twist/receive/index.vue
@@ -1,16 +1,16 @@
<template>
  <wd-tabs v-model="tab" auto-line-width>
    <wd-tab title="单丝领用" name="单丝领用">
      <Monofil />
      <Monofil v-if="tab === '单丝领用'" />
    </wd-tab>
    <wd-tab title="盘具领用" name="盘具领用">
      <view class="content">
        <Plate />
        <Plate v-if="tab === '盘具领用'" />
      </view>
    </wd-tab>
    <wd-tab title="芯线领用" name="芯线领用">
      <view class="content">
        <SteelCore />
        <SteelCore v-if="tab === '芯线领用'" />
      </view>
    </wd-tab>
  </wd-tabs>
src/pages/production/twist/receive/monofil.vue
@@ -79,7 +79,7 @@
import MonofilCard from "../components/MonofilCard.vue";
import StatisticsModal from "../components/StatisticsModal.vue";
import { useToast } from "wot-design-uni";
import { onLoad, onUnload } from "@dcloudio/uni-app";
import { onLoad, onUnload, onShow, onHide } from "@dcloudio/uni-app";
import Scan from "@/components/scan/index.vue";
import ManageApi from "@/api/product/manage";
import TwistApi from "@/api/product/twist";
@@ -95,20 +95,21 @@
const showStatisticsModal = ref(false);
const showManualInput = ref(false);
const manualOutPutId = ref("");
const isPageVisible = ref(false); // 标记页面是否可见
// 监听标签切换
watch(tab, () => {
  if (tab.value) {
    console.log("tab.value:===========1", tab.value);
    getList();
  }
});
const getScanCode = async (code: any) => {
  console.log("自定义扫描的结果回调函数:", code);
  // let parseData = code.trim();
  console.log("code:===========", JSON.parse(code.code));
  console.log("id:=============", JSON.parse(code.code).id);
  // 检查页面是否可见,如果不可见则不处理扫码数据
  if (!isPageVisible.value) {
    return;
  }
  try {
    // 检查是否已选择标签
    if (!tab.value) {
@@ -117,13 +118,11 @@
    }
    // 找到当前选中的层
    console.log("tab.value:===========2", tab.value);
    const currentLayer = nodeList.value.find((node) => node.twistedLayer === tab.value);
    if (!currentLayer) {
      toast.error("未找到当前选中的层");
      return;
    }
    console.log("tab.value:===========3", currentLayer);
    const { data } = await TwistApi.getScarn({
      outPutId: JSON.parse(code.code).id,
      twistId: currentLayer.twistId,
@@ -259,7 +258,6 @@
    // 设置默认第一层
    if (nodeList.value && nodeList.value.length > 0 && !tab.value) {
      tab.value = nodeList.value[0].twistedLayer;
      console.log("设置默认第一层:", tab.value);
      // 设置默认标签后,加载第一层的数据
      getList();
    }
@@ -344,9 +342,21 @@
  getRootNumber(options.id);
  // getRootNumber(118);
});
onShow(() => {
  // 页面显示时标记为可见
  isPageVisible.value = true;
});
onHide(() => {
  // 页面隐藏时标记为不可见
  isPageVisible.value = false;
});
onUnload(() => {
  // 开启广播监听事件
  // 取消广播监听事件
  uni.$off("scanMono", getScanCode);
  isPageVisible.value = false;
});
</script>
src/pages/production/twist/receive/steelCore/edit.vue
@@ -37,13 +37,10 @@
// 接收列表页传递的数据
const receiveEditData = (data: any) => {
  console.log("receiveEditData 接收到的数据:", data);
  if (data && formRef.value) {
    // 确保 list 和 editId 都存在
    if (data.list && data.editId) {
      formRef.value.setFormData(data.list, data.editId);
    } else {
      console.error("数据格式错误:", data);
    }
  }
};
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>
src/pages/production/twist/receive/steelCore/index.vue
@@ -8,7 +8,12 @@
      @query="getList"
    >
      <template #top>
        <CardTitle title="芯线领用" :hideAction="true" :full="false" @action="addReport" />
        <CardTitle title="芯线领用" :hideAction="false" :full="false">
          <template #action>
            <wd-button type="icon" icon="scan" color="#0D867F" @click="openScan"></wd-button>
            <wd-button type="icon" icon="add-circle" color="#0D867F" @click="addReport"></wd-button>
          </template>
        </CardTitle>
      </template>
      <wd-card v-for="(item, index) in cardList" :key="index" type="rectangle" custom-class="round">
        <template #title>
@@ -28,7 +33,7 @@
        <wd-button type="text" @click="cancelAdd">取消</wd-button>
        <wd-button type="text" @click="submitAdd">确定</wd-button>
      </view>
      <SteelCore ref="addFormRef" mode="add" @refresh="reloadList" />
      <SteelCore ref="addFormRef" mode="add" :wireId="paramsId" @refresh="reloadList" />
    </wd-popup>
    <wd-popup v-model="editDialog.visible" position="bottom" custom-class="yl-popup">
      <view class="action px-3">
@@ -38,10 +43,12 @@
      <SteelCore
        ref="editFormRef"
        mode="edit"
        :wireId="paramsId"
        :editData="editDialog.currentItem"
        @refresh="reloadList"
      />
    </wd-popup>
    <Scan ref="scanRef" emitName="scanSteelCore" />
    <wd-toast />
  </view>
</template>
@@ -51,15 +58,19 @@
import ProductionCard from "../../../components/ProductionCard.vue";
import { useToast } from "wot-design-uni";
import SteelCore from "./form.vue";
import { onLoad } from "@dcloudio/uni-app";
import { onLoad, onUnload, onShow, onHide } from "@dcloudio/uni-app";
import ManageApi from "@/api/product/manage";
import TwistApi from "@/api/product/twist";
import zPaging from "@/components/z-paging/z-paging.vue";
import Scan from "@/components/scan/index.vue";
const paramsId = ref();
const pagingRef = ref();
const addFormRef = ref();
const editFormRef = ref();
const scanRef = ref();
const toast = useToast();
const isPageVisible = ref(false); // 标记页面是否可见
const addDialog = reactive({
  visible: false,
});
@@ -147,9 +158,61 @@
  pagingRef.value.refresh();
};
// 扫码相关方法
const openScan = () => {
  scanRef.value.triggerScan();
};
const getScanCode = async (code: any) => {
  // 检查页面是否可见,如果不可见则不处理扫码数据
  if (!isPageVisible.value) {
    return;
  }
  try {
    const parseData = JSON.parse(code.code);
    // 打开新增弹框并填充扫码获取的信息
    addDialog.visible = true;
    // 等待弹框打开后填充表单数据
    // 使用双重等待:nextTick + setTimeout 确保组件已完全挂载
    nextTick(() => {
      setTimeout(() => {
        if (addFormRef.value) {
          addFormRef.value.fillFormData(parseData);
          toast.success("扫码成功,请确认信息");
        } else {
          toast.error("表单加载失败,请重试");
        }
      }, 200); // 延迟200ms确保弹框和组件已完全渲染
    });
  } catch (error) {
    toast.error("二维码异常,请更换二维码!");
  }
};
onLoad((options: any) => {
  // 开启广播监听事件
  uni.$on("scanSteelCore", getScanCode);
  paramsId.value = options.id;
});
onShow(() => {
  // 页面显示时标记为可见
  isPageVisible.value = true;
});
onHide(() => {
  // 页面隐藏时标记为不可见
  isPageVisible.value = false;
});
onUnload(() => {
  // 取消广播监听事件
  uni.$off("scanSteelCore", getScanCode);
  isPageVisible.value = false;
});
</script>
<style lang="scss" scoped>
src/pages/production/wire/attachment/index.vue
@@ -523,3 +523,6 @@