|
@@ -3,7 +3,7 @@ import { NZ_MODAL_DATA } from 'ng-zorro-antd/modal';
|
|
|
import { horizontalInOut } from '../../../common.animation';
|
|
|
import { KnowledgeService } from '../../../services/knowledge.service';
|
|
|
import { CommonNzModule } from './../../../common.nz.module';
|
|
|
-import { RiskItemVisualComponent } from './../risk-item-visual/risk-item-visual.component';
|
|
|
+import { RiskItemsVisualClassifyComponent } from './../risk-items-visual-classify/risk-items-visual-classify.component';
|
|
|
|
|
|
export interface RiskItemPickerModalData {
|
|
|
title: string;
|
|
@@ -18,7 +18,7 @@ export interface RiskItemPickerModalData {
|
|
|
@Component({
|
|
|
selector: 'risk-item-picker-modal',
|
|
|
standalone: true,
|
|
|
- imports: [CommonNzModule, RiskItemVisualComponent],
|
|
|
+ imports: [CommonNzModule, RiskItemsVisualClassifyComponent],
|
|
|
templateUrl: './modal.component.html',
|
|
|
styleUrl: './modal.component.less',
|
|
|
animations: [horizontalInOut],
|
|
@@ -63,23 +63,77 @@ export class RiskItemPickerModalComponent {
|
|
|
onClear() {
|
|
|
this.selectedItems = [];
|
|
|
this.nzModalData.onChange([]);
|
|
|
+ this.allChecked = false;
|
|
|
+ this.indeterminate = false;
|
|
|
}
|
|
|
onItemChange(value: number, boolean = true) {
|
|
|
const item = this.items.find(p => p.id === value);
|
|
|
if (item) {
|
|
|
if (boolean) {
|
|
|
- this.selectedItems.unshift(item);
|
|
|
+ this.selectedItems = [item, ...this.selectedItems];
|
|
|
} else {
|
|
|
this.selectedItems = this.selectedItems.filter(p => p.id !== value);
|
|
|
}
|
|
|
this.nzModalData.onChange(this.selectedItems.map(p => p.id));
|
|
|
}
|
|
|
+ this.updateAllCheckedStatus();
|
|
|
}
|
|
|
|
|
|
onRemove(itemId: number) {
|
|
|
this.selectedItems = this.selectedItems.filter(p => p.id !== itemId);
|
|
|
+ this.updateAllCheckedStatus();
|
|
|
this.nzModalData.onChange(this.selectedItems.map(p => p.id));
|
|
|
}
|
|
|
+
|
|
|
+ allChecked = false;
|
|
|
+ indeterminate = false;
|
|
|
+
|
|
|
+ get isAllCheckboxDisabled(): boolean {
|
|
|
+ if (this.filteredItems.length === 0) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (!this.category && !this.type && !this.searchText) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ updateAllChecked(): void {
|
|
|
+ if (this.isAllCheckboxDisabled) return;
|
|
|
+
|
|
|
+ this.indeterminate = false;
|
|
|
+ if (this.allChecked) {
|
|
|
+ this.filteredItems.forEach(item => {
|
|
|
+ if (!this.selectedItems.includes(item)) {
|
|
|
+ this.selectedItems = [...this.selectedItems, item];
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.filteredItems.forEach(item => {
|
|
|
+ if (this.selectedItems.includes(item)) {
|
|
|
+ this.selectedItems = this.selectedItems.filter(p => p.id !== item.id);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ this.nzModalData.onChange(this.selectedItems.map(p => p.id));
|
|
|
+ }
|
|
|
+
|
|
|
+ updateAllCheckedStatus(): void {
|
|
|
+ if (this.filteredItems.length === 0) {
|
|
|
+ this.allChecked = false;
|
|
|
+ this.indeterminate = false;
|
|
|
+ } else if (this.filteredItems.every(item => this.selectedItems.find(p => p.id === item.id))) {
|
|
|
+ this.allChecked = true;
|
|
|
+ this.indeterminate = false;
|
|
|
+ } else if (this.filteredItems.some(item => this.selectedItems.find(p => p.id === item.id))) {
|
|
|
+ this.allChecked = false;
|
|
|
+ this.indeterminate = true;
|
|
|
+ } else {
|
|
|
+ this.allChecked = false;
|
|
|
+ this.indeterminate = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
get title() {
|
|
|
return this.nzModalData.title || '选择风险条目';
|
|
|
}
|
|
@@ -98,6 +152,7 @@ export class RiskItemPickerModalComponent {
|
|
|
result = result.filter(p => p.title.includes(this.searchText));
|
|
|
}
|
|
|
this.filteredItems = result;
|
|
|
+ this.updateAllCheckedStatus();
|
|
|
}
|
|
|
get types() {
|
|
|
return this.nzModalData.types;
|