You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.8 KiB
49 lines
1.8 KiB
// |
|
// RepeatViewModels.swift |
|
// Lookfit |
|
// |
|
// 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<String, TableViewCellModel>]>(value: []) |
|
let weekdays = [MultiLanguageKey.monday.localized, MultiLanguageKey.tuesday.localized, MultiLanguageKey.wednesday.localized, MultiLanguageKey.thursday.localized, MultiLanguageKey.friday.localized, MultiLanguageKey.saturday.localized, MultiLanguageKey.sunday.localized] |
|
|
|
/// 更新回调 |
|
var updateCycle = PublishSubject<String>() |
|
|
|
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.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<String, TableViewCellModel>.init(model: "", items: dataSource) |
|
dataVariable.accept([setMod]) |
|
} |
|
|
|
}
|
|
|