From 2dd434830299e781cd942ef5e6e938160dd12704 Mon Sep 17 00:00:00 2001
From: zhangwencui <1064582902@qq.com>
Date: 星期二, 03 三月 2026 17:15:18 +0800
Subject: [PATCH] 原材料检验功能开发

---
 src/pages/qualityManagement/materialInspection/add.vue | 1134 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 1,134 insertions(+), 0 deletions(-)

diff --git a/src/pages/qualityManagement/materialInspection/add.vue b/src/pages/qualityManagement/materialInspection/add.vue
new file mode 100644
index 0000000..0309813
--- /dev/null
+++ b/src/pages/qualityManagement/materialInspection/add.vue
@@ -0,0 +1,1134 @@
+<template>
+  <view class="material-inspection-add">
+    <!-- 浣跨敤閫氱敤椤甸潰澶撮儴缁勪欢 -->
+    <PageHeader :title="isEdit ? '缂栬緫鍘熸潗鏂欐楠�' : '鏂板鍘熸潗鏂欐楠�'"
+                @back="goBack" />
+    <!-- 琛ㄥ崟鍐呭 -->
+    <up-form :model="form"
+             ref="formRef"
+             label-width="110"
+             :rules="rules">
+      <!-- 鍩烘湰淇℃伅 -->
+      <up-form-item label="渚涘簲鍟�"
+                    prop="supplier"
+                    required
+                    border-bottom>
+        <up-input v-model="form.supplier"
+                  placeholder="璇烽�夋嫨渚涘簲鍟�"
+                  readonly
+                  :disabled="supplierQuantityDisabled" />
+        <template #right>
+          <up-icon @click="showSupplierSheet = true"
+                   name="arrow-right" />
+        </template>
+      </up-form-item>
+      <up-form-item label="浜у搧鍚嶇О"
+                    prop="productId"
+                    required
+                    border-bottom>
+        <up-input v-model="form.productName"
+                  placeholder="璇烽�夋嫨浜у搧"
+                  readonly
+                  @click="showProductTree = true"
+                  :disabled="isEdit" />
+        <template #right>
+          <up-icon @click="showProductTree = true"
+                   name="arrow-right" />
+        </template>
+      </up-form-item>
+      <up-form-item label="瑙勬牸鍨嬪彿"
+                    prop="productModelId"
+                    required
+                    border-bottom>
+        <up-input v-model="form.model"
+                  placeholder="璇烽�夋嫨瑙勬牸鍨嬪彿"
+                  readonly
+                  :disabled="isEdit" />
+        <template #right>
+          <up-icon @click="showModelSheet = true"
+                   name="arrow-right" />
+        </template>
+      </up-form-item>
+      <up-form-item label="鎸囨爣閫夋嫨"
+                    prop="testStandardId"
+                    border-bottom>
+        <up-input v-model="testStandardDisplay"
+                  placeholder="璇烽�夋嫨鎸囨爣"
+                  readonly />
+        <template #right>
+          <up-icon @click="openTestStandardSheet"
+                   name="arrow-right" />
+        </template>
+      </up-form-item>
+      <up-form-item label="鍗曚綅"
+                    prop="unit"
+                    border-bottom>
+        <up-input v-model="form.unit"
+                  placeholder="璇疯緭鍏ュ崟浣�"
+                  disabled />
+      </up-form-item>
+      <up-form-item label="鏁伴噺"
+                    prop="quantity"
+                    required
+                    border-bottom>
+        <up-input v-model="form.quantity"
+                  type="number"
+                  placeholder="璇疯緭鍏ユ暟閲�"
+                  :disabled="supplierQuantityDisabled" />
+      </up-form-item>
+      <up-form-item label="妫�娴嬪崟浣�"
+                    prop="checkCompany"
+                    border-bottom>
+        <up-input v-model="form.checkCompany"
+                  placeholder="璇疯緭鍏ユ娴嬪崟浣�"
+                  clearable />
+      </up-form-item>
+      <up-form-item label="妫�娴嬬粨鏋�"
+                    prop="checkResult"
+                    required
+                    border-bottom>
+        <up-input v-model="form.checkResult"
+                  placeholder="璇烽�夋嫨妫�娴嬬粨鏋�"
+                  readonly
+                  @click="showResultSheet" />
+        <template #right>
+          <up-icon @click="showResultSheet = true"
+                   name="arrow-right" />
+        </template>
+      </up-form-item>
+      <up-form-item label="妫�楠屽憳"
+                    prop="checkName"
+                    border-bottom>
+        <up-input v-model="form.checkName"
+                  placeholder="璇烽�夋嫨妫�楠屽憳"
+                  readonly
+                  @click="showInspectorSheet" />
+        <template #right>
+          <up-icon @click="showInspectorSheet = true"
+                   name="arrow-right" />
+        </template>
+      </up-form-item>
+      <up-form-item label="妫�娴嬫棩鏈�"
+                    prop="checkTime"
+                    required
+                    border-bottom>
+        <up-input v-model="form.checkTime"
+                  placeholder="璇烽�夋嫨妫�娴嬫棩鏈�"
+                  readonly />
+        <!-- <template #right>
+          <up-icon name="calendar"
+                   @click="showDatePicker"></up-icon>
+        </template> -->
+      </up-form-item>
+      <!-- <up-form-item label="閲囪喘璁㈠崟鍙�"
+                    prop="purchaseContractNo"
+                    border-bottom>
+        <up-input v-model="form.purchaseContractNo"
+                  placeholder="璇疯緭鍏ラ噰璐鍗曞彿"
+                  clearable />
+      </up-form-item> -->
+      <!-- 妫�楠岄」鐩� -->
+      <view class="inspection-items-container">
+        <view class="steps-header">
+          <text class="steps-title">妫�楠岄」鐩�</text>
+          <text class="steps-count">鍏� {{ tableData.length }} 涓」鐩�</text>
+        </view>
+        <view class="steps-list">
+          <view v-for="(item, index) in tableData"
+                :key="index"
+                class="exec-step-item">
+            <view class="step-number">
+              {{ index + 1 }}
+            </view>
+            <view class="step-content">
+              <view class="step-row">
+                <text class="step-label">鎸囨爣锛�</text>
+                <text class="step-value">{{ item.parameterItem }}</text>
+              </view>
+              <view class="step-row">
+                <text class="step-label">鍗曚綅锛�</text>
+                <text class="step-value">{{ item.unit }}</text>
+              </view>
+              <view class="step-row">
+                <text class="step-label">鏍囧噯鍊硷細</text>
+                <text class="step-value">{{ item.standardValue }}</text>
+              </view>
+              <view class="step-row">
+                <text class="step-label">鍐呮帶鍊硷細</text>
+                <text class="step-value">{{ item.controlValue }}</text>
+              </view>
+              <view class="step-row">
+                <text class="step-label">妫�楠屽�硷細</text>
+                <up-input v-model="item.testValue"
+                          placeholder="璇疯緭鍏ユ楠屽��"
+                          clearable
+                          border-bottom
+                          class="step-input" />
+              </view>
+            </view>
+          </view>
+          <view v-if="tableData.length === 0"
+                class="empty-data">
+            <text>璇峰厛閫夋嫨鎸囨爣</text>
+          </view>
+        </view>
+      </view>
+    </up-form>
+    <!-- 搴曢儴鎸夐挳 -->
+    <view class="bottom-buttons">
+      <up-button type="default"
+                 size="default"
+                 @click="goBack"
+                 class="bottom-btn">
+        鍙栨秷
+      </up-button>
+      <up-button type="primary"
+                 size="default"
+                 @click="submitForm"
+                 :loading="loading"
+                 class="bottom-btn">
+        {{ isEdit ? '淇濆瓨' : '鎻愪氦' }}
+      </up-button>
+    </view>
+    <!-- 鏃ユ湡閫夋嫨鍣� -->
+    <up-popup v-model:show="showDate"
+              mode="date"
+              :start-year="2020"
+              :end-year="2030"
+              @confirm="confirmDate" />
+    <!-- 渚涘簲鍟嗛�夋嫨 -->
+    <up-action-sheet :show="showSupplierSheet"
+                     :actions="supplierOptions"
+                     @select="selectSupplier"
+                     @close="showSupplierSheet = false"
+                     title="閫夋嫨渚涘簲鍟�" />
+    <!-- 浜у搧閫夋嫨 -->
+    <up-action-sheet :show="showProductSheet"
+                     :actions="productSheetOptions"
+                     @select="selectProduct"
+                     @close="showProductSheet = false"
+                     title="閫夋嫨浜у搧" />
+    <!-- 瑙勬牸鍨嬪彿閫夋嫨 -->
+    <up-action-sheet :show="showModelSheet"
+                     :actions="modelSheetOptions"
+                     @select="selectModel"
+                     @close="showModelSheet = false"
+                     title="閫夋嫨瑙勬牸鍨嬪彿" />
+    <!-- 妫�娴嬬粨鏋滈�夋嫨 -->
+    <up-action-sheet :show="showResultSheet"
+                     :actions="resultSheetOptions"
+                     @select="selectResult"
+                     @close="showResultSheet = false"
+                     title="閫夋嫨妫�娴嬬粨鏋�" />
+    <!-- 妫�楠屽憳閫夋嫨 -->
+    <up-action-sheet :show="showInspectorSheet"
+                     :actions="userSheetOptions"
+                     @select="selectInspector"
+                     @close="showInspectorSheet = false"
+                     title="閫夋嫨妫�楠屽憳" />
+    <!-- 鎸囨爣閫夋嫨 -->
+    <up-action-sheet :show="showTestStandardSheet"
+                     :actions="testStandardSheetOptions"
+                     @select="selectTestStandard"
+                     @close="showTestStandardSheet = false"
+                     title="閫夋嫨鎸囨爣" />
+    <!-- 浜у搧鏍戝舰閫夋嫨鍣� -->
+    <up-popup v-model:show="showProductTree"
+              position="bottom"
+              :round="true"
+              :closeable="true"
+              @close="showProductTree = false">
+      <view class="tree-selector">
+        <view class="tree-header">
+          <text class="tree-title">閫夋嫨浜у搧</text>
+        </view>
+        <view class="tree-content">
+          <view class="tree-node"
+                v-for="(node, index) in productOptions"
+                :key="index">
+            <view v-if="node.children && node.children.length > 0"
+                  class="tree-node-header"
+                  @click="toggleNode(node)">
+              <up-icon :name="node.expanded ? 'arrow-down' : 'arrow-right'"
+                       class="tree-node-icon" />
+              <text class="tree-node-label">{{ node.label }}</text>
+            </view>
+            <view v-else
+                  class="tree-node-header"
+                  @click="selectTreeNode(node)">
+              <text class="tree-node-icon-placeholder"></text>
+              <text class="tree-node-label">{{ node.label }}</text>
+              <up-icon name="checkmark"
+                       v-if="form.productId == node.value"
+                       class="tree-node-check" />
+            </view>
+            <view v-if="node.children && node.children.length > 0 && node.expanded"
+                  class="tree-node-children">
+              <view class="tree-node"
+                    v-for="(child, childIndex) in node.children"
+                    :key="childIndex">
+                <view v-if="child.children && child.children.length > 0"
+                      class="tree-node-header"
+                      @click="toggleNode(child)">
+                  <up-icon :name="child.expanded ? 'arrow-down' : 'arrow-right'"
+                           class="tree-node-icon" />
+                  <text class="tree-node-label">{{ child.label }}</text>
+                </view>
+                <view v-else
+                      class="tree-node-header"
+                      @click="selectTreeNode(child)">
+                  <text class="tree-node-icon-placeholder"></text>
+                  <text class="tree-node-label">{{ child.label }}</text>
+                  <up-icon name="checkmark"
+                           v-if="form.productId == child.value"
+                           class="tree-node-check" />
+                </view>
+                <view v-if="child.children && child.children.length > 0 && child.expanded"
+                      class="tree-node-children">
+                  <view class="tree-node"
+                        v-for="(grandchild, grandchildIndex) in child.children"
+                        :key="grandchildIndex">
+                    <view class="tree-node-header"
+                          @click="selectTreeNode(grandchild)">
+                      <text class="tree-node-icon-placeholder"></text>
+                      <text class="tree-node-label">{{ grandchild.label }}</text>
+                      <up-icon name="checkmark"
+                               v-if="form.productId == grandchild.value"
+                               class="tree-node-check" />
+                    </view>
+                  </view>
+                </view>
+              </view>
+            </view>
+          </view>
+        </view>
+      </view>
+    </up-popup>
+  </view>
+</template>
+
+<script setup>
+  import { ref, computed, onMounted, nextTick } from "vue";
+  import { onShow } from "@dcloudio/uni-app";
+  import PageHeader from "@/components/PageHeader.vue";
+  import dayjs from "dayjs";
+  import { getOptions } from "@/api/procurementManagement/procurementLedger.js";
+  import { modelList, productTreeList } from "@/api/basicData/product.js";
+  import {
+    qualityInspectAdd,
+    qualityInspectUpdate,
+    qualityInspectParamInfo,
+    qualityInspectDetailByProductId,
+    getQualityTestStandardParamByTestStandardId,
+  } from "@/api/qualityManagement/materialInspection.js";
+  import { userListNoPage } from "@/api/system/user.js";
+
+  // 鏄剧ず鎻愮ず淇℃伅
+  const showToast = message => {
+    uni.showToast({
+      title: message,
+      icon: "none",
+    });
+  };
+
+  // 琛ㄥ崟寮曠敤
+  const formRef = ref(null);
+  // 鍔犺浇鐘舵��
+  const loading = ref(false);
+  // 鏃ユ湡閫夋嫨鍣�
+  const showDate = ref(false);
+  // 渚涘簲鍟嗛�夋嫨
+  const showSupplierSheet = ref(false);
+  // 浜у搧閫夋嫨
+  const showProductSheet = ref(false);
+  // 浜у搧鏍戝舰閫夋嫨鍣�
+  const showProductTree = ref(false);
+  // 瑙勬牸鍨嬪彿閫夋嫨
+  const showModelSheet = ref(false);
+  // 妫�娴嬬粨鏋滈�夋嫨
+  const showResultSheet = ref(false);
+  // 妫�楠屽憳閫夋嫨
+  const showInspectorSheet = ref(false);
+  // 鎸囨爣閫夋嫨
+  const showTestStandardSheet = ref(false);
+
+  // 琛ㄥ崟鏁版嵁
+  const form = ref({
+    checkTime: dayjs().format("YYYY-MM-DD"),
+    supplier: "",
+    checkName: "",
+    productName: "",
+    productId: "",
+    productModelId: "",
+    model: "",
+    testStandardId: "",
+    unit: "",
+    quantity: "",
+    checkCompany: "",
+    checkResult: "",
+    productMainId: null,
+    purchaseLedgerId: null,
+  });
+
+  // 鏄剧ず鐢ㄧ殑鍙橀噺
+  const testStandardDisplay = ref("");
+
+  // 妫�楠岄」鐩�
+  const tableData = ref([]);
+  const tableLoading = ref(false);
+
+  // 渚涘簲鍟嗗垪琛�
+  const supplierList = ref([]);
+  // 浜у搧閫夐」
+  const productOptions = ref([]);
+  // 鍨嬪彿閫夐」
+  const modelOptions = ref([]);
+  // 妫�楠屽憳鍒楄〃
+  const userList = ref([]);
+  // 妫�娴嬬粨鏋滈�夐」
+  const resultOptions = ref([
+    { label: "鍚堟牸", value: "鍚堟牸" },
+    { label: "涓嶅悎鏍�", value: "涓嶅悎鏍�" },
+  ]);
+  // 鎸囨爣閫夐」
+  const testStandardOptions = ref([]);
+  // 褰撳墠浜у搧ID
+  const currentProductId = ref(0);
+
+  // ActionSheet閫夐」
+  const supplierOptions = computed(() => {
+    return supplierList.value.map(item => ({
+      name: item.supplierName,
+      value: item.supplierName,
+    }));
+  });
+
+  const productSheetOptions = computed(() => {
+    return productOptions.value.map(item => ({
+      name: item.label,
+      value: item.value,
+    }));
+  });
+
+  const modelSheetOptions = computed(() => {
+    return modelOptions.value.map(item => ({
+      name: item.model,
+      value: item.id,
+    }));
+  });
+
+  const resultSheetOptions = computed(() => {
+    return resultOptions.value.map(item => ({
+      name: item.label,
+      value: item.value,
+    }));
+  });
+
+  const userSheetOptions = computed(() => {
+    return userList.value.map(item => ({
+      name: item.nickName,
+      value: item.nickName,
+    }));
+  });
+
+  const testStandardSheetOptions = computed(() => {
+    return testStandardOptions.value.map(item => ({
+      name: item.standardName || item.standardNo,
+      value: item.id,
+    }));
+  });
+
+  // 琛ㄥ崟楠岃瘉瑙勫垯
+  const rules = {
+    checkTime: [{ required: true, message: "璇疯緭鍏�", trigger: "blur" }],
+    supplier: [{ required: true, message: "璇疯緭鍏�", trigger: "blur" }],
+    checkName: [{ required: false, message: "璇疯緭鍏�", trigger: "blur" }],
+    productId: [{ required: true, message: "璇疯緭鍏�", trigger: "blur" }],
+    productModelId: [
+      { required: true, message: "璇烽�夋嫨浜у搧鍨嬪彿", trigger: "change" },
+    ],
+    testStandardId: [
+      { required: false, message: "璇烽�夋嫨鎸囨爣", trigger: "change" },
+    ],
+    unit: [{ required: false, message: "璇疯緭鍏�", trigger: "blur" }],
+    quantity: [{ required: true, message: "璇疯緭鍏�", trigger: "blur" }],
+    checkCompany: [{ required: false, message: "璇疯緭鍏�", trigger: "blur" }],
+    checkResult: [
+      { required: true, message: "璇烽�夋嫨妫�娴嬬粨鏋�", trigger: "change" },
+    ],
+  };
+
+  // 鏄惁涓虹紪杈戞ā寮�
+  const isEdit = computed(() => {
+    const id = getPageId();
+    return !!id;
+  });
+
+  // 缂栬緫鏃讹細productMainId 鎴� purchaseLedgerId 浠讳竴鏈夊�煎垯渚涘簲鍟嗐�佹暟閲忕疆鐏�
+  const supplierQuantityDisabled = computed(() => {
+    const v = form.value || {};
+    return !!(v.productMainId != null || v.purchaseLedgerId != null);
+  });
+
+  // 鑾峰彇椤甸潰ID
+  const getPageId = () => {
+    const pages = getCurrentPages();
+    const currentPage = pages[pages.length - 1];
+    return currentPage.options.id;
+  };
+
+  // 杩斿洖涓婁竴椤�
+  const goBack = () => {
+    uni.navigateBack();
+  };
+
+  // 鏄剧ず鏃ユ湡閫夋嫨鍣�
+  const showDatePicker = () => {
+    showDate.value = true;
+  };
+
+  // 纭鏃ユ湡閫夋嫨
+  const confirmDate = e => {
+    form.value.checkTime = dayjs(e.value).format("YYYY-MM-DD");
+  };
+
+  // 閫夋嫨渚涘簲鍟�
+  const selectSupplier = e => {
+    form.value.supplier = e.value;
+    showSupplierSheet.value = false;
+  };
+
+  // 閫夋嫨浜у搧
+  const selectProduct = e => {
+    form.value.productId = e.value;
+    form.value.productName = e.name;
+    showProductSheet.value = false;
+    getModels(e.value);
+  };
+
+  // 鍒囨崲鏍戝舰鑺傜偣灞曞紑/鎶樺彔
+  const toggleNode = node => {
+    node.expanded = !node.expanded;
+  };
+
+  // 閫夋嫨鏍戝舰鑺傜偣
+  const selectTreeNode = node => {
+    // 纭繚鍙�夋嫨鏈鑺傜偣
+    if (!node.children || node.children.length == 0) {
+      form.value.productId = node.value;
+      form.value.productName = node.label;
+      showProductTree.value = false;
+      getModels(node.value);
+    }
+  };
+
+  // 杞崲浜у搧鏍戠粨鏋�
+  function convertIdToValue(data) {
+    return data.map(item => {
+      const { id, children, ...rest } = item;
+      const newItem = {
+        ...rest,
+        value: id, // 灏� id 鏀逛负 value
+      };
+      if (children && children.length > 0) {
+        newItem.children = convertIdToValue(children);
+      }
+
+      return newItem;
+    });
+  }
+
+  // 鏍规嵁ID鏌ユ壘鑺傜偣
+  const findNodeById = (nodes, productId) => {
+    for (let i = 0; i < nodes.length; i++) {
+      if (nodes[i].value === productId) {
+        return nodes[i].label; // 鎵惧埌鑺傜偣锛岃繑鍥炶鑺傜偣
+      }
+      if (nodes[i].children && nodes[i].children.length > 0) {
+        const foundNode = findNodeById(nodes[i].children, productId);
+        if (foundNode) {
+          return foundNode; // 鍦ㄥ瓙鑺傜偣涓壘鍒帮紝杩斿洖璇ヨ妭鐐�
+        }
+      }
+    }
+    return null; // 娌℃湁鎵惧埌鑺傜偣锛岃繑鍥瀗ull
+  };
+
+  // 閫夋嫨瑙勬牸鍨嬪彿
+  const selectModel = e => {
+    form.value.productModelId = e.value;
+    showModelSheet.value = false;
+    handleChangeModel(e.value);
+  };
+
+  // 澶勭悊鍨嬪彿鍙樺寲
+  const handleChangeModel = value => {
+    form.value.model =
+      modelOptions.value.find(item => item.id == value)?.model || "";
+    form.value.unit =
+      modelOptions.value.find(item => item.id == value)?.unit || "";
+  };
+
+  // 閫夋嫨妫�娴嬬粨鏋�
+  const selectResult = e => {
+    form.value.checkResult = e.value;
+    showResultSheet.value = false;
+  };
+
+  // 閫夋嫨妫�楠屽憳
+  const selectInspector = e => {
+    form.value.checkName = e.value;
+    showInspectorSheet.value = false;
+  };
+
+  // 閫夋嫨鎸囨爣
+  const selectTestStandard = e => {
+    form.value.testStandardId = e.value;
+    testStandardDisplay.value = e.name;
+    showTestStandardSheet.value = false;
+    handleTestStandardChange(e.value);
+  };
+
+  // 鎸囨爣閫夋嫨鍙樺寲澶勭悊
+  const handleTestStandardChange = testStandardId => {
+    if (!testStandardId) {
+      tableData.value = [];
+      return;
+    }
+    tableLoading.value = true;
+    getQualityTestStandardParamByTestStandardId(testStandardId)
+      .then(res => {
+        tableData.value = res.data || [];
+      })
+      .catch(error => {
+        console.error("鑾峰彇鏍囧噯鍙傛暟澶辫触:", error);
+        tableData.value = [];
+      })
+      .finally(() => {
+        tableLoading.value = false;
+      });
+  };
+  const openTestStandardSheet = () => {
+    console.log("openTestStandardSheet");
+    showTestStandardSheet.value = true;
+  };
+
+  // 鑾峰彇渚涘簲鍟嗗垪琛�
+  const getSuppliers = () => {
+    getOptions().then(res => {
+      supplierList.value = res.data;
+    });
+  };
+
+  // 鑾峰彇浜у搧閫夐」
+  const getProductOptions = () => {
+    return productTreeList().then(res => {
+      productOptions.value = convertIdToValue(res);
+      return productOptions.value;
+    });
+  };
+
+  // 鑾峰彇鐢ㄦ埛鍒楄〃
+  const getUserList = async () => {
+    try {
+      const userRes = await userListNoPage();
+      userList.value = userRes.data || [];
+    } catch (e) {
+      console.error("鍔犺浇妫�楠屽憳鍒楄〃澶辫触", e);
+      userList.value = [];
+    }
+  };
+
+  // 鑾峰彇鍨嬪彿鍒楄〃
+  const getModels = value => {
+    form.value.productModelId = "";
+    form.value.unit = "";
+    modelOptions.value = [];
+    currentProductId.value = value;
+    form.value.productName = findNodeById(productOptions.value, value);
+    modelList({ id: value }).then(res => {
+      modelOptions.value = res;
+    });
+    if (currentProductId.value) {
+      getList();
+    }
+  };
+
+  // 鑾峰彇鎸囨爣鍒楄〃
+  const getList = () => {
+    if (!currentProductId.value) {
+      testStandardOptions.value = [];
+      tableData.value = [];
+      return;
+    }
+    let params = {
+      productId: currentProductId.value,
+      inspectType: 0,
+    };
+    qualityInspectDetailByProductId(params).then(res => {
+      // 淇濆瓨涓嬫媺妗嗛�夐」鏁版嵁
+      testStandardOptions.value = res.data || [];
+      // 娓呯┖琛ㄦ牸鏁版嵁锛岀瓑寰呯敤鎴烽�夋嫨鎸囨爣
+      tableData.value = [];
+      // 娓呯┖鎸囨爣閫夋嫨
+      form.value.testStandardId = "";
+      testStandardDisplay.value = "";
+    });
+  };
+
+  // 鑾峰彇妫�楠屽弬鏁板垪琛紙缂栬緫妯″紡锛�
+  const getQualityInspectParamList = id => {
+    qualityInspectParamInfo(id).then(res => {
+      tableData.value = res.data;
+    });
+  };
+
+  // 鎻愪氦琛ㄥ崟
+  const submitForm = async () => {
+    console.log("submitForm", form.value, tableData.value);
+    try {
+      // await formRef.value.validate();
+      if (!form.value.productModelId) {
+        showToast("璇烽�夋嫨瑙勬牸鍨嬪彿");
+        return;
+      }
+      if (!form.value.supplier) {
+        showToast("璇烽�夋嫨渚涘簲鍟�");
+        return;
+      }
+      if (!form.value.quantity) {
+        showToast("璇疯緭鍏ユ暟閲�");
+        return;
+      }
+      if (!form.value.productId) {
+        showToast("璇烽�夋嫨浜у搧");
+        return;
+      }
+      if (!form.value.checkResult) {
+        showToast("璇烽�夋嫨妫�娴嬬粨鏋�");
+        return;
+      }
+
+      loading.value = true;
+
+      form.value.inspectType = 0;
+      if (isEdit.value) {
+        tableData.value.forEach(item => {
+          delete item.id;
+        });
+      }
+
+      const data = { ...form.value, qualityInspectParams: tableData.value };
+      data.quantity = Number(data.quantity);
+      if (isEdit.value) {
+        const res = await qualityInspectUpdate(data);
+        showToast("淇濆瓨鎴愬姛");
+        setTimeout(() => {
+          uni.navigateBack();
+        }, 1500);
+      } else {
+        const res = await qualityInspectAdd(data);
+        showToast("鎻愪氦鎴愬姛");
+        setTimeout(() => {
+          uni.navigateBack();
+        }, 1500);
+      }
+    } catch (error) {
+      console.error("琛ㄥ崟楠岃瘉澶辫触:", error);
+      showToast("鎻愪氦澶辫触锛岃閲嶈瘯");
+    } finally {
+      loading.value = false;
+    }
+  };
+
+  // 鍒濆鍖栬〃鍗�
+  const initForm = async () => {
+    const id = getPageId();
+    if (id) {
+      // 缂栬緫妯″紡锛屽姞杞芥暟鎹�
+      // 鍏堥噸缃〃鍗曟暟鎹�
+      form.value = {
+        checkTime: dayjs().format("YYYY-MM-DD"),
+        supplier: "",
+        checkName: "",
+        productName: "",
+        productId: "",
+        productModelId: "",
+        model: "",
+        testStandardId: "",
+        unit: "",
+        quantity: "",
+        checkCompany: "",
+        checkResult: "",
+        productMainId: null,
+        purchaseLedgerId: null,
+      };
+      testStandardOptions.value = [];
+      tableData.value = [];
+      // 鍏堢‘淇濅骇鍝佹爲宸插姞杞斤紝鍚﹀垯缂栬緫鏃朵骇鍝�/瑙勬牸鍨嬪彿鏃犳硶鍙嶆樉
+      await getProductOptions();
+      // 浠庢湰鍦板瓨鍌ㄨ幏鍙栫紪杈戞暟鎹�
+      const row = uni.getStorageSync("inspectionEditData") || {
+        id: id,
+        checkTime: "2026-03-03",
+        supplier: "涓婃捣閲戝睘鏉愭枡鏈夐檺鍏徃",
+        checkName: "寮犱笁",
+        productName: "涓嶉攬閽㈡澘鏉�",
+        productId: 1,
+        productModelId: 1,
+        model: "304",
+        testStandardId: "1",
+        unit: "kg",
+        quantity: 1000,
+        checkCompany: "绗笁鏂规娴嬫満鏋�",
+        checkResult: "鍚堟牸",
+        productMainId: null,
+        purchaseLedgerId: null,
+      };
+      // 鍏堜繚瀛� testStandardId锛岄伩鍏嶈娓呯┖
+      const savedTestStandardId = row.testStandardId;
+      form.value = { ...row };
+      currentProductId.value = row.productId || 0;
+      // 鍏抽敭锛氱紪杈戞椂鍔犺浇瑙勬牸鍨嬪彿涓嬫媺閫夐」锛屾墠鑳藉弽鏄� productModelId
+      if (currentProductId.value) {
+        try {
+          const res = await modelList({ id: currentProductId.value });
+          modelOptions.value = res || [];
+          // 鍚屾鍥炲~ model / unit
+          if (form.value.productModelId) {
+            handleChangeModel(form.value.productModelId);
+          }
+        } catch (e) {
+          console.error("鍔犺浇瑙勬牸鍨嬪彿澶辫触", e);
+          modelOptions.value = [];
+        }
+      }
+      // 缂栬緫妯″紡涓嬶紝鍏堝姞杞芥寚鏍囬�夐」锛岀劧鍚庡姞杞藉弬鏁板垪琛�
+      if (currentProductId.value) {
+        // 鍏堝姞杞芥寚鏍囬�夐」
+        let params = {
+          productId: currentProductId.value,
+          inspectType: 0,
+        };
+        qualityInspectDetailByProductId(params).then(res => {
+          testStandardOptions.value = res.data || [];
+          // 浣跨敤 nextTick 纭繚閫夐」宸茬粡娓叉煋
+          nextTick(() => {
+            // 濡傛灉缂栬緫鏁版嵁涓湁 testStandardId锛屽垯璁剧疆骞跺姞杞藉搴旂殑鍙傛暟
+            if (savedTestStandardId) {
+              // 纭繚绫诲瀷鍖归厤
+              const matchedOption = testStandardOptions.value.find(
+                item =>
+                  item.id == savedTestStandardId ||
+                  String(item.id) === String(savedTestStandardId)
+              );
+              if (matchedOption) {
+                // 纭繚浣跨敤鍖归厤椤圭殑 id
+                form.value.testStandardId = matchedOption.id;
+                testStandardDisplay.value =
+                  matchedOption.standardName || matchedOption.standardNo;
+                // 缂栬緫淇濈暀鍘熸楠屽�硷紝鐩存帴鎷夊彇鍘熷弬鏁版暟鎹�
+                getQualityInspectParamList(row.id);
+              } else {
+                // 濡傛灉鎵句笉鍒板尮閰嶉」锛屽皾璇曠洿鎺ヤ娇鐢ㄥ師鍊�
+                console.warn(
+                  "鏈壘鍒板尮閰嶇殑鎸囨爣閫夐」锛宼estStandardId:",
+                  savedTestStandardId
+                );
+                form.value.testStandardId = savedTestStandardId;
+                getQualityInspectParamList(row.id);
+              }
+            } else {
+              // 鍚﹀垯浣跨敤鏃х殑閫昏緫
+              getQualityInspectParamList(row.id);
+            }
+          });
+        });
+      }
+      // 灞曞紑浜у搧鏍戝埌褰撳墠閫変腑鐨勮妭鐐�
+      expandProductTree(productOptions.value, row.productId);
+    } else {
+      // 鏂板妯″紡锛屽垵濮嬪寲琛ㄥ崟
+      form.value = {
+        checkTime: dayjs().format("YYYY-MM-DD"),
+        supplier: "",
+        checkName: "",
+        productName: "",
+        productId: "",
+        productModelId: "",
+        model: "",
+        testStandardId: "",
+        unit: "",
+        quantity: "",
+        checkCompany: "",
+        checkResult: "",
+        productMainId: null,
+        purchaseLedgerId: null,
+      };
+    }
+  };
+
+  // 灞曞紑浜у搧鏍戝埌鎸囧畾鑺傜偣
+  const expandProductTree = (nodes, targetId) => {
+    for (let i = 0; i < nodes.length; i++) {
+      const node = nodes[i];
+      if (node.value === targetId) {
+        return true; // 鎵惧埌鐩爣鑺傜偣
+      }
+      if (node.children && node.children.length > 0) {
+        const found = expandProductTree(node.children, targetId);
+        if (found) {
+          node.expanded = true; // 灞曞紑鐖惰妭鐐�
+          return true;
+        }
+      }
+    }
+    return false;
+  };
+
+  onMounted(() => {
+    getSuppliers();
+    getProductOptions();
+    getUserList();
+    initForm();
+  });
+
+  onShow(() => {
+    initForm();
+  });
+</script>
+
+<style scoped lang="scss">
+  @import "@/static/scss/form-common.scss";
+
+  .material-inspection-add {
+    min-height: 100vh;
+    background: #f8f9fa;
+    padding-bottom: 100px;
+  }
+
+  // 妫�楠岄」鐩鍣�
+  .inspection-items-container {
+    padding: 20px;
+    background-color: #fff;
+  }
+
+  .steps-header {
+    display: flex;
+    justify-content: space-between;
+    align-items: center;
+    margin-bottom: 20px;
+    padding-bottom: 12px;
+    border-bottom: 1px solid #e4e7ed;
+  }
+
+  .steps-title {
+    font-size: 16px;
+    font-weight: 600;
+    color: #303133;
+  }
+
+  .steps-count {
+    font-size: 14px;
+    color: #909399;
+  }
+
+  .steps-list {
+    margin-bottom: 20px;
+  }
+
+  .exec-step-item {
+    position: relative;
+    display: flex;
+    margin-bottom: 16px;
+    padding: 16px;
+    background-color: #ffffff;
+    border: 1px solid #e4e7ed;
+    border-radius: 8px;
+    transition: all 0.3s ease;
+    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
+  }
+
+  .exec-step-item:hover {
+    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
+    border-color: #409eff;
+    transform: translateY(-1px);
+  }
+
+  .delete-btn {
+    position: absolute;
+    top: -25rpx;
+    right: -25rpx;
+    width: 50rpx;
+    height: 50rpx;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    text-align: center;
+    font-size: 20px;
+    border-radius: 50%;
+    background-color: red;
+    border: none;
+    z-index: 10;
+  }
+
+  .delete-btn:hover {
+    transform: scale(1.1);
+    box-shadow: 0 3px 6px rgba(245, 108, 108, 0.4);
+  }
+
+  .step-number {
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    width: 32px;
+    height: 32px;
+    margin-right: 16px;
+    background-color: #ecf5ff;
+    color: #409eff;
+    font-size: 14px;
+    font-weight: 600;
+    border-radius: 50%;
+    flex-shrink: 0;
+  }
+
+  .step-content {
+    flex: 1;
+    min-width: 0;
+  }
+
+  .step-row {
+    display: flex;
+    align-items: flex-start;
+    margin-bottom: 12px;
+  }
+
+  .step-row:last-child {
+    margin-bottom: 0;
+  }
+
+  .step-label {
+    display: inline-block;
+    width: 80px;
+    font-size: 14px;
+    color: #606266;
+    margin-right: 12px;
+    flex-shrink: 0;
+    line-height: 36px;
+  }
+
+  .step-input {
+    flex: 1;
+    min-width: 0;
+  }
+
+  .step-input input {
+    font-size: 14px;
+    color: #303133;
+  }
+
+  .add-step-btn {
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    width: 100%;
+    height: 44px;
+    line-height: 44px;
+    font-size: 14px;
+    border-radius: 8px;
+    transition: all 0.3s ease;
+    gap: 8px;
+  }
+
+  .add-step-btn:hover {
+    transform: translateY(-1px);
+    box-shadow: 0 2px 8px rgba(64, 158, 255, 0.3);
+  }
+
+  .add-step-btn text {
+    font-size: 14px;
+  }
+
+  // 搴曢儴鎸夐挳
+  .bottom-buttons {
+    position: fixed;
+    bottom: 0;
+    left: 0;
+    right: 0;
+    display: flex;
+    padding: 16px 20px;
+    background: #ffffff;
+    border-top: 1px solid #f0f0f0;
+    gap: 16px;
+  }
+
+  .bottom-btn {
+    flex: 1;
+  }
+
+  // 鏍戝舰閫夋嫨鍣ㄦ牱寮�
+  .tree-selector {
+    width: 100%;
+    max-height: 70vh;
+    background: #ffffff;
+    border-radius: 16px 16px 0 0;
+  }
+
+  .tree-header {
+    padding: 16px 20px;
+    border-bottom: 1px solid #f0f0f0;
+    text-align: center;
+  }
+
+  .tree-title {
+    font-size: 16px;
+    font-weight: 600;
+    color: #303133;
+  }
+
+  .tree-content {
+    padding: 10px 0;
+    max-height: calc(70vh - 60px);
+    overflow-y: auto;
+  }
+
+  .tree-node {
+    padding: 0 20px;
+  }
+
+  .tree-node-header {
+    display: flex;
+    align-items: center;
+    padding: 12px 0;
+    cursor: pointer;
+  }
+
+  .tree-node-icon {
+    width: 20px;
+    height: 20px;
+    margin-right: 8px;
+    color: #909399;
+  }
+
+  .tree-node-icon-placeholder {
+    width: 20px;
+    height: 20px;
+    margin-right: 8px;
+  }
+
+  .tree-node-label {
+    flex: 1;
+    font-size: 14px;
+    color: #303133;
+  }
+
+  .tree-node-check {
+    width: 20px;
+    height: 20px;
+    color: #409eff;
+  }
+
+  .tree-node-children {
+    margin-left: 28px;
+  }
+</style>

--
Gitblit v1.9.3