Przeglądaj źródła

Merge remote-tracking branch 'origin/dev' into test

lihaiting 1 tydzień temu
rodzic
commit
62c34800a5

+ 11 - 0
src/api/bpm/components/purchasingManage/purchasePlanManage.js

@@ -63,3 +63,14 @@ export async function cancel(data) {
   }
   return Promise.reject(new Error(res.data.message));
 }
+/**
+ * 获取审批采购部门
+ * 返回部门对象(id / name / parentId / type);无匹配部门时返回空对象
+ */
+export async function getApprovalPurchaseDept() {
+  const res = await request.get(`/eom/purchaseplan/getApprovalPurchaseDept`);
+  if (res.data.code == 0) {
+    return res.data.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}

+ 22 - 2
src/components/CommomSelect/dept-select.vue

@@ -30,21 +30,41 @@
     },
     data () {
       return {
-        treeData: []
+        treeData: [],
+        /** 组织原始平铺数据:用于按 id 校验节点是否存在 */
+        orgList: [],
+        /** 首屏组织数据加载 promise */
+        dataLoading: null
       };
     },
     created () {
-      this.getData();
+      this.dataLoading = this.getData();
     },
     methods: {
       async getData (params = {}) {
         const data = await listOrganizations(params);
+        this.orgList = data || [];
         this.treeData = this.$util.toTreeData({
           data: data || [],
           idField: 'id',
           parentIdField: 'parentId'
         });
       },
+      /**
+       * 判断部门 id 是否存在于组织架构中(等待首屏数据加载完成)
+       * 供父组件在「程序化默认值」场景下校验,避免传入不存在的部门 id
+       */
+      async hasNode (id) {
+        if (id === undefined || id === null || id === '') return false;
+        try {
+          if (this.dataLoading) await this.dataLoading;
+        } catch (error) {
+          return false;
+        }
+        return this.orgList.some(
+          item => item && String(item.id) === String(id)
+        );
+      },
       /* 更新选中数据 */
       updateValue (value) {
         this.$emit('input', value);

+ 60 - 6
src/views/bpm/handleTask/components/purchasePlanManage/submit.vue

@@ -8,7 +8,7 @@
         style="margin-bottom: 20px"
       >
         <deptSelect
-        
+          ref="deptSelectRef"
           v-model="form.useDeptId"
           @changeGroup="searchDeptNodeClick"
         />
@@ -127,7 +127,8 @@
   import {
     assign,
     cancel,
-    UpdateInformation
+    UpdateInformation,
+    getApprovalPurchaseDept
   } from '@/api/bpm/components/purchasingManage/purchasePlanManage';
   import deptSelect from '@/components/CommomSelect/dept-select.vue';
   import { getUserPage } from '@/api/system/organization';
@@ -170,7 +171,42 @@
     created() {
       this.getAllUsers()
     },
+    mounted() {
+      // 需要部门下拉已挂载(ref 可用)后才能校验默认值是否合法
+      this.loadApprovalPurchaseDept()
+    },
     methods: {
+      /**
+       * 主管指派节点:接口返回审批采购部门时,自动预选该部门并带出其下的采购员。
+       * 接口返回空对象、或返回的部门不在组织架构中 → 不预选,保持手选,
+       * 避免把不存在的部门 id 传给采购员查询接口、导致通过时取不到采购员。
+       */
+      async loadApprovalPurchaseDept() {
+        if (this.taskDefinitionKey !== 'deptLeaderAssign') return;
+        try {
+          const dept = await getApprovalPurchaseDept();
+          if (!dept || !Object.keys(dept).length) return;
+          // 部门主键,与 /main/group/getGroupList 节点 id(dept-select 的 value-key)对应
+          const deptId = dept.id;
+          if (deptId === undefined || deptId === null || deptId === '') return;
+          const deptSelect = this.$refs.deptSelectRef;
+          const exists = deptSelect ? await deptSelect.hasNode(deptId) : false;
+          if (!exists) {
+            this.$message.warning(
+              `审批采购部门「${dept.name || deptId}」不在组织架构中,请手动选择采购部门`
+            );
+            return;
+          }
+          this.form.useDeptId = deptId;
+          // 部门确定后按该部门筛选采购员,与手动选择部门的行为保持一致
+          this.searchDeptNodeClick(deptId);
+        } catch (error) {
+          console.warn(
+            '[采购计划审批] 获取审批采购部门失败:',
+            error.message || error
+          );
+        }
+      },
       getAllUsers() {
         this.userOptions = [];
         listAllUserBind().then((data) => {
@@ -255,6 +291,10 @@
         console.log(this.form)
         //主管指派采购员
         if (this.taskDefinitionKey === 'deptLeaderAssign') {
+          if (!this.form.useDeptId) {
+            this.$message.warning(`请选择采购部门!`);
+            return;
+          }
           if (!this.form.userId) {
             this.$message.warning(`请选择采购员!`);
             return;
@@ -265,7 +305,9 @@
             assignList: this.form.assignList,
             id: this.taskId,
             reason: this.form.reason,
-            businessId: this.businessId
+            businessId: this.businessId,
+            // 采购部门:取界面上当前选中的部门(可能是接口默认带出的,也可能是手选的)
+            useDeptId: this.form.useDeptId
           });
         }
         // //采购员核对
@@ -284,6 +326,10 @@
 
         if(this.taskDefinitionKey === 'deptLeaderAssign') {
           variables.userId = this.selectId.join(',');
+          // 采购部门:与界面显示保持一致(默认带出的或手选的),通过/驳回都要带对
+          if (this.form.useDeptId) {
+            variables.useDeptId = this.form.useDeptId;
+          }
         }
         await API({
           id: this.taskId,
@@ -296,12 +342,20 @@
         });
       },
       async rejectTask(status) {
+        const variables = {
+          pass: !!status
+        };
+        // 主管指派节点驳回:部门同样按界面当前值带出,保证与通过时口径一致
+        if (
+          this.taskDefinitionKey === 'deptLeaderAssign' &&
+          this.form.useDeptId
+        ) {
+          variables.useDeptId = this.form.useDeptId;
+        }
         await rejectTask({
           id: this.taskId,
           reason: this.form.reason,
-          variables: {
-            pass: !!status
-          }
+          variables
         });
         this.$emit('handleAudit', {
           status,

+ 2 - 2
vue.config.js

@@ -48,8 +48,8 @@ module.exports = {
         // target: 'http://192.168.1.3:18086',
         // target: 'http://192.168.1.147:18086', // 陈兵
         // target: 'http://192.168.1.116:18086', // 赵沙金
-        // target: 'http://192.168.1.113:18086', // 郭丹
-        target: 'http://192.168.1.102:18086', // 吴志豪
+        target: 'http://192.168.1.113:18086', // 郭丹
+        // target: 'http://192.168.1.102:18086', // 吴志豪
 
         changeOrigin: true, // 只有这个值为true的情况下 s才表示开启跨域
         pathRewrite: {