From af8cab142a6b15c06e131a8474574dd5b00df982 Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期四, 04 十二月 2025 22:09:58 +0800
Subject: [PATCH] feat: 改造微信accesstoken存放在系统配置表中

---
 app/pagesTask/components/StaffSelector.vue |  130 ++++++++++++++++++++++++++++++++++++-------
 1 files changed, 109 insertions(+), 21 deletions(-)

diff --git a/app/pagesTask/components/StaffSelector.vue b/app/pagesTask/components/StaffSelector.vue
index 55c5391..972aae1 100644
--- a/app/pagesTask/components/StaffSelector.vue
+++ b/app/pagesTask/components/StaffSelector.vue
@@ -5,7 +5,7 @@
       <view class="staff-list">
         <view class="staff-item" v-for="(staff, index) in selectedStaff" :key="staff.userId">
           <view class="staff-info">
-            <text class="staff-name">{{ staff.nickName }}</text>
+            <text class="staff-name">{{ getStaffDisplayName(staff) }}</text>
           </view>
           <uni-icons 
             v-if="canRemove(index)"
@@ -109,7 +109,7 @@
 <script>
 import { mapState } from 'vuex'
 import uniPopup from '@/uni_modules/uni-popup/components/uni-popup/uni-popup.vue'
-import { listBranchUsers } from "@/api/system/user"
+import { listUsersByBranchDepts } from "@/api/system/user"
 
 export default {
   name: 'StaffSelector',
@@ -141,6 +141,16 @@
     currentUserRemovable: {
       type: Boolean,
       default: false
+    },
+    // 鍒嗗叕鍙窱D鍒楄〃锛堝閮ㄤ紶鍏ワ紝鐢ㄤ簬鎸囧畾鍔犺浇鍝簺鍒嗗叕鍙哥殑鐢ㄦ埛锛�
+    branchDeptIds: {
+      type: Array,
+      default: null
+    },
+    // 鍗曚釜鍒嗗叕鍙窱D锛堜粎浼犱竴涓椂鏇翠究鎹凤級
+    branchDeptId: {
+      type: [Number, String],
+      default: null
     }
   },
   data() {
@@ -149,7 +159,9 @@
       allStaffList: [],
       filteredStaffList: [],
       staffSearchKeyword: '',
-      staffFilterType: 'driver' // 榛樿閫変腑鍙告満
+      staffFilterType: 'driver', // 榛樿閫変腑鍙告満
+      staffListCache: {}, // 缂撳瓨: { key: { data: [], timestamp: 0 } }
+      cacheExpireTime: 5 * 60 * 1000 // 缂撳瓨杩囨湡鏃堕棿锛�5鍒嗛挓
     }
   },
   computed: {
@@ -174,6 +186,23 @@
       },
       immediate: true,
       deep: true
