Ver código fonte

fix:5664创建合同、订单等,售出方或采购方名称应该默认为当前登陆人所属机构的名称

mlchen 2 semanas atrás
pai
commit
660801ecf7

+ 43 - 19
src/views/contractManage/contractBook/components/addDialog.vue

@@ -1177,16 +1177,8 @@
       }
     },
     created() {
-      this.getGroupAll();
-      enterprisePage({
-        pageNum: 1,
-        size: 200
-      }).then((res) => {
-        console.log('企业列表', res);
-        console.log('企业列表第一个', this.$store.state.user.info);
-        this.companyInfo = res.list[0] || {};
-        this.enterprisePage = [];
-        this.enterprisePage.push(...res.list);
+      Promise.all([this.getGroupAll(), this.getEnterprisePage()]).then(() => {
+        this.companyInfo = this.getCurrentEnterprise() || {};
         this.getEnterprise();
       });
       //交易方式//1 先票后款 2 先款后票
@@ -1207,7 +1199,7 @@
       },
       // 获取公司数据
       getGroupAll() {
-        listOrganizations().then((list) => {
+        return listOrganizations().then((list) => {
           this.groupData = list;
           this.groupTreeData = this.$util.toTreeData({
             data: list,
@@ -1519,21 +1511,45 @@
           this.form[keyArr[4]] = data.address;
           return;
         }
-        if (this.enterprisePage.length > 0) {
+        const enterprise = this.getCurrentEnterprise();
+        if (enterprise) {
           this.form[keyArr[0]] =
-            this.form[keyArr[0]] || this.enterprisePage[0].name;
+            this.form[keyArr[0]] || enterprise.name;
           this.form[keyArr[1]] =
-            this.form[keyArr[1]] || this.enterprisePage[0].id;
+            this.form[keyArr[1]] || enterprise.id;
           this.form[keyArr[2]] =
             this.form[keyArr[2]] ||
-            this.enterprisePage[0].unifiedSocialCreditCode;
-          this.form[keyArr[2]] =
-            this.form[keyArr[2]] || this.enterprisePage[0].fax;
+            enterprise.unifiedSocialCreditCode;
           this.form[keyArr[3]] =
-            this.form[keyArr[3]] || this.enterprisePage[0].fax;
+            this.form[keyArr[3]] || enterprise.fax;
           this.form[keyArr[4]] =
-            this.form[keyArr[4]] || this.enterprisePage[0].address;
+            this.form[keyArr[4]] || enterprise.address;
+        }
+      },
+      getEnterprisePage() {
+        return enterprisePage({
+          pageNum: 1,
+          size: 200
+        }).then((res) => {
+          this.enterprisePage = [];
+          this.enterprisePage.push(...res.list);
+        });
+      },
+      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;
       },
 
       // 交易方式改变
@@ -1703,6 +1719,13 @@
         this.create = create;
         this.source = source;
         this.contractBookTypeList = copyObj(this.categoryTreeList[0].children);
+        if (this.groupData.length == 0) {
+          await this.getGroupAll();
+        }
+        if (this.enterprisePage.length == 0) {
+          await this.getEnterprisePage();
+        }
+        this.companyInfo = this.getCurrentEnterprise() || {};
         console.log('contractBookTypeList!!!', this.contractBookTypeList);
         if (type == 'add') {
           console.log(
@@ -1712,6 +1735,7 @@
           let userInfo = this.$store.getters.user.info;
           this.form.transactionMode = this.defaultTransactionMode;
           this.isUpdate = false;
+          this.getEnterprise();
           userInfo.id = userInfo.userId;
           this.changePersonel();
           this.form.contractStartDate = new Date();

+ 34 - 10
src/views/saleManage/quotation/components/addDialog.vue

@@ -305,6 +305,7 @@ import {
 } from '@/api/saleManage/businessOpportunity';
 import { getTableList } from '@/api/saleManage/businessOpportunity';
 import { enterprisePage } from '@/api/contractManage/contractBook';
+import { listOrganizations } from '@/api/system/organization';
 import { getcontactlink } from '@/api/saleManage/businessFollow';
 import headList from '@/BIZComponents/user-select/user-select.vue';
 import { copyObj } from '@/utils/util';
@@ -472,6 +473,7 @@ export default {
     };
   },
   created() {
+    this.getGroupAll();
     this.getEnterprisePage();
   },
 
@@ -632,6 +634,9 @@ export default {
       this.editType = type;
       this.row = row;
       this.visible = true;
+      if (this.groupData.length == 0) {
+        await this.getGroupAll();
+      }
       if (this.enterprisePage.length == 0) {
         await this.getEnterprisePage();
       }
@@ -641,11 +646,9 @@ export default {
         userInfo.id = userInfo.userId;
         this.form.settlementMode = '3';
         this.changePersonel(userInfo);
-        if (this.enterprisePage.length > 0) {
-          this.form.quoteName = this.enterprisePage[0].name;
-          // this.form.quoteTel = this.enterprisePage[0].tel;
-          this.form.quoteFax = this.enterprisePage[0].fax;
-          this.form.quoteAddress = this.enterprisePage[0].address;
+        const enterprise = this.getCurrentEnterprise();
+        if (enterprise) {
+          this.getEnterprise(enterprise);
         }
         if (this.contactData.id) {
           this.changeParent({ id: this.contactData.id }, 'init');
@@ -670,8 +673,13 @@ export default {
         await this.getDetailData(row.id);
       }
     },
+    getGroupAll() {
+      return listOrganizations().then((list) => {
+        this.groupData = list;
+      });
+    },
     getEnterprisePage() {
-      enterprisePage({
+      return enterprisePage({
         pageNum: 1,
         size: 100
       }).then((res) => {
@@ -679,10 +687,26 @@ export default {
         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.quoteName);
       this.form.quoteName = data.name;
 
       // this.form.quoteTel = data.tel;