123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- //
- // SwitchAccountViewController.swift
- // JiaPeiManage
- //
- // Created by Ning.ge on 2023/7/28.
- //
- import UIKit
- import RxSwift
- import RxCocoa
- final class SwitchAccountViewController: BaseTableViewController {
-
- let cellIdentifier:String = "_SwitchAccountCellID"
- // MARK: UI let
- let statusBar = UIView().then {
- $0.backgroundColor = UIColor.db_theme
- }
-
- let navBar = MeTraineeNavBar.loadFromNib().then {
- $0.search_layout_right.constant = 15.f
- }
-
- //edit
- var edit:Bool = false
- //切换viewmodel
- let switchAccountViewModel = SwitchAccountViewModel()
-
- override func setupConstraints() {
-
- statusBar.snp.makeConstraints { (make) in
- make.left.right.top.equalToSuperview()
- make.height.equalTo(Metric.statusBarHeight)
- }
-
- navBar.snp.remakeConstraints { (make) in
- make.left.right.equalToSuperview()
- make.height.equalTo(Metric.navBarHeight)
- make.top.equalTo(statusBar.snp.bottom)
- }
-
- self.tableView.snp.remakeConstraints { make in
- make.top.equalTo(navBar.snp.bottom)
- make.left.right.bottom.equalTo(self.view)
- }
- self.loadViewIfNeeded()
- }
-
- override func viewDidLoad() {
- super.viewDidLoad()
- setupUI()
- biandView()
- }
-
- // MARK: 私有方法
- func setupUI(){
- self.view.addSubview(navBar)
- self.view.addSubview(statusBar)
- self.navBar.title_label.text = "个人中心"
- self.view.backgroundColor = .db_theme
- self.navBar.back_button.addTarget(self, action: #selector(actionBackdo), for: .touchUpInside)
- self.navBar.search_button.setImage(nil, for: .normal)
- self.navBar.search_button.setTitle("编辑", for: .normal)
- self.navBar.search_button.titleLabel?.font = NYFont.SysFont.sys_14
- self.switchAccountViewModel.vc = self
-
- }
- //绑定-rx
- func biandView(){
-
- tableView.delegate = self.switchAccountViewModel
- tableView.separatorStyle = .none //去除分割线
- tableView.register(UINib(nibName: "SwitchAccountCell", bundle: nil), forCellReuseIdentifier: cellIdentifier)
- tableView.rowHeight = 96.f
- tableView.alwaysBounceVertical = false
- tableView.bounces = false
- tableView.contentInset = UIEdgeInsets(top: 20, left: 0, bottom: 20, right: 0)
- self.isEmptyDisplay = true
- self.hideLoadAnimation()
- //编辑事件
- self.navBar.search_button.rx.tap.subscribe ({ [unowned self] (_) in
- self.edit = !self.edit
- let title = self.edit ? "完成":"编辑"
- self.navBar.search_button.setTitle(title, for: .normal)
- self.switchAccountViewModel.getAccountsRead()
- }).disposed(by: disposeBag)
- //RX 绑定
- self.switchAccountViewModel.items
- .bind(to: tableView.rx.items(cellIdentifier: cellIdentifier,cellType:SwitchAccountCell.self)) {[unowned self] (row, model, cell) in
- cell.sacontentView.backgroundColor = ((row%2) != 0) ? UIColor("#113357") : UIColor("#0B2B4D")
- cell.setIsEdit(edit: self.edit)
- cell.setUserinfo(userinfo: model)
- cell.index = row
- cell.viewModel = self.switchAccountViewModel
- }
- .disposed(by: disposeBag)
- // 单独处理删除按钮的点击事件,不与 tableView.rx.items 的绑定混合
- self.switchAccountViewModel.deleteButtonTapped
- .subscribe(onNext: { [unowned self] row in
- // 在这里处理点击事件,row 表示点击的单元格的索引
- self.switchAccountViewModel.deleteAccount(row: row)
- })
- .disposed(by: disposeBag)
- // tableView点击事件
- tableView.rx.itemSelected.throttle(.seconds(1), scheduler: MainScheduler.instance)
- .subscribe(onNext: { [unowned self]indexPath in
- print("点击\(indexPath)行")
- if !self.edit{
- self.switchAccountViewModel.switchAccount(row: indexPath.row)
- }
- }).disposed(by: disposeBag)
- self.switchAccountViewModel.getAccountsRead()
- }
-
- }
|