spring
2 天以前 ffecde25db733a6295d24e484684922470c6599a
fix: 编辑产品小类时,提示选择父节点
已修改1个文件
38 ■■■■ 文件已修改
src/views/basicData/product/index.vue 38 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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"
@@ -285,6 +285,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([]);
@@ -388,17 +390,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) => {
@@ -417,14 +430,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 +452,7 @@
  // 关闭产品弹框
  const closeProDia = () => {
    proxy.$refs.formRef.resetFields();
    productDialogTarget.value = null;
    productDia.value = false;
  };