|
|
|
//
|
|
|
|
// UserInfoViewModel.swift
|
|
|
|
// HPlusFit
|
|
|
|
//
|
|
|
|
// Created by lemo. on 2019/9/7.
|
|
|
|
// Copyright © 2019 lemo. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
class UserInfoViewModel: ViewModel {
|
|
|
|
|
|
|
|
var relay = BehaviorRelay(value: [SectionModel<String,TableViewCellModel>]())
|
|
|
|
|
|
|
|
override init() {
|
|
|
|
super.init()
|
|
|
|
loadFuncationList()
|
|
|
|
}
|
|
|
|
|
|
|
|
func loadFuncationList() {
|
|
|
|
guard let userInfo = UserDefaultsManager.getUserInfo() else { return }
|
|
|
|
// 功能列表
|
|
|
|
let funcationList: [UserInfoType] = [.head, .gender, .nickname, .height, .weight, .birthday]
|
|
|
|
let gender = userInfo.gender ? MultiLanguageKey.femaleFB.localized : MultiLanguageKey.maleFB.localized
|
|
|
|
let descriptions = ["", gender, userInfo.nickname, "\(userInfo.heightCM) cm", "\(userInfo.weightKG) kg", userInfo.birthday]
|
|
|
|
var items: [TableViewCellModel] = []
|
|
|
|
funcationList.enumerated().forEach { (offset, type) in
|
|
|
|
let isHiddenBottomLine = offset == funcationList.count - 1
|
|
|
|
let rightIcon = offset == 0 ? userInfo.getAvatarImg : nil
|
|
|
|
let cellModel = TableViewCellModel(title: type.title, isSwitch: false, description: descriptions[offset], isArrows: true, isOn: false, image: nil, isBottomLine: !isHiddenBottomLine, righeImg: rightIcon, userInfoType: type)
|
|
|
|
items.append(cellModel)
|
|
|
|
}
|
|
|
|
relay.accept([SectionModel(model: "", items: items)])
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
enum UserInfoType {
|
|
|
|
case head, gender, nickname, height, weight, birthday
|
|
|
|
|
|
|
|
var title: String {
|
|
|
|
switch self {
|
|
|
|
case .head: return MultiLanguageKey.headFB.localized
|
|
|
|
case .gender: return MultiLanguageKey.genderFB.localized
|
|
|
|
case .nickname: return MultiLanguageKey.nicknameFB.localized
|
|
|
|
case .height: return MultiLanguageKey.heightFB.localized
|
|
|
|
case .weight: return MultiLanguageKey.weightFB.localized
|
|
|
|
case .birthday: return MultiLanguageKey.birthdayFB.localized
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|