Bladeren bron

feat(fuzzy-select): 添加删除按钮功能并优化问题人选择逻辑

在fuzzy-select组件中添加删除按钮,支持清空选择项
优化problemRect页面中问题人选择逻辑,处理null值和删除操作
修复问题人必填校验时的提示信息
huoyi 4 maanden geleden
bovenliggende
commit
0b01834c4d
3 gewijzigde bestanden met toevoegingen van 104 en 23 verwijderingen
  1. 50 3
      src/components/fuzzy-select/fuzzy-select.vue
  2. 2 2
      src/config.js
  3. 52 18
      src/pages/problemRect/index.vue

+ 50 - 3
src/components/fuzzy-select/fuzzy-select.vue

@@ -1,8 +1,15 @@
1 1
 <template>
2 2
   <view class="fuzzy-select-container">
3
-    <!-- 搜索输入框 -->
4
-    <uni-easyinput ref="inputRef" v-model="searchKeyword" :placeholder="placeholder" :clearable="true"
5
-      :disabled="disabled" @input="handleInput" @focus="showDropdown = true" @blur="handleBlur" />
3
+    <!-- 搜索输入框和删除按钮 -->
4
+    <view class="input-container">
5
+      <uni-easyinput ref="inputRef" v-model="searchKeyword" :placeholder="placeholder" :clearable="true"
6
+        :disabled="disabled" @input="handleInput" @focus="showDropdown = true" @blur="handleBlur" />
7
+      
8
+      <!-- 删除按钮 -->
9
+      <view v-if="value && !disabled" class="delete-btn" @click="handleDelete">
10
+        <text class="delete-icon">×</text>
11
+      </view>
12
+    </view>
6 13
 
7 14
     <!-- 下拉选项列表 -->
8 15
     <view v-if="showDropdown && filteredOptions.length > 0" class="dropdown-list">
@@ -175,6 +182,13 @@ export default {
175 182
         this.$refs.inputRef.blur()
176 183
       }
177 184
     },
185
+
186
+    // 处理删除
187
+    handleDelete() {
188
+      if (this.disabled) return;
189
+      this.clearSearch()
190
+      this.$emit('delete')
191
+    },
178 192
   }
179 193
 }
180 194
 </script>
@@ -185,6 +199,39 @@ export default {
185 199
   width: 100%;
186 200
 }
187 201
 
