Browse Source

refactor(attendance): 重构考勤班组组件和弹窗的区域选择逻辑

1.  修复考勤人员选择弹窗的区域数据解析逻辑,新增selectedLocationPath存储完整三级路径
2.  重构positions计算属性,支持正确解析终端、区域、通道三级选择数据
3.  优化树形转换函数,保留原始节点的区域通道字段信息
4.  移除多余的debugger语句和空行冗余代码
5.  修正curUserWorkingGroupData赋值逻辑,直接使用result变量
huoyi 5 days ago
parent
commit
3628efb411

+ 42 - 25
src/pages/attendance/components/AddAttendancePersonnelModal.vue

@@ -160,7 +160,8 @@ export default {
160 160
       isSubmittingPost: false,
161 161
       currentTime: undefined,
162 162
       errModalShow: false,
163
-      errModalContent: ''
163
+      errModalContent: '',
164
+      selectedLocationPath: [] // 存储完整的三级路径数据
164 165
     }
165 166
   },
166 167
   computed: {
@@ -169,37 +170,44 @@ export default {
169 170
     },
170 171
     //单选获取的区域
171 172
     positions() {
172
-      return this.notkezhang ? {
173
+      // 解析三级路径数据
174
+      const path = this.selectedLocationPath
175
+      const result = {
176
+        terminlCode: '',
177
+        terminlName: '',
173 178
         regionalCode: '',
174 179
         regionalName: '',
175
-        channelCode: this.channelOrRegional,
176
-        channelName: this.channelOrRegionalName
177
-      } : {
178
-        regionalCode: this.channelOrRegional,
179
-        regionalName: this.channelOrRegionalName,
180 180
         channelCode: '',
181 181
         channelName: ''
182 182
       }
183
+
184
+      if (path.length >= 1) {
185
+        result.terminlCode = path[0].terminlCode || path[0].value
186
+        result.terminlName = path[0].terminlName || path[0].text
187
+      }
188
+      if (path.length >= 2) {
189
+        result.regionalCode = path[1].regionalCode || path[1].value
190
+        result.regionalName = path[1].regionalName || path[1].text
191
+      }
192
+      if (path.length >= 3) {
193
+        result.channelCode = path[2].channelCode || path[2].value
194
+        result.channelName = path[2].channelName || path[2].text
195
+      }
196
+
197
+      return result
183 198
     },
184 199
     //多选获得的区域
185 200
     getSelectArea() {
186 201
       let area = []
187 202
       this.selectedAreas.forEach(item => {
188 203
         item.children.forEach(child => {
189
-          area.push(this.notkezhang ? {
190
-            regionalCode: '',
191
-            regionalName: '',
192
-            channelCode: child.code,
193
-            channelName: child.label,
194
-            terminlCode: item.code,
195
-            terminlName: item.label
196
-          } : {
197
-            regionalCode: child.code,
198
-            regionalName: child.label,
199
-            channelCode: '',
200
-            channelName: '',
201
-            terminlCode: item.code,
202
-            terminlName: item.label
204
+          area.push({
205
+            terminlCode: child.terminlCode || item.code,
206
+            terminlName: child.terminlName || item.label,
207
+            regionalCode: child.regionalCode || (this.notkezhang ? '' : child.code),
208
+            regionalName: child.regionalName || (this.notkezhang ? '' : child.label),
209
+            channelCode: child.channelCode || (this.notkezhang ? child.code : ''),
210
+            channelName: child.channelName || (this.notkezhang ? child.label : '')
203 211
           })
204 212
         })
205 213
       })
@@ -268,7 +276,14 @@ export default {
268 276
       return list.map(node => ({
269 277
         text: node.label,
270 278
         value: node.code,
271
-        children: node.children ? this.convertTree(node.children) : null
279
+        children: node.children ? this.convertTree(node.children) : null,
280
+        // 保留原始数据字段
281
+        terminlName: node.terminlName,
282
+        terminlCode: node.terminlCode,
283
+        regionalName: node.regionalName,
284
+        regionalCode: node.regionalCode,
285
+        channelName: node.channelName,
286
+        channelCode: node.channelCode
272 287
       }))
273 288
     },
274 289
     invokerDataConfigTree(level) {
@@ -281,6 +296,8 @@ export default {
281 296
     onLocationChange({ detail }) {
282 297
       const { value } = detail
283 298
       this.channelOrRegionalName = value.map(item => item.text).join('/')
299
+      // 存储完整的三级路径数据
300
+      this.selectedLocationPath = value
284 301
     },
285 302
     openModal() {
286 303
       if (this.disabled || (this.selectedMember.length === 0 && this.notkezhang)) return
@@ -383,12 +400,12 @@ export default {
383 400
         });
384 401
         return;
385 402
       }
386
-      debugger
403
+      
387 404
       const checkUserStatusALL = this.selectedUser.map(item => {
388 405
         return this.checkUserStatus(item)
389 406
       })
390 407
       uni.showLoading({ title: '正在查询人员状态...' });
391
-      debugger
408
+      
392 409
       Promise.all(checkUserStatusALL).then((res) => {
393 410
         const checkResult = res.filter(Boolean)
394 411
         if (checkResult.length) {
@@ -468,7 +485,7 @@ export default {
468 485
           }];
469 486
         }
470 487
         console.log(postRecordList, "postRecordList")
471
-        debugger
488
+        
472 489
 
473 490
         return addPostRecord(postRecordList)
474 491
       });

+ 9 - 8
src/pages/attendance/components/WorkingGroup.vue

@@ -52,7 +52,8 @@
52 52
       <!-- {{ selectedMember.length === 0 }}{{ !userInfo.roles.includes('banzuzhang') }}{{ !attendanceInfo.checkInTime }} -->
53 53
       <!-- :disabled="!attendanceInfo.checkInTime || checkOutStatus" -->
54 54
       <AddAttendancePersonnelModal v-if="index === 0" :disabled="checkOutStatus" :notkezhang="notkezhang"
55
-        :userInfo="userInfo" @updateRecord="invokerGetPostRecordList" :selectedMember="selectedMember" :attendanceInfo="attendanceInfo">
55
+        :userInfo="userInfo" @updateRecord="invokerGetPostRecordList" :selectedMember="selectedMember"
56
+        :attendanceInfo="attendanceInfo">
56 57
         <!-- :class="{ disabled: !attendanceInfo.checkInTime }"   没有选人不可以上通道 -->
57 58
         <view v-if="authority" class="custom-btn" @click="openModal"
58 59
           :class="{ disabled: selectedMember.length === 0 && !userInfo.roles.includes('banzuzhang') || (!attendanceInfo.checkInTime || (attendanceInfo.checkInTime && attendanceInfo.checkOutTime)) }">
@@ -132,8 +133,8 @@ export default {
132 133
       if (!this.checkOutStatus) {
133 134
         return;
134 135
       }
135
-  
136
-      
136
+
137
+
137 138
       this.currentTime = formatTime(new Date())
138 139
       this.checkOutWork = true
139 140
     },
@@ -181,12 +182,12 @@ export default {
181 182
                 checkOutTime: attr.checkOutTime === '2000-01-01 00:00:00' ? '' : formatTime(attr.checkOutTime, 'hh:mm:ss'),
182 183
                 userName: formatName(attr.userName),
183 184
               }
184
-              if (attr.userId === this.userInfo.userId) {
185
-                info = result
186
-              }
187
-
185
+              // if (attr.userId === this.userInfo.userId) {
186
+              //   info = result
187
+              // }
188
+              info = result
188 189
               if (index === 0) { // 取最新纪录
189
-                this.curUserWorkingGroupData = info
190
+                this.curUserWorkingGroupData = result
190 191
                 this.workingGroupId = item.shiftCode
191 192
               }
192 193
               return result