gaoluyang
2026-05-18 da57fbd8e7fa021614fb32502fb1520ea4e34e1e
src/views/basicData/product/index.vue
@@ -43,12 +43,12 @@
                <el-button type="primary"
                           link
                           :disabled="isTopLevelNode(data, node)"
                           @click="openProDia('edit', data)">
                           @click="openProDia('edit', data, node)">
                  编辑
                </el-button>
                <el-button type="primary"
                           link
                           @click="openProDia('add', data)">
                           @click="openProDia('add', data, node)">
                  添加产品
                </el-button>
                <el-button v-if="!node.childNodes.length"
@@ -161,6 +161,17 @@
                        placeholder="请输入单位"
                        clearable
                        @keydown.enter.prevent />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="库存量:"
                          prop="stockInventory">
              <el-input-number v-model="modelForm.stockInventory"
                               :min="0"
                               style="width: 100%"
                               placeholder="请输入库存量"
                               controls-position="right"
                               @keydown.enter.prevent />
            </el-form-item>
          </el-col>
        </el-row>
@@ -285,6 +296,8 @@
  const search = ref("");
  const currentId = ref("");
  const currentParentId = ref("");
  /** 产品弹窗:add 存父节点 id;edit 存当前节点 id 与 parentId(不依赖树选中项) */
  const productDialogTarget = ref(null);
  const operationType = ref("");
  const treeLoad = ref(false);
  const list = ref([]);
@@ -301,6 +314,10 @@
    {
      label: "单位",
      prop: "unit",
    },
    {
      label: "库存量",
      prop: "stockInventory",
    },
    {
      dataType: "action",
@@ -340,18 +357,18 @@
      model: "",
      unit: "",
      productCode: "",
      stockInventory: 0,
    },
    modelRules: {
      model: [{ required: true, message: "请输入", trigger: "blur" }],
      unit: [{ required: true, message: "请输入", trigger: "blur" }],
      productCode: [{ required: true, message: "请输入", trigger: "blur" }],
    },
  });
  const { form, rules, modelForm, modelRules } = toRefs(data);
  // 查询产品树
  const getProductTreeList = () => {
    treeLoad.value = true;
    productTreeList()
    productTreeList({ productType: "成品" })
      .then(res => {
        list.value = res || [];
        normalizeExpandedKeys(list.value);
@@ -388,17 +405,28 @@
    return [null, undefined, "", 0, "0"].includes(data?.parentId);
  };
  // 打开产品弹框
  const openProDia = (type, data) => {
    if (data && type === "edit" && isTopLevelNode(data)) {
  const openProDia = (type, data, node) => {
    if (data && type === "edit" && isTopLevelNode(data, node)) {
      proxy.$modal.msgWarning("一级节点不能编辑或删除");
      return;
    }
    operationType.value = type;
    productDia.value = true;
    form.value.productName = "";
    if (type === "edit") {
      form.value.productName = data.productName;
    productDialogTarget.value = null;
    if (type === "add" && data) {
      productDialogTarget.value = { parentId: data.id };
    } else if (type === "edit" && data) {
      let parentId = data.parentId;
      if (
        [null, undefined, ""].includes(parentId) &&
        node?.parent?.data?.id != null
      ) {
        parentId = node.parent.data.id;
      }
      productDialogTarget.value = { id: data.id, parentId };
    }
    productDia.value = true;
    form.value.productName =
      type === "edit" && data ? data.productName : "";
  };
  // 打开规格型号弹框
  const openModelDia = (type, data) => {
@@ -407,6 +435,7 @@
    modelForm.value.model = "";
    modelForm.value.unit = "";
    modelForm.value.productCode = "";
    modelForm.value.stockInventory = 0;
    modelForm.value.id = "";
    if (type === "edit") {
      modelForm.value = { ...data };
@@ -417,14 +446,16 @@
    proxy.$refs.formRef.validate(valid => {
      if (valid) {
        if (operationType.value === "add") {
          form.value.parentId = currentId.value;
          form.value.parentId =
            productDialogTarget.value?.parentId ?? currentId.value;
          form.value.id = "";
        } else if (operationType.value === "addOne") {
          form.value.id = "";
          form.value.parentId = "";
        } else {
          form.value.id = currentId.value;
          form.value.parentId = "";
          form.value.id =
            productDialogTarget.value?.id ?? currentId.value;
          form.value.parentId = productDialogTarget.value?.parentId ?? "";
        }
        addOrEditProduct(form.value).then(res => {
          proxy.$modal.msgSuccess("提交成功");
@@ -437,6 +468,7 @@
  // 关闭产品弹框
  const closeProDia = () => {
    proxy.$refs.formRef.resetFields();
    productDialogTarget.value = null;
    productDia.value = false;
  };