+    },
+    // 鐩戝惉鍒嗗叕鍙窱D鏁扮粍鍙樺寲锛岄噸鏂板姞杞界敤鎴峰垪琛�
+    branchDeptIds: {
+      handler(newVal, oldVal) {
+        if (JSON.stringify(newVal) !== JSON.stringify(oldVal)) {
+          console.log('鍒嗗叕鍙窱D鍙樺寲锛岄噸鏂板姞杞界敤鎴�:', newVal)
+          this.loadStaffList()
+        }
+      },
+      deep: true
+    },
+    // 鐩戝惉鍗曚釜鍒嗗叕鍙窱D鍙樺寲
+    branchDeptId(newVal, oldVal) {
+      if (newVal !== oldVal) {
+        console.log('鍒嗗叕鍙窱D鍙樺寲锛岄噸鏂板姞杞界敤鎴�:', newVal)
+        this.loadStaffList()
+      }
     }
   },
   mounted() {
@@ -207,29 +236,73 @@
     
     // 鍔犺浇浜哄憳鍒楄〃
     loadStaffList() {
-      listBranchUsers().then(response => {
+      // 鑾峰彇鎵�鏈夐儴闂↖D
+      let deptIds = []
+      if (this.branchDeptIds && this.branchDeptIds.length > 0) {
+        deptIds = this.branchDeptIds
+      } else if (this.branchDeptId) {
+        deptIds = [this.branchDeptId]
+      }
+          
+      if (deptIds.length > 0) {
+        console.log('鏍规嵁鍒嗗叕鍙窱D鍔犺浇鐢ㄦ埛:', deptIds)
+        this.loadStaffByBranchDepts(deptIds)
+      } else {
+        console.log('鏈紶鍏ュ垎鍏徃ID,缁勪欢涓嶅姞杞戒汉鍛樺垪琛�')
+        this.$modal && this.$modal.showToast && this.$modal.showToast('璇蜂紶鍏ュ垎鍏徃ID')
+      }
+    },
+    
+    // 鏍规嵁鍒嗗叕鍙窱D鏁扮粍鍔犺浇鐢ㄦ埛锛堟敮鎸佺紦瀛橈級
+    loadStaffByBranchDepts(deptIds) {
+      // 鐢熸垚缂撳瓨key锛堟寜鎺掑簭鍚巌d鎷兼帴锛�
+      const cacheKey = [...deptIds].sort((a, b) => a - b).join(',')
+      const cached = this.staffListCache[cacheKey]
+      const now = Date.now()
+      
+      // 妫�鏌ョ紦瀛樻槸鍚︽湁鏁�
+      if (cached && (now - cached.timestamp) < this.cacheExpireTime) {
+        console.log('浣跨敤缂撳瓨鐨勪汉鍛樺垪琛�:', cacheKey)
+        this.processUserList(cached.data)
+        return
+      }
+      
+      // 缂撳瓨澶辨晥鎴栦笉瀛樺湪,璋冪敤鎺ュ彛
+      console.log('鍔犺浇浜哄憳鍒楄〃:', deptIds)
+      listUsersByBranchDepts(deptIds).then(response => {
         const userList = response.data || []
-        
-        this.allStaffList = userList.map(user => ({
-          userId: user.userId,
-          nickName: user.nickName,
-          phonenumber: user.phonenumber,
-          deptName: user.dept?.deptName || '',
-          postName: user.posts && user.posts.length > 0 ? user.posts[0].postName : '',
-          roleName: user.roles && user.roles.length > 0 ? user.roles[0].roleName : '',
-          posts: user.posts || [],
-          roles: user.roles || [],
-          dept: user.dept || null,
-          // 鏀寔澶氱绫诲瀷
-          types: this.getUserTypes(user),
-          type: this.getUserTypes(user)[0] || 'driver' // 涓昏绫诲瀷锛堢敤浜庡悜鍚庡吋瀹癸級
-        }))
-        
-        this.filterStaffList()
+        // 鏇存柊缂撳瓨
+        this.staffListCache[cacheKey] = {
+          data: userList,
+          timestamp: now
+        }
+        this.processUserList(userList)
       }).catch(error => {
         console.error('鍔犺浇浜哄憳鍒楄〃澶辫触:', error)
         this.$modal.showToast('鍔犺浇浜哄憳鍒楄〃澶辫触')
       })
+    },
+
+    
+    
+    // 澶勭悊鐢ㄦ埛鍒楄〃鏁版嵁
+    processUserList(userList) {
+      this.allStaffList = userList.map(user => ({
+        userId: user.userId,
+        nickName: user.nickName,
+        phonenumber: user.phonenumber,
+        deptName: user.dept?.deptName || '',
+        postName: user.posts && user.posts.length > 0 ? user.posts[0].postName : '',
+        roleName: user.roles && user.roles.length > 0 ? user.roles[0].roleName : '',
+        posts: user.posts || [],
+        roles: user.roles || [],
+        dept: user.dept || null,
+        // 鏀寔澶氱绫诲瀷
+        types: this.getUserTypes(user),
+        type: this.getUserTypes(user)[0] || 'driver' // 涓昏绫诲瀷锛堢敤浜庡悜鍚庡吋瀹癸級
+      }))
+      
+      this.filterStaffList()
     },
     
     // 鏍规嵁鐢ㄦ埛鐨勫矖浣嶆垨瑙掕壊鍒ゆ柇鎵�鏈夌被鍨嬶紙鏀寔澶氱韬唤锛�
@@ -381,6 +454,21 @@
     emitChange() {
       this.$emit('input', this.selectedStaff)
       this.$emit('change', this.selectedStaff)
+    },
+    
+    // 鑾峰彇浜哄憳鏄剧ず鍚嶇О锛堜紭鍏堟樉绀哄鍚嶏紝濡傛灉濮撳悕涓虹┖鍒欐樉绀烘墜鏈哄彿锛�
+    getStaffDisplayName(staff) {
+      if (!staff) {
+        return '鏈煡浜哄憳'
+      }
+      // 浼樺厛鏄剧ず nickName锛屽鏋滀负绌哄垯鏄剧ず鎵嬫満鍙凤紝閮戒负绌哄垯鏄剧ず userId
+      if (staff.nickName && staff.nickName.trim()) {
+        return staff.nickName
+      }
+      if (staff.phonenumber && staff.phonenumber.trim()) {
+        return staff.phonenumber
+      }
+      return `鐢ㄦ埛${staff.userId || ''}`
     }
   }
 }

--
Gitblit v1.9.1