| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- //
- // SelectTaAccountInfoViewController.swift
- // MTP2_iOS
- //
- // Created by Muchinfo on 2021/2/4.
- // Copyright © 2021 Muchinfo. All rights reserved.
- //
- import UIKit
- /// 账户切换视图容器控制类
- class SelectTaAccountInfoViewController: BaseViewController {
-
- // MARK: - 属性列表
- /// tableView
- @IBOutlet weak var tableView: UITableView! {
- didSet {
- /// 刷新列表数据
- tableView.reloadData()
- }
- }
- /// 高度约束
- @IBOutlet weak var heightLayoutConstraint: NSLayoutConstraint! {
- didSet {
- /// 控制高度约束
- heightLayoutConstraint.constant = CGFloat(list.count >= 4 ? 4 : list.count)*60.0+44.0
- }
- }
-
- /// 资金账户列表
- var list: [MoTaAccountInfo] {
- get {
- return MTP2BusinessCore.shared.accountManager?.taAccountInfos ?? []
- }
- }
- // MARK: - 生命周期
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view.
- }
-
- // MARK: - 交互相关
- /// onButtonPressed
- /// - Parameter sender: sender
- @IBAction fileprivate func onButtonPressed(_ sender: Any) {
- self.dismiss(animated: true, completion: {})
- }
- }
- extension SelectTaAccountInfoViewController: UITableViewDelegate, UITableViewDataSource {
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return list.count
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: "SelectTaAccountInfo_Cell", for: indexPath) as! SelectTaAccountInfoCell
- cell.model = list[indexPath.row]
- return cell
- }
-
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- /// 防止重复点击
- if MTP2BusinessCore.shared.getCurrentAccountID() == list[indexPath.row].accountid {
- /// 返回上层视图
- self.dismiss(animated: true, completion: {})
- return
- }
- /// 设置当前账户
- MTP2BusinessCore.shared.setCurrentTaAccountInfo(accountid: list[indexPath.row].accountid)
- /// 返回上层视图
- self.dismiss(animated: true, completion: {})
- /// 执行回调
- if let bk = popBlock { bk(list[indexPath.row]) }
- }
-
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- return 60.0
- }
- }
- class SelectTaAccountInfoCell: BaseTableViewCell<MoTaAccountInfo> {
- /// 名称简写
- @IBOutlet weak var name: UILabel! {
- didSet {
- name.backgroundColor = .fromHex(rgbValue: 0xFF5C6F)
- name.layer.cornerRadius = 15
- name.layer.masksToBounds = true
- }
- }
- /// 账户名称
- @IBOutlet weak var accountName: UILabel!
- /// 资金账号
- @IBOutlet weak var accountNo: UILabel!
- /// 是否选中
- @IBOutlet weak var check: UIImageView!
-
- /// 实体
- override var model: MoTaAccountInfo? {
- didSet {
- /// 异常
- guard let obj = model else { return }
- /// 资金账号
- accountNo.text = "\(obj.accountid)"
- /// 账户名称
- if obj.accountname != "" {
- accountName.text = obj.accountname
- } else if let userinfo = MTP2BusinessCore.shared.accountManager?.loginQuery?.userInfo {
- accountName.text = userinfo.customername
- }
- /// 名称简写
- name.text = obj.ismain == 1 ? "母" : "子"
- /// 选中当前
- check.image = MTP2BusinessCore.shared.getCurrentAccountID() == obj.accountid ? UIImage(named: "select_check") : nil
- }
- }
- }
|