202
+.input-container {
203
+  position: relative;
204
+  display: flex;
205
+  align-items: center;
206
+}
207
+
208
+.delete-btn {
209
+  position: absolute;
210
+  right: 8px;
211
+  top: 50%;
212
+  transform: translateY(-50%);
213
+  width: 20px;
214
+  height: 20px;
215
+  border-radius: 50%;
216
+  background-color: #f0f0f0;
217
+  display: flex;
218
+  align-items: center;
219
+  justify-content: center;
220
+  cursor: pointer;
221
+  z-index: 10;
222
+}
223
+
224
+.delete-btn:hover {
225
+  background-color: #e0e0e0;
226
+}
227
+
228
+.delete-icon {
229
+  font-size: 16px;
230
+  color: #999;
231
+  font-weight: bold;
232
+  line-height: 1;
233
+}
234
+
188 235
 .dropdown-list {
189 236
   position: absolute;
190 237
   top: 100%;

+ 2 - 2
src/config.js

@@ -1,11 +1,11 @@
1 1
 // 应用全局配置
2 2
 module.exports = {
3 3
    // 接口地址  本地调试使用 http://192.168.3.222:38080  打包使用 /prod-api
4
- //  baseUrl: process.env.NODE_ENV === 'development' ? 'http://192.168.3.221:82/prod-api' : '/prod-api', //生产
4
+  //  baseUrl: process.env.NODE_ENV === 'development' ? 'http://192.168.3.221:82/prod-api' : '/prod-api', //生产
5 5
   //  baseUrl: process.env.NODE_ENV === 'development' ? 'http://192.168.3.221:8080' : '/prod-api',
6 6
 // baseUrl: process.env.NODE_ENV === 'development' ? 'http://guangxi.qinghe.sundot.cn:8088' : 'http://guangxi.qinghe.sundot.cn:8088/prod-api',
7 7
 // baseUrl: 'http://guangxi.qinghe.sundot.cn:8088',
8
-    baseUrl:'http://airport.samsundot.com:9021/prod-api',
8
+   baseUrl:'http://airport.samsundot.com:9021/prod-api',
9 9
   // 应用信息
10 10
   appInfo: {
11 11
     // 应用名称

+ 52 - 18
src/pages/problemRect/index.vue

@@ -62,12 +62,16 @@
62 62
                                     </view>
63 63
                                     <view class="problem-content">
64 64
                                         <view class="problem-person">
65
-                                            <view class="problem-label">问题人<text style="color: red;margin-left: 10rpx;">请确定问题人</text></view>
66
-
67
-                                            <fuzzy-select v-model="problem.checkUserList.userId" :options="userOptions"
68
-                                                :placeholder="'请输入问题' + (index + 1) + '的责任人'" data-value="userId"
69
-                                                data-text="nickName" @change="handleUserSelect"
70
-                                                :disabled="formDisabled" />
65
+                                            <view class="problem-label"><text v-if="isResponsiblePerson"
66
+                                                    style="color: red;">*</text>问题人<text
67
+                                                    style="color: red;margin-left: 10rpx;">请确定问题人</text></view>
68
+
69
+                                            <fuzzy-select :value="getCheckUserListValue(problem.checkUserList)"
70
+                                                :options="userOptions" :placeholder="'请输入问题' + (index + 1) + '的责任人'"
71
+                                                data-value="userId" data-text="nickName"
72
+                                                @input="handleUserInput(index, $event)"
73
+                                                @change="handleUserSelect($event, index)"
74
+                                                @delete="handleUserDelete(index)" :disabled="formDisabled" />
71 75
                                         </view>
72 76
                                         <view class="problem-description">
73 77
                                             <text class="problem-label">问题描述</text>
@@ -209,7 +213,7 @@ import { listAllUser } from "@/api/system/user.js"
209 213
 import { getProblemRectDetail, approvalAgree, approvalReject } from '@/api/problemRect/problemRect.js'
210 214
 import { getApprovelHistory } from '@/api/approve/approve.js'
211 215
 import { getDeptManager, getDeptDetail } from "@/api/system/dept/dept.js"
212
-import { buildTeamOptions, buildDepartmentOptions,buildBrigadeOptions } from "@/utils/common.js"
216
+import { buildTeamOptions, buildDepartmentOptions, buildBrigadeOptions } from "@/utils/common.js"
213 217
 export default {
214 218
     components: { HomeContainer, RejectModal },
215 219
     mixins: [useDictMixin],
@@ -315,7 +319,7 @@ export default {
315 319
                 selectTeamName: '', // 整改班组名称
316 320
                 selectTeamLeaderId: '', // 班组长ID
317 321
                 selectTeamLeaderName: '', // 班组长姓名
318
-                
322
+
319 323
                 // 被检查对象相关字段
320 324
                 checkedBrigadeId: '', // 被检查大队ID
321 325
                 checkedBrigadeName: '', // 被检查大队名称
@@ -364,10 +368,39 @@ export default {
364 368
         console.log(this.$store.state.user)
365 369
     },
366 370
     methods: {
367
-        handlecheckedDepartmentIdChange(e) {
371
+        handleUserSelect(e, index) {
372
+            const person = this.userOptions.find(item => item.userId == e)
373
+            if (this.formData.checkProjectItemList && this.formData.checkProjectItemList[index]) {
374
+                this.formData.checkProjectItemList[index].checkUserList = person;
375
+            }
376
+        },
368 377
 
378
+        // 获取checkUserList的值,处理null情况
379
+        getCheckUserListValue(checkUserList) {
380
+            return checkUserList && checkUserList.userId ? checkUserList.userId : '';
381
+        },
382
+
383
+        // 处理用户输入
384
+        handleUserInput(index, value) {
385
+            if (this.formData.checkProjectItemList && this.formData.checkProjectItemList[index]) {
386
+                if (!this.formData.checkProjectItemList[index].checkUserList) {
387
+                    this.formData.checkProjectItemList[index].checkUserList = {};
388
+                }
389
+                this.formData.checkProjectItemList[index].checkUserList.userId = value;
390
+            }
391
+        },
392
+
393
+        // 处理用户删除
394
+        handleUserDelete(index) {
395
+            // 将problem.checkUserList置为null
396
+            if (this.formData.checkProjectItemList && this.formData.checkProjectItemList[index]) {
397
+                this.formData.checkProjectItemList[index].checkUserList = null;
398
+                // 强制更新视图以确保fuzzy-select组件重新渲染
399
+                this.$nextTick(() => {
400
+                    this.$forceUpdate();
401
+                });
402
+            }
369 403
         },
370
-        
371 404
         // 被检查大队选择
372 405
         handlecheckedBrigadeIdChange(e) {
373 406
             const { text, value } = e.detail.value[0];
@@ -422,7 +455,7 @@ export default {
422 455
 
423 456
         // 填充表单数据
424 457
         async fillFormData(data) {
425
-            console.log(data,"data")
458
+            console.log(data, "data")
426 459
             // debugger
427 460
             let checedProjectArr = [];
428 461
             if (data.checkProjectItemList && data.checkProjectItemList?.length > 0) {
@@ -476,7 +509,7 @@ export default {
476 509
 
477 510
             }
478 511
             console.log(checedProjectArr, "checedProjectArr")
479
-        //    debugger
512
+            //    debugger
480 513
 
481 514
             this.formData = {
482 515
                 ...this.formData,
@@ -555,7 +588,7 @@ export default {
555 588
 
556 589
             // 还原checkProjectItemList结构到后端原始格式
557 590
             const restoredCheckProjectItemList = this.restoreOriginalCheckProjectItemList();
558
-            
591
+
559 592
             const payload = {
560 593
                 ...this.formData,
561 594
                 checkProjectItemList: restoredCheckProjectItemList,
@@ -580,22 +613,23 @@ export default {
580 613
 
581 614
         // 提交表单
582 615
         submitForm() {
616
+            debugger
583 617
             // 如果当前用户是责任人,校验问题人字段必填
584 618
             if (this.isResponsiblePerson) {
585
-                const hasEmptyProblemUser = this.formData.checkProjectItemList?.some(problem => 
619
+                const hasEmptyProblemUser = this.formData.checkProjectItemList?.some(problem =>
586 620
                     !problem.checkUserList || !problem.checkUserList.userId
587 621
                 );
588
-                
622
+
589 623
                 if (hasEmptyProblemUser) {
590
-                    uni.showToast({ 
591
-                        title: '请填写所有问题的责任人', 
624
+                    uni.showToast({
625
+                        title: '请填写所有问题的问题人',
592 626
                         icon: 'none',
593 627
                         duration: 3000
594 628
                     });
595 629
                     return;
596 630
                 }
597 631
             }
598
-            
632
+
599 633
             this.$refs.form.validate().then(res => {
600 634
                 uni.showLoading({ title: '提交中...', mask: true });
601 635