import { TreeTableComponent } from '@farris/ui-treetable'; import { FavoriteIcon, FAVORITE_FIELD_NAME } from '../lookup-displaytype'; import { LookupGridComponent } from '../lookup-grid.component'; import { cloneDeep } from 'lodash-es'; import { DataTableComponent } from '@farris/ui-datatable'; export class MultiSelectionManager { constructor(private ins: LookupGridComponent) {} onSelectedTableCellClick(e: any) { if (e.col.field === FAVORITE_FIELD_NAME) { e.event.stopPropagation(); const classList = e.event.target['classList']; if (classList.contains('f-lookup-unfavorite')) { const rid = e.row[this.ins.idField]; this.ins.lookupSelectionSer.unSelect(rid); // 取消选中 主列表 收藏列表 中的数据 if (this.ins.isTree()) { const tt = this.ins.lookupCmpMgr.getComponentInstance('treetable') as TreeTableComponent; tt.unCheckedNode(rid); tt.unSelectNode(rid); if (this.ins.useFavorite) { const _tt = this.ins.lookupCmpMgr.getComponentInstance('fav') as TreeTableComponent; if (_tt.data && _tt.data.length && _tt.findRowNode(rid)) { _tt.unCheckedNode(rid); _tt.unSelectNode(rid); } } } else { const dt = this.ins.lookupCmpMgr.getComponentInstance() as DataTableComponent; dt.unCheckRow(rid); if (this.ins.useFavorite) { const _dt = this.ins.lookupCmpMgr.getComponentInstance('fav') as DataTableComponent; if (_dt.data && _dt.data.length) { _dt.unCheckRow(rid); } } } } } } // 初始化已选数据列信息 initSelectedColumns() { let selectedColumns = []; if (this.ins.showSelected && !this.ins.singleSelect) { selectedColumns = cloneDeep(this.ins.gridOptions.columns); const favcol = selectedColumns.find(n => n.field === FAVORITE_FIELD_NAME); if (favcol) { favcol.formatter = () => { return FavoriteIcon.remove; }; } else { selectedColumns = selectedColumns.concat([ { field: FAVORITE_FIELD_NAME, width: 80, formatter: () => { return FavoriteIcon.remove; } } ]); } } return selectedColumns; } updateSelections(data) { if (Array.isArray(data)) { this.ins.lookupSelectionSer.updateSelections(data, true); } else { this.ins.lookupSelectionSer.select(data); } } remove(id: any) { if (id) { this.ins.lookupSelectionSer.unSelect(id); } } clear() { this.ins.lookupSelectionSer.clearSelections(); } save(rows: any) { if (this.ins.showSelected) { this.ins.personalConf.selections = rows; this.ins.personalConfigService.savePersonalConfig(this.ins.personalConf); } } loadData() { let items = this.ins.personalConf ? (this.ins.personalConf.selections || []) : []; if (!items.length) { items = this.ins.lookupSelectionSer.getSelections(); } this.ins.lookupSelectionSer.loadSelections(items); } }