yyb
5 天以前 46e81fa90c8e089a781fdc994b5427b6e57fb311
src/views/basicData/customerFile/index.vue
@@ -592,7 +592,7 @@
    },
    {
      label: "客户地区",
      prop: "regions",
      prop: "regionsName",
      width: 120,
    },
    {
@@ -721,6 +721,8 @@
      taxpayerIdentificationNumber: "",
      companyAddress: "",
      regions: "",
      regionsId: "",
      regionsld: "",
      companyPhone: "",
      contactPerson: "",
      contactPhone: "",
@@ -958,10 +960,14 @@
    const ids = value || [];
    if (!ids.length) {
      form.value.regions = "";
      form.value.regionsId = "";
      form.value.regionsld = "";
      return;
    }
    const lastId = ids[ids.length - 1];
    form.value.regions = regionNodeMap.value.get(lastId)?.regionsName || "";
    form.value.regionsId = lastId;
    form.value.regionsld = lastId;
  };
  const findRegionPathByName = (tree, targetName, parentPath = []) => {
    for (const item of tree || []) {
@@ -970,6 +976,18 @@
        return currentPath;
      }
      const childResult = findRegionPathByName(item.children || [], targetName, currentPath);
      if (childResult.length) return childResult;
    }
    return [];
  };
  const findRegionPathById = (tree, targetId, parentPath = []) => {
    if (targetId === undefined || targetId === null || targetId === "") return [];
    for (const item of tree || []) {
      const currentPath = [...parentPath, item.id];
      if (String(item.id) === String(targetId)) {
        return currentPath;
      }
      const childResult = findRegionPathById(item.children || [], targetId, currentPath);
      if (childResult.length) return childResult;
    }
    return [];
@@ -1028,6 +1046,8 @@
    operationType.value = type;
    form.value = {};
    formRegionPath.value = [];
    form.value.regionsId = "";
    form.value.regionsld = "";
    form.value.maintainer = userStore.nickName;
    formYYs.value.contactList = [
      {
@@ -1042,10 +1062,23 @@
    if (type === "edit") {
      getCustomer(row.id).then(res => {
        form.value = { ...res.data };
        formRegionPath.value = findRegionPathByName(
          regionTreeData.value,
          form.value.regions || ""
        );
        const regionIdForEdit = form.value.regionsId || form.value.regionsld;
        formRegionPath.value = findRegionPathById(regionTreeData.value, regionIdForEdit);
        if (!formRegionPath.value.length) {
          formRegionPath.value = findRegionPathByName(
            regionTreeData.value,
            form.value.regionsName || form.value.regions || ""
          );
        }
        const selectedRegionId =
          formRegionPath.value.length > 0
            ? formRegionPath.value[formRegionPath.value.length - 1]
            : "";
        if (selectedRegionId && !form.value.regions) {
          form.value.regions = regionNodeMap.value.get(selectedRegionId)?.regionsName || "";
        }
        form.value.regionsId = form.value.regionsId || selectedRegionId;
        form.value.regionsld = form.value.regionsld || form.value.regionsId || selectedRegionId;
        formYYs.value.contactList = res.data.contactPerson
          .split(",")
          .map((item, index) => {
@@ -1081,6 +1114,10 @@
    form.value.contactPhone = formYYs.value.contactList
      .map(item => item.contactPhone)
      .join(",");
    if (!form.value.regionsId && formRegionPath.value.length) {
      form.value.regionsId = formRegionPath.value[formRegionPath.value.length - 1];
    }
    form.value.regionsld = form.value.regionsId || "";
    addCustomer(form.value).then(res => {
      proxy.$modal.msgSuccess("提交成功");
      closeDia();
@@ -1095,6 +1132,10 @@
    form.value.contactPhone = formYYs.value.contactList
      .map(item => item.contactPhone)
      .join(",");
    if (!form.value.regionsId && formRegionPath.value.length) {
      form.value.regionsId = formRegionPath.value[formRegionPath.value.length - 1];
    }
    form.value.regionsld = form.value.regionsId || "";
    updateCustomer(form.value).then(res => {
      proxy.$modal.msgSuccess("提交成功");
      closeDia();