Просмотр исходного кода

机构和人员的选择支持清除

chenyidong месяцев назад: 3
Родитель
Сommit
ab99712f35
1 измененных файлов с 52 добавлено и 5 удалено
  1. 52 5
      components/ba-tree-picker/ba-tree-picker.vue

+ 52 - 5
components/ba-tree-picker/ba-tree-picker.vue

@@ -5,11 +5,18 @@
5
 		<view class="tree-cover" :class="{'show':showDialog}" @tap="_cancel"></view>
5
 		<view class="tree-cover" :class="{'show':showDialog}" @tap="_cancel"></view>
6
 		<view class="tree-dialog" :class="{'show':showDialog}">
6
 		<view class="tree-dialog" :class="{'show':showDialog}">
7
 			<view class="tree-bar">
7
 			<view class="tree-bar">
8
-				<view class="tree-bar-cancel" :style="{'color':cancelColor}" hover-class="hover-c" @tap="_cancel">取消
8
+				<view class="tree-bar-left">
9
+					<view class="tree-bar-cancel" :style="{'color':cancelColor}" hover-class="hover-c" @tap="_cancel">取消
10
+					</view>
9
 				</view>
11
 				</view>
10
 				<view class="tree-bar-title" :style="{'color':titleColor}">{{title}}</view>
12
 				<view class="tree-bar-title" :style="{'color':titleColor}">{{title}}</view>
11
-				<view class="tree-bar-confirm" :style="{'color':confirmColor}" hover-class="hover-c" @tap="_confirm">
12
-					{{multiple?'确定':''}}
13
+				<view class="tree-bar-right">
14
+					<view v-if="showClear" class="tree-bar-clear" :style="{'color':cancelColor}" hover-class="hover-c" @tap="_clear">
15
+						清除
16
+					</view>
17
+					<view class="tree-bar-confirm" :style="{'color':confirmColor}" hover-class="hover-c" @tap="_confirm">
18
+						{{multiple?'确定':''}}
19
+					</view>
13
 				</view>
20
 				</view>
14
 			</view>
21
 			</view>
15
 			<view class="tree-view">
22
 			<view class="tree-view">
@@ -64,7 +71,7 @@
64
 
71
 
65
 <script>
72
 <script>
66
 	export default {
73
 	export default {
67
-		emits: ['select-change'],
74
+		emits: ['select-change', 'clear'],
68
 		name: "ba-tree-picker",
75
 		name: "ba-tree-picker",
69
 		props: {
76
 		props: {
70
 			personNames : {
77
 			personNames : {
@@ -129,6 +136,10 @@
129
 				type: Boolean,
136
 				type: Boolean,
130
 				default: false
137
 				default: false
131
 			},
138
 			},
139
+			showClear: { // 是否显示清除按钮
140
+				type: Boolean,
141
+				default: true
142
+			},
132
 		},
143
 		},
133
 		data() {
144
 		data() {
134
 			return {
145
 			return {
@@ -167,6 +178,23 @@
167
 				this._hide()
178
 				this._hide()
168
 				this.$emit("cancel", '');
179
 				this.$emit("cancel", '');
169
 			},
180
 			},
181
+			_clear() {
182
+				// 清除所有选中状态
183
+				this.treeList.forEach((item, index) => {
184
+					this.treeList[index].checkStatus = 0;
185
+					this.treeList[index].childCheckCount = 0;
186
+					this.treeList[index].childCheckPCount = 0;
187
+				});
188
+				
189
+				// 关闭对话框
190
+				this._hide();
191
+				
192
+				// 触发选择变更事件,返回空值
193
+				this.$emit("select-change", [], []);
194
+				
195
+				// 触发清除事件
196
+				this.$emit("clear", '');
197
+			},
170
 			_confirm() { //多选
198
 			_confirm() { //多选
171
 				let selectedList = []; //如果子集全部选中,只返回父级 id
199
 				let selectedList = []; //如果子集全部选中,只返回父级 id
172
 				let selectedNames = [];
200
 				let selectedNames = [];
@@ -508,12 +536,31 @@
508
 		line-height: 1;
536
 		line-height: 1;
509
 	}
537
 	}
510
 
538
 
539
+	.tree-bar-left {
540
+		display: flex;
541
+		align-items: center;
542
+	}
543
+
544
+	.tree-bar-right {
545
+		display: flex;
546
+		align-items: center;
547
+		gap: 20rpx;
548
+	}
549
+
511
 	.tree-bar-confirm {
550
 	.tree-bar-confirm {
512
 		color: #0055ff;
551
 		color: #0055ff;
513
 		padding: 15rpx;
552
 		padding: 15rpx;
514
 	}
553
 	}
515
 
554
 
516
-	.tree-bar-title {}
555
+	.tree-bar-clear {
556
+		color: #757575;
557
+		padding: 15rpx;
558
+	}
559
+
560
+	.tree-bar-title {
561
+		flex: 1;
562
+		text-align: center;
563
+	}
517
 
564
 
518
 	.tree-bar-cancel {
565
 	.tree-bar-cancel {
519
 		color: #757575;
566
 		color: #757575;