Quellcode durchsuchen

refactor(安检上报): 重构岗位数据初始化逻辑

将岗位数据获取逻辑提取到独立方法initPositionAndOptions中
在安检员变更时自动更新岗位选项数据
huoyi vor 2 Monaten
Ursprung
Commit
3002660ffc
1 geänderte Dateien mit 27 neuen und 15 gelöschten Zeilen
  1. 27 15
      src/pages/seizedReported/index.vue

+ 27 - 15
src/pages/seizedReported/index.vue

@@ -765,10 +765,9 @@ export default {
765 765
           treeSelectByType("ITEM_CATEGORY", 3),
766 766
           treeSelectByType("CHECK_POINT", 3)
767 767
         ]);
768
-        // 查询用户岗位列表
769
-        const postListsRes = await getPostListsByUserId(this.currentUser.id);
770
-
771
-
768
+        // 初始化岗位选项数据
769
+        await this.initPositionAndOptions();
770
+        
772 771
         const convertTree = (list = []) =>
773 772
           list.map(node => ({
774 773
             text: node.label,
@@ -776,27 +775,18 @@ export default {
776 775
             children: node.children ? convertTree(node.children) : null
777 776
           }))
778 777
 
779
-
780
-
781
-
782 778
         this.position_options = convertTree(positionRes.data || []);
783 779
         this.item_category_options = itemCategoryRes.data || [];
784 780
         this.forbiddenList = itemCategoryRes.data || [];
785 781
         this.check_point_options = checkPointRes.data || [];
786 782
 
787
-        // 岗位  item_check_method_options (x光机  人身检查)字典  item_check_method
788 783
         // 处理方式  item_handling_method_options  字典  item_handling_method
789 784
         // 单位 units  字典  item_unit
790 785
         const dict = await this.useDict(
791
-          // 'item_check_method',
792 786
           'item_handling_method',
793 787
           'item_unit'
794 788
         )
795 789
 
796
-
797
-
798
-
799
-        this.item_check_method_options = postListsRes.data || [];
800 790
         this.item_handling_method_options = dict.item_handling_method || [];
801 791
         // console.log(this.item_handling_method_options,"this.item_handling_method_options")
802 792
         this.item_unit_options = dict.item_unit || [];
@@ -831,6 +821,23 @@ export default {
831 821
       return result;
832 822
     },
833 823
 
824
+    // 初始化岗位和选项数据
825
+    async initPositionAndOptions() {
826
+      try {
827
+        // 使用当前选择的inspectUserId查询岗位列表
828
+        const userId = this.formData.inspectUserId || this.currentUser.id;
829
+        const postListsRes = await getPostListsByUserId(userId);
830
+
831
+
832
+        // 更新岗位选项
833
+        this.item_check_method_options = postListsRes.data || [];
834
+        
835
+        console.log("岗位和选项数据已更新,用户ID:", userId);
836
+      } catch (error) {
837
+        console.error("初始化岗位和选项数据失败:", error);
838
+      }
839
+    },
840
+
834 841
     // 加载部门人员(kezhang角色使用)
835 842
     async loadDepartmentUsers() {
836 843
       if (!this.isKezhang) return;
@@ -1061,11 +1068,16 @@ export default {
1061 1068
     },
1062 1069
 
1063 1070
     // 安检员选择变化(kezhang角色使用)
1064
-    onInspectUserChange(e) {
1065
-      console.log("安检员选择变化", e.detail.value)
1071
+    async onInspectUserChange(e) {
1072
+      console.log("查获人员选择变化", e.detail.value)
1066 1073
       const arr = e.detail.value || [];
1067 1074
       this.formData.inspectUserId = arr[arr.length - 1]?.value || '';
1068 1075
       this.formData.inspectUserName = arr.map(item => item.text).join('/');
1076
+      
1077
+      // 切换查获人员后,重新初始化岗位和选项数据
1078
+      if (this.formData.inspectUserId) {
1079
+        await this.initPositionAndOptions();
1080
+      }
1069 1081
     },
1070 1082
 
1071 1083
     // 部位类型变化