66 lines
1.7 KiB
Swift
66 lines
1.7 KiB
Swift
//
|
|
// RemoveMemberViewModel.swift
|
|
// QuickLocation
|
|
//
|
|
// Created by 八条 on 2026/6/12.
|
|
//
|
|
|
|
import RxSwift
|
|
import RxCocoa
|
|
import RxDataSources
|
|
import ObjectMapper
|
|
|
|
typealias RemoveMemberListSectionModel = SectionModel<String, GroupMemberModel>
|
|
|
|
class RemoveMemberViewModel {
|
|
|
|
let groupId: String
|
|
|
|
var groupModel: GroupInfoModel?
|
|
|
|
struct Output {
|
|
var sectionedItems: Observable<[ReviewMemberListSectionModel]>
|
|
}
|
|
|
|
let output: Output
|
|
|
|
private var disposeBag = DisposeBag()
|
|
private let sectionedItems = PublishSubject<[ReviewMemberListSectionModel]>()
|
|
private var list: [GroupMemberModel] = []
|
|
|
|
var selectedMembers = BehaviorRelay<[String]>(value: [])
|
|
|
|
lazy var cellAction: Action<GroupMemberModel, Void> = { this in
|
|
return Action { model in
|
|
let memberId = model.user_id
|
|
guard !self.groupId.contains(memberId) else { return .empty() }
|
|
|
|
var current = this.selectedMembers.value
|
|
if let idx = current.firstIndex(of: memberId) {
|
|
current.remove(at: idx)
|
|
} else {
|
|
current.append(memberId)
|
|
}
|
|
this.selectedMembers.accept(current)
|
|
self.sectionedItems.onNext(self.list.mapSection())
|
|
return .empty()
|
|
}
|
|
}(self)
|
|
|
|
func isSelected(id: String) -> Bool {
|
|
(self.selectedMembers.value.first(where: { $0 == id }) != nil)
|
|
}
|
|
|
|
func loadData(_ list: [GroupMemberModel]) {
|
|
self.list = list
|
|
sectionedItems.onNext(list.mapSection())
|
|
}
|
|
|
|
init(groupId: String) {
|
|
self.groupId = groupId
|
|
output = Output(
|
|
sectionedItems: sectionedItems.asObservable()
|
|
)
|
|
}
|
|
}
|