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.
54 lines
1.8 KiB
54 lines
1.8 KiB
![]()
2 years ago
|
//
|
||
|
// NewAddAlarmViewModel.swift
|
||
|
// Lookfit
|
||
|
//
|
||
|
// Created by lemo on 2018/8/6.
|
||
|
// Copyright © 2020年 ecell. All rights reserved.
|
||
|
//
|
||
|
|
||
|
import UIKit
|
||
|
|
||
|
class NewAddAlarmViewModel: ViewModel {
|
||
|
|
||
|
var dataVariable = BehaviorRelay<[MultipleSectionModel]>(value: [])
|
||
|
var dataSource: [MultipleSectionModel] = []
|
||
|
|
||
|
/// 当前新增/编辑的闹钟
|
||
|
var alarmModel: AlarmModel = AlarmModel()
|
||
|
/// 当前闹钟数组
|
||
|
var alarms: [AlarmModel] = []
|
||
|
/// 是否为添加闹钟
|
||
|
var isAdd: Bool = true
|
||
|
/// 编辑的下标
|
||
|
var editIndex: Int = 0
|
||
|
|
||
|
init(alarmModel: AlarmModel = AlarmModel(), isAdd: Bool = true, editIndex: Int = 0) {
|
||
|
super.init()
|
||
|
self.alarmModel = alarmModel
|
||
|
self.isAdd = isAdd
|
||
|
self.editIndex = editIndex
|
||
|
if let alarms = GlobalDeviceProfileModel.shareInstance.alarmModels {
|
||
|
self.alarms = alarms
|
||
|
}
|
||
|
loadData(model: alarmModel)
|
||
|
}
|
||
|
|
||
|
func loadData(model: AlarmModel) {
|
||
|
dataSource.removeAll()
|
||
|
var timeStr: String? = nil
|
||
|
if let hour = model.Hour, let minutes = model.Minutes {
|
||
|
timeStr = "\(hour):\(minutes)"
|
||
|
}
|
||
|
let mod1 = MultipleSectionModel.SinglePickerSection(title: "", items: [SectionItem.SinglePicker(title: nil, selectedItem: timeStr)])
|
||
|
let cycle = GlobalDeviceProfileModel.cycle(cycleStr: model.Cycle)
|
||
|
let cellModel = TableViewCellModel(title: MultiLanguageKey.repeatCycle.localized, isSwitch: false, description: cycle, isArrows: true, isOn: false, image: nil, isBottomLine: false)
|
||
|
let mod2 = MultipleSectionModel.SettingSection(title: "", items: [.TableViewCellModel(cellModel: cellModel)])
|
||
|
dataSource.append(mod1)
|
||
|
dataSource.append(mod2)
|
||
|
dataVariable.accept(dataSource)
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|