// // RepeatViewModels.swift // FireBoltt // // Created by lemo on 2018/5/14. // Copyright © 2020年 ecell. All rights reserved. // import UIKit typealias CycleSelectedClosure = ((String) -> Void) class RepeatViewModels: ViewModel { var cycleStr: String = "0000000" var selects: [Bool] = [] var dataSource: [TableViewCellModel] = [] var dataVariable = BehaviorRelay<[SectionModel]>(value: []) let weekdays = [MultiLanguageKey_FB.mondayFB.localized, MultiLanguageKey_FB.tuesdayFB.localized, MultiLanguageKey_FB.wednesdayFB.localized, MultiLanguageKey_FB.thursdayFB.localized, MultiLanguageKey_FB.fridayFB.localized, MultiLanguageKey_FB.saturdayFB.localized, MultiLanguageKey_FB.sundayFB.localized] /// 更新回调 var updateCycle = PublishSubject() init(cycle: String) { super.init() loadData(cycle: cycle) } // 更新星期的选择状态 func updateDataSource(idx: Int) { selects[idx] = !selects[idx] let cycle = selects.map { $0 == false ? "0" : "1" }.joined() loadData(cycle: cycle) } func loadData(cycle: String) { dataSource.removeAll() cycleStr = cycle selects = cycleStr.indices.enumerated().map { cycleStr[$0.element] == "1" } weekdays.enumerated().forEach { (index, day) in let rightImg = selects[index] ? R.image.fb_icon_tick() : nil let cellModel = TableViewCellModel(title: day, isSwitch: false, description: nil, isArrows: false, isOn: false, image: nil, isBottomLine: index != (weekdays.count - 1), righeImg: rightImg) dataSource.append(cellModel) } let setMod = SectionModel.init(model: "", items: dataSource) dataVariable.accept([setMod]) } }