// // GroupMemberListVC.swift // QuickLocation // // Created by 八条 on 2026/6/29. // import UIKit import RxSwift import RxCocoa import RxDataSources final class GroupMemberListVC: BaseViewController { fileprivate var rootView: GroupMemberListView! private let viewModel: GroupMemberListVM override func loadView() { rootView = GroupMemberListView(frame: UIScreen.main.bounds) view = rootView } override func viewDidLoad() { super.viewDidLoad() bindViewModel() requestGroupInfo() } private func bindViewModel() { rootView.tableView.rx.setDelegate(rootView) .disposed(by: disposeBag) viewModel.output.directoryItems .subscribe(onNext: { [weak self] sections in self?.rootView.updateSectionTitles(sections.map(\.title)) }) .disposed(by: disposeBag) viewModel.output.directoryItems .bind(to: rootView.tableView.rx.items(dataSource: dataSource)) .disposed(by: disposeBag) rootView.searchField.rx.text.orEmpty .distinctUntilChanged() .subscribe(onNext: { [weak self] keyword in self?.rootView.updateSearchPlaceholder(isHidden: !keyword.isEmpty) self?.viewModel.updateSearchKeyword(keyword) }) .disposed(by: disposeBag) rootView.searchField.rx.controlEvent(.editingDidEndOnExit) .subscribe(onNext: { [weak self] in self?.rootView.searchField.resignFirstResponder() }) .disposed(by: disposeBag) } private lazy var dataSource: RxTableViewSectionedReloadDataSource = { RxTableViewSectionedReloadDataSource( configureCell: { dataSource, tableView, indexPath, member in let cell: GroupMemberDirectoryCell = tableView.dequeueReusableCell(for: indexPath) let count = dataSource.sectionModels[indexPath.section].items.count cell.configure(member, showsSeparator: indexPath.row < count - 1, roundsTopCorners: indexPath.row == 0, roundsBottomCorners: indexPath.row == count - 1) return cell }, titleForHeaderInSection: { dataSource, section in dataSource.sectionModels[section].title } ) }() private func requestGroupInfo() { DLToast.showLoading() GroupService.groupUsers(groupKey: viewModel.groupKey) .subscribe(onNext: { [weak self] response in guard let self else { return } DLToast.dismiss() guard response.isValid(for: self.viewModel.groupKey), let group = response.model else { DLToast.showError(text: response.message ?? "获取圈子成员失败") return } self.viewModel.loadData(group: group, members: response.list) }, onError: { error in DLToast.dismiss() DLToast.showError(text: error.localizedDescription) }) .disposed(by: disposeBag) } init(groupKey: String) { viewModel = GroupMemberListVM(groupKey: groupKey) super.init(nibName: nil, bundle: nil) } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } }