SelectTaAccountInfoViewController.swift 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // SelectTaAccountInfoViewController.swift
  3. // MTP2_iOS
  4. //
  5. // Created by Muchinfo on 2021/2/4.
  6. // Copyright © 2021 Muchinfo. All rights reserved.
  7. //
  8. import UIKit
  9. /// 账户切换视图容器控制类
  10. class SelectTaAccountInfoViewController: BaseViewController {
  11. // MARK: - 属性列表
  12. /// tableView
  13. @IBOutlet weak var tableView: UITableView! {
  14. didSet {
  15. /// 刷新列表数据
  16. tableView.reloadData()
  17. }
  18. }
  19. /// 高度约束
  20. @IBOutlet weak var heightLayoutConstraint: NSLayoutConstraint! {
  21. didSet {
  22. /// 控制高度约束
  23. heightLayoutConstraint.constant = CGFloat(list.count >= 4 ? 4 : list.count)*60.0+44.0
  24. }
  25. }
  26. /// 资金账户列表
  27. var list: [MoTaAccountInfo] {
  28. get {
  29. return MTP2BusinessCore.shared.accountManager?.taAccountInfos ?? []
  30. }
  31. }
  32. // MARK: - 生命周期
  33. override func viewDidLoad() {
  34. super.viewDidLoad()
  35. // Do any additional setup after loading the view.
  36. }
  37. // MARK: - 交互相关
  38. /// onButtonPressed
  39. /// - Parameter sender: sender
  40. @IBAction fileprivate func onButtonPressed(_ sender: Any) {
  41. self.dismiss(animated: true, completion: {})
  42. }
  43. }
  44. extension SelectTaAccountInfoViewController: UITableViewDelegate, UITableViewDataSource {
  45. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  46. return list.count
  47. }
  48. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  49. let cell = tableView.dequeueReusableCell(withIdentifier: "SelectTaAccountInfo_Cell", for: indexPath) as! SelectTaAccountInfoCell
  50. cell.model = list[indexPath.row]
  51. return cell
  52. }
  53. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  54. /// 防止重复点击
  55. if MTP2BusinessCore.shared.getCurrentAccountID() == list[indexPath.row].accountid {
  56. /// 返回上层视图
  57. self.dismiss(animated: true, completion: {})
  58. return
  59. }
  60. /// 设置当前账户
  61. MTP2BusinessCore.shared.setCurrentTaAccountInfo(accountid: list[indexPath.row].accountid)
  62. /// 返回上层视图
  63. self.dismiss(animated: true, completion: {})
  64. /// 执行回调
  65. if let bk = popBlock { bk(list[indexPath.row]) }
  66. }
  67. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  68. return 60.0
  69. }
  70. }
  71. class SelectTaAccountInfoCell: BaseTableViewCell<MoTaAccountInfo> {
  72. /// 名称简写
  73. @IBOutlet weak var name: UILabel! {
  74. didSet {
  75. name.backgroundColor = .fromHex(rgbValue: 0xFF5C6F)
  76. name.layer.cornerRadius = 15
  77. name.layer.masksToBounds = true
  78. }
  79. }
  80. /// 账户名称
  81. @IBOutlet weak var accountName: UILabel!
  82. /// 资金账号
  83. @IBOutlet weak var accountNo: UILabel!
  84. /// 是否选中
  85. @IBOutlet weak var check: UIImageView!
  86. /// 实体
  87. override var model: MoTaAccountInfo? {
  88. didSet {
  89. /// 异常
  90. guard let obj = model else { return }
  91. /// 资金账号
  92. accountNo.text = "\(obj.accountid)"
  93. /// 账户名称
  94. if obj.accountname != "" {
  95. accountName.text = obj.accountname
  96. } else if let userinfo = MTP2BusinessCore.shared.accountManager?.loginQuery?.userInfo {
  97. accountName.text = userinfo.customername
  98. }
  99. /// 名称简写
  100. name.text = obj.ismain == 1 ? "母" : "子"
  101. /// 选中当前
  102. check.image = MTP2BusinessCore.shared.getCurrentAccountID() == obj.accountid ? UIImage(named: "select_check") : nil
  103. }
  104. }
  105. }