Browse Source

fix:5656【采购订单】根据当前用户带出来的采购部门、采购方不对;销售的售出方也有问题

mlchen 2 weeks ago
parent
commit
806ff726d7

+ 40 - 22
src/views/purchasingManage/purchaseOrder/components/addDialogNew.vue

@@ -1756,7 +1756,7 @@
       },
       // 获取公司数据
       getGroupAll() {
-        listOrganizations().then((list) => {
+        return listOrganizations().then((list) => {
           this.groupData = list;
           this.groupTreeData = this.$util.toTreeData({
             data: list,
@@ -2247,6 +2247,9 @@
         this.rawDetailListCache = [];
         this.outputDetailListCache = [];
         this.visible = true;
+        if (this.groupData.length == 0) {
+          await this.getGroupAll();
+        }
         if (this.enterprisePage.length == 0) {
           await this.getEnterprisePage();
         }
@@ -2254,23 +2257,21 @@
           // console.log('enterprisePage~~~~~', this.enterprisePage);
           this.form.transactionMode = this.defaultTransactionMode;
           this.isUpdate = false;
-          if (this.enterprisePage.length > 0) {
-            this.form.partaName = this.enterprisePage[0]?.name;
-            this.form.partaUnifiedSocialCreditCode =
-              this.enterprisePage[0]?.unifiedSocialCreditCode;
-            this.form.partaFax = this.enterprisePage[0]?.fax;
-            this.form.partaAddress = this.enterprisePage[0]?.address;
-            this.form.purchaseDeptId = this.enterprisePage[0]?.groupId || '';
-            this.form.purchaseDeptName = this.enterprisePage[0]?.name || '';
-            this.form.purchaseUserId = this.$store.state.user.info?.id || '';
-            this.form.purchaseUserName = this.$store.state.user.info?.name || '';
-            this.$nextTick(() => {
-              this.issueNumberChange(this.form.issueNumber);
-              if(this.form.purchaseDeptId) {
-                this.getPurchaseUser(this.form.purchaseDeptId);
-              }
-            })
+          const userInfo = this.$store.state.user.info || {};
+          const enterprise = this.getCurrentEnterprise();
+          this.form.purchaseDeptId = userInfo.groupId || '';
+          this.form.purchaseDeptName = userInfo.groupName || '';
+          this.form.purchaseUserId = userInfo.id || '';
+          this.form.purchaseUserName = userInfo.name || '';
+          if (enterprise) {
+            this.getEnterprise(enterprise);
           }
+          this.$nextTick(() => {
+            this.issueNumberChange(this.form.issueNumber);
+            if (this.form.purchaseDeptId) {
+              this.getPurchaseUser(this.form.purchaseDeptId);
+            }
+          });
           this.form.contractStartDate = formatDate(new Date(), 'yyyy-MM-dd');
           this.form.isGeneratePaymentPlan = +this.isGenReceiptPlan;
         } else {
@@ -2279,7 +2280,7 @@
         }
       },
       getEnterprisePage() {
-        enterprisePage({
+        return enterprisePage({
           pageNum: 1,
           size: 100
         }).then((res) => {
@@ -2287,11 +2288,28 @@
           this.enterprisePage.push(...res.list);
         });
       },
-      getEnterprise() {
-        let data = this.enterprisePage.find(
-          (item) => item.name == this.form.quoteName
-        );
+      getCurrentEnterprise() {
+        let groupId = this.$store.state.user.info?.groupId;
+        const visitedGroupIds = [];
+        while (groupId && !visitedGroupIds.includes(groupId)) {
+          const enterprise = this.enterprisePage.find(
+            (item) => item.groupId == groupId
+          );
+          if (enterprise) {
+            return enterprise;
+          }
+          visitedGroupIds.push(groupId);
+          const group = this.groupData.find((item) => item.id == groupId);
+          groupId = group?.parentId;
+        }
+        return this.enterprisePage.length === 1 ? this.enterprisePage[0] : null;
+      },
+      getEnterprise(enterprise) {
+        let data =
+          enterprise ||
+          this.enterprisePage.find((item) => item.name == this.form.partaName);
         this.form.partaName = data.name;
+        this.form.partaId = data.id;
         this.form.partaUnifiedSocialCreditCode = data.unifiedSocialCreditCode;
         this.form.partaFax = data.fax;
         this.form.partaAddress = data.address;

+ 34 - 20
src/views/saleManage/saleOrder/components/addDialogNew.vue

@@ -1274,7 +1274,7 @@
                 deptIds: ['1998632792148717569', '1998632872721297409']
               })
             : listOrganizations();
-        apiRequest.then((list) => {
+        return apiRequest.then((list) => {
           // console.log('listOrganizations', list);
           this.groupData = list;
           this.groupTreeData = this.$util.toTreeData({
@@ -1918,6 +1918,9 @@
         // this.clientEnvironmentId =
         //   this.$store.state.user.info.clientEnvironmentId;
         this.row = row;
+        if (this.groupData.length == 0) {
+          await this.getGroupAll();
+        }
         if (this.enterprisePage.length == 0) {
           await this.getEnterprisePage();
         }
@@ -1926,13 +1929,9 @@
         if (type == 'add') {
           this.form.transactionMode = this.defaultTransactionMode;
           this.isUpdate = false;
-          if (this.enterprisePage.length > 0) {
-            this.form.partbName = this.enterprisePage[0].name;
-            this.form.partbId = this.enterprisePage[0].id;
-            this.form.partbUnifiedSocialCreditCode =
-              this.enterprisePage[0].unifiedSocialCreditCode;
-            this.form.partbFax = this.enterprisePage[0].fax;
-            this.form.partbAddress = this.enterprisePage[0].address;
+          const enterprise = this.getCurrentEnterprise();
+          if (enterprise) {
+            this.getEnterprise(enterprise);
           }
           if (this.contactData.id) {
             this.changeParent({ id: this.contactData.id });
@@ -1988,23 +1987,22 @@
         this.title = '新增';
         this.visible = true;
         this.isUpdate = false;
+        if (this.groupData.length == 0) {
+          await this.getGroupAll();
+        }
         if (this.enterprisePage.length == 0) {
           await this.getEnterprisePage();
         }
-        if (this.enterprisePage.length > 0) {
-          this.form.partbName = this.enterprisePage[0].name;
-          this.form.partbId = this.enterprisePage[0].id;
-          this.form.partbUnifiedSocialCreditCode =
-            this.enterprisePage[0].unifiedSocialCreditCode;
-          this.form.partbFax = this.enterprisePage[0].fax;
-          this.form.partbAddress = this.enterprisePage[0].address;
+        const enterprise = this.getCurrentEnterprise();
+        if (enterprise) {
+          this.getEnterprise(enterprise);
         }
         this.form.createDeptName = this.user.info.groupName;
         this.form.isGenerateReceiptPlan = +this.isGenReceiptPlan;
         await this.changeContract(row);
       },
       getEnterprisePage() {
-        enterprisePage({
+        return enterprisePage({
           pageNum: 1,
           size: 100
         }).then((res) => {
@@ -2012,10 +2010,26 @@
           this.enterprisePage.push(...res.list);
         });
       },
-      getEnterprise() {
-        let data = this.enterprisePage.find(
-          (item) => item.name == this.form.partbName
-        );
+      getCurrentEnterprise() {
+        let groupId = this.$store.state.user.info?.groupId;
+        const visitedGroupIds = [];
+        while (groupId && !visitedGroupIds.includes(groupId)) {
+          const enterprise = this.enterprisePage.find(
+            (item) => item.groupId == groupId
+          );
+          if (enterprise) {
+            return enterprise;
+          }
+          visitedGroupIds.push(groupId);
+          const group = this.groupData.find((item) => item.id == groupId);
+          groupId = group?.parentId;
+        }
+        return this.enterprisePage.length === 1 ? this.enterprisePage[0] : null;
+      },
+      getEnterprise(enterprise) {
+        let data =
+          enterprise ||
+          this.enterprisePage.find((item) => item.name == this.form.partbName);
         this.form.partbName = data.name;
         this.form.partbId = data.id;
         this.form.partbUnifiedSocialCreditCode = data.unifiedSocialCreditCode;