// // AccountManagerViewController.swift // MTP2_iOS // // Created by Muchinfo on 2021/3/26. // Copyright © 2021 Muchinfo. All rights reserved. // import UIKit import GTMRefresh import WHToast import JXSegmentedView import IBAnimatable import SwiftyAttributes import NVActivityIndicatorView /// 账户管理主视图容器控制类 class AccountManagerViewController: BaseViewController { // MARK: - 属性列表 /// 类目 @IBOutlet weak var segmentedView: JXSegmentedView! { didSet { segmentedView.dataSource = dataSource segmentedView.indicators = [indicator] segmentedView.delegate = self } } /// 数据列表 @IBOutlet weak var tableView: UITableView! /// 登录账户信息 var objs: [Any] = [] { didSet { /// noDataButton noDataButton.isHidden = objs.count != 0 /// 刷新列表 self.tableView.reloadData() } } /// 选中的位置 var selectedIndex: (row: Int, isExpland: Bool)? { didSet { if let index = selectedIndex { /// 刷新某一行 tableView.reloadRows(at: [IndexPath(row: index.row, section: 0)], with: .automatic) } } } /// CellIdentifier let CellIdentifier = "AccountManager_Cell" /// 权限功能 var roleTitles: [String] { get { var titles: [String] = [] /// 权限控制 guard let commonManager = MTP2BusinessCore.shared.commonManager else { return titles } if commonManager.containMenu(key: "client_accountmanage_business") { titles.append("业务账户") } if commonManager.containMenu(key: "client_accountmanage_trade") { titles.append("交易账户") } if commonManager.containMenu(key: "client_accountmanage_manage") { titles.append("管理账户") } if commonManager.containMenu(key: "client_accountmanage_ta") { titles.append("期货账户") } return titles } } // MARK: - 生命周期 override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. /// addLoadingView addLoadingView() /// titles dataSource.titles = roleTitles segmentedView.reloadData() /// 请求数据 if roleTitles.count != 0 { /// 添加下拉刷新 tableView.gtm_addRefreshHeaderView(refreshHeader: DefaultGTMRefreshHeader()) { switch self.roleTitles[self.segmentedView.selectedIndex] { case "业务账户": self.queryAccMgrLoginUser(1) case "交易账户": self.queryAccMgrLoginUser(2) case "管理账户": self.queryAccMgrLoginUser(3) default: /// 期货账户 self.queryAccMgrTaaccount() } } /// 默认选中第一个 segmentedView.defaultSelectedIndex = 0 segmentedView.delegate?.segmentedView(segmentedView, didSelectedItemAt: 0) } } // MARK: - 接口查询 /// 查询账户管理登录账号 /// - Parameter querytype: 查询类型 1-业务账户 2-交易账户 3-管理账户 fileprivate func queryAccMgrLoginUser(_ querytype: Int) { /// 异常 guard let accountManager = MTP2BusinessCore.shared.accountManager else { return } /// startAnimating _anim?.startAnimating() /// 查询登录账户信息 accountManager.queryAccMgrLoginUser(querytype: querytype, callback: { isSuccess, er, users in DispatchQueue.main.async { /// stopAnimating self._anim?.stopAnimating() /// endRefreshing self.tableView.endRefreshing() /// 查询失败 if !isSuccess { self.objs = [] WHToast.showMessage("数据查询失败,原因:\(er?.retMsg ?? "请求超时")", duration: ToastTimer, finishHandler: {}) return } /// 过滤掉注销账户 var array: [MoMgrLoginUser] = [] users?.forEach({ obj in var u = MoMgrLoginUser() u.roleid = obj.roleid u.rolename = obj.rolename u.accountstatus = obj.accountstatus u.mobile = obj.mobile u.querytype = obj.querytype u.userlist = obj.userlist.filter({$0.loginstatus != .invalid}) array.append(u) }) /// 数据赋值 self.objs = array } }) } /// 查询期货账户 fileprivate func queryAccMgrTaaccount() { /// 异常 guard let accountManager = MTP2BusinessCore.shared.accountManager else { return } /// startAnimating _anim?.startAnimating() /// queryAccMgrTaaccount accountManager.queryAccMgrTaaccount { (isSuccess, er, tas) in DispatchQueue.main.async { /// stopAnimating self._anim?.stopAnimating() /// endRefreshing self.tableView.endRefreshing() /// 查询失败 if !isSuccess { self.objs = [] WHToast.showMessage("数据查询失败,原因:\(er?.retMsg ?? "请求超时")", duration: ToastTimer, finishHandler: {}) return } /// 数据赋值 self.objs = tas ?? [] } } } /// 登录账户操作请求方法 /// - Parameters: /// - obj: 数据 /// - type: 操作类型-1:新增 2:修改 3:新增管理员 4:修改管理员 5:冻结 6:解冻 7:注销 8:恢复 9:重置密码 fileprivate func doLoginAccountOperator(_ obj: MoSubMgrLoginUser, _ type: Int) { /// 异常 guard let accountManager = MTP2BusinessCore.shared.accountManager else { return } /// startAnimating NVActivityIndicatorPresenter.sharedInstance.startAnimating(animData("请求中...")) /// 发送请求 accountManager.requestLoginaccountOperate(operatetype: type, userid: obj.userid, loginid: obj.loginid, logincode: nil, accountname: nil, password: nil, mobile: nil, roleids: nil, logintaaccounts: nil) { (isSuccess, er) in DispatchQueue.main.async { /// stopAnimating NVActivityIndicatorPresenter.sharedInstance.stopAnimating() /// 请求失败 if !isSuccess { WHToast.showMessage("请求失败,原因:\(er?.retMsg ?? "请求超时")", duration: ToastTimer, finishHandler: {}) return } /// 请求成功 WHToast.showSuccess(withMessage: "请求成功", duration: ToastTimer, finishHandler: { /// 重新请求数据 self.tableView.triggerRefreshing() }) } } } /// 期货账户子账户操作 /// - Parameters: /// - obj: 子账户 /// - type: 操作类型 fileprivate func doFutureAccountOperator(_ obj: MoSubMgrTaaccount, _ type: Int) { /// 异常 guard let accountManager = MTP2BusinessCore.shared.accountManager else { return } /// startAnimating NVActivityIndicatorPresenter.sharedInstance.startAnimating(animData("请求中...")) /// 期货账户注销操作 accountManager.requestTaaccountOperate(accountid: obj.accountid, tradestatus: type) { (isSuccess, er) in DispatchQueue.main.async { /// stopAnimating NVActivityIndicatorPresenter.sharedInstance.stopAnimating() /// 请求失败 if !isSuccess { WHToast.showMessage("请求失败,原因:\(er?.retMsg ?? "请求超时")", duration: ToastTimer, finishHandler: {}) return } /// 请求成功 WHToast.showSuccess(withMessage: "请求成功", duration: ToastTimer, finishHandler: { /// 重新请求数据 self.tableView.triggerRefreshing() }) } } } // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { // Get the new view controller using segue.destination. // Pass the selected object to the new view controller. switch segue.identifier { case "ShowNewFuturesAccount": /// 新增期货主账户 if let n = segue.destination as? NewFuturesAccountViewController, let obj = sender as? (Any?, Any?) { n.popBlock = { (_ takeInfo: Any?) in /// 刷新数据 self.tableView.triggerRefreshing() } n.moMgrTaaccount = obj.0 as? MoMgrTaaccount n.operatorType = obj.1 as! OperatorType } case "ShowNewSubFutureAccount": /// 增加期货子账户 if let n = segue.destination as? NewSubFutureAccountViewController, let obj = sender as? (Any?, Any?) { if let type = obj.1 as? OperatorType { if type == .update || type == .detail { /// 修改 /// 主账户信息 n.moMgrTaaccount = (obj.0 as? (Any, Any))?.0 as? MoMgrTaaccount /// 子账户信息 n.subMgrTaaccount = (obj.0 as? (Any, Any))?.1 as? MoSubMgrTaaccount } else { n.moMgrTaaccount = obj.0 as? MoMgrTaaccount } n.operatorType = type } n.popBlock = { (_ takeInfo: Any?) in /// 刷新数据 self.tableView.triggerRefreshing() } } case "ShowNewAdministratorAccount": /// 新增管理员账户 if let n = segue.destination as? NewAdministratorAccountViewController, let obj = sender as? (Any, OperatorType) { n.popBlock = { (_ takeInfo: Any?) in /// 刷新数据 self.tableView.triggerRefreshing() } /// 新增 if let loginUser = obj.0 as? MoMgrLoginUser { n.loginUser = loginUser } else if let subLoginUser = obj.0 as? MoSubMgrLoginUser { n.subLoginUser = subLoginUser } n.operatorType = obj.1 } case "ShowNewLoginAccount": /// 新增登录账号 if let n = segue.destination as? NewLoginAccountViewController, let obj = sender as? (Any, OperatorType) { n.popBlock = { (_ takeInfo: Any?) in /// 刷新数据 self.tableView.triggerRefreshing() } if let loginUser = obj.0 as? MoMgrLoginUser { n.loginUser = loginUser /// 判断其是否是交易员 n.isTrader = loginUser.querytype == 2 } else if let sub = obj.0 as? MoSubMgrLoginUser { n.subLoginUser = sub n.isTrader = sub.roletype.contains("24") } n.operatorType = obj.1 } case "ShowCredit": /// 授信 if let c = segue.destination as? CreditViewController, let obj = sender as? (Any?, Any?) { c.popBlock = { (_ takeInfo: Any?) in /// 刷新数据 self.tableView.triggerRefreshing() } c.subTaaccount = obj.0 as? MoSubMgrTaaccount } case "ShowNewTraderUser": /// 交易用户 if let n = segue.destination as? NewTraderUserViewController, let obj = sender as? (Any?, OperatorType) { n.operatorType = obj.1 n.traderUser = obj.0 as? MoMgrLoginUser n.popBlock = { (_ model: Any?) in /// 请求数据 self.tableView.triggerRefreshing() } } case "ShowSeeRole": /// 查看权限 if let n = segue.destination as? NewRoleSetViewController, let obj = sender as? (MoMgrLoginUser?, OperatorType) { n.operatorType = .detail n.loginUser = obj.0 n.navigationItem.title = "权限模板详情" } default: break } } } // MARK: - UITableViewDelegate, UITableViewDataSource extension AccountManagerViewController: UITableViewDelegate, UITableViewDataSource { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 1 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: CellIdentifier, for: indexPath) as! AccountArborescenceCell cell.indexPath = indexPath var count = 0 self.objs.forEach { (obj) in if let login = obj as? MoMgrLoginUser { count += login.userlist.count } else if let ta = obj as? MoMgrTaaccount { count += ta.subacclist.count } } /// 显示机构名称 if let name = MTP2BusinessCore.shared.accountManager?.userAccountInfo?.accountname { /// 傻逼人做傻逼事 cell.model = name+(roleTitles[segmentedView.selectedIndex] == "期货账户" ? "" : " (\(count))") } if roleTitles.count != 0 { /// 设置按钮 switch roleTitles[segmentedView.selectedIndex] { case "业务账户": /// 业务账户 cell.roleSet.isHidden = true cell.new.isHidden = true case "交易账户": /// 交易账户 cell.roleSet.isHidden = true cell.new.isHidden = false case "管理账户": /// 管理账户 cell.roleSet.isHidden = false cell.new.isHidden = true default: /// 期货账户 cell.roleSet.isHidden = true cell.new.isHidden = false } } cell.objs = self.objs /// 回调块 cell.block = { (_ model: Any?, _ sender: Any?) in switch (model.self, sender.self) { case (is MoMgrLoginUser, is OperatorType): /// 新增登录账号主账户、管理员账户 if let obj = model as? MoMgrLoginUser, let type = sender as? OperatorType, type == .add { switch obj.querytype { case 1: /// 业务账户 self.performSegue(withIdentifier: "ShowNewLoginAccount", sender: (obj, type)) case 3: /// 管理账户 self.performSegue(withIdentifier: "ShowNewAdministratorAccount", sender: (obj, type)) default: /// 交易账户 self.performSegue(withIdentifier: "ShowNewLoginAccount", sender: (obj, type)) } } else if let obj = model as? MoMgrLoginUser, let type = sender as? OperatorType, type == .update { self.performSegue(withIdentifier: "ShowNewTraderUser", sender: (obj, type)) } else if let obj = model as? MoMgrLoginUser, let type = sender as? OperatorType, type == .seeRole { self.performSegue(withIdentifier: "ShowSeeRole", sender: (obj, type)) } case (is String, is OperatorType): /// 角色设置 账户设置 if self.roleTitles.count != 0 { if let type = sender as? OperatorType, type == .roleSet { self.performSegue(withIdentifier: self.roleTitles[self.segmentedView.selectedIndex] == "期货账户" ? "ShowFuturesAccountSet" : "ShowRoleSet", sender: (model, sender)) } else if let type = sender as? OperatorType, type == .add { /// 新增角色、期货账户信息 self.performSegue(withIdentifier: self.roleTitles[self.segmentedView.selectedIndex] == "期货账户" ? "ShowNewFuturesAccount" : "ShowNewTraderUser", sender: (model, sender)) } } case (is MoMgrTaaccount, is OperatorType): /// 新增期货子账户、修改期货账户 if let type = sender as? OperatorType { self.performSegue(withIdentifier: type == .add ? "ShowNewSubFutureAccount" : "ShowNewFuturesAccount", sender: (model, sender)) } default: break } } /// 回调块 cell.callBack = { (_ model: Any?, _ sender: Any?) in switch (model.self, sender.self) { case (is MoSubMgrLoginUser, is OperatorType): /// 登录账户 if let login = model as? MoSubMgrLoginUser, let type = sender as? OperatorType { switch type { case .lock: /// 冻结 self.doLoginAccountOperator(login, 5) case .loginout: /// 注销 self.doLoginAccountOperator(login, 7) case .unlock: /// 解冻 self.doLoginAccountOperator(login, 6) case .resetpwd: /// 重置密码 let rp = self.viewController("Settings", "LoginPasswordUpdateFirst") as! LoginPasswordUpdateViewController rp.navigationItem.title = "重置登录密码" rp.takeInfo = login self.navigationController?.pushViewController(rp, animated: true) case .update, .detail: /// 修改 self.performSegue(withIdentifier: login.usertype == 2 ? "ShowNewAdministratorAccount" : "ShowNewLoginAccount", sender: (model, sender)) default: break } } case (is MoMgrTaaccount, is OperatorType): /// 期货账户 添加子账户 if let taAccount = model as? MoMgrTaaccount, let type = sender as? OperatorType, type == .add { self.performSegue(withIdentifier: "ShowNewSubFutureAccount", sender: taAccount) } case (is MoSubMgrTaaccount, is OperatorType): /// 期货账户子账户操作 if let obj = model as? MoSubMgrTaaccount, let type = sender as? OperatorType { switch type { case .credit: /// 授信 self.performSegue(withIdentifier: "ShowCredit", sender: (model, sender)) case .loginout: /// 注销 self.doFutureAccountOperator(obj, 7) case .update: /// 修改 self.performSegue(withIdentifier: "ShowNewSubFutureAccount", sender: ((self.objs[indexPath.row], obj), sender)) default: /// 详细 self.performSegue(withIdentifier: "ShowNewSubFutureAccount", sender: ((self.objs[indexPath.row], obj), sender)) } } default: break } } return cell } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { if objs.count != 0 { switch objs[indexPath.row].self { case is MoMgrLoginUser: /// 登录账号 var height: CGFloat = 0.0 height += CGFloat(objs.count+1)*50.0 (objs as! [MoMgrLoginUser]).forEach { (user) in user.userlist.forEach { (sub) in height += sub.subexpland ? 90.0 : 50.0 } } return height default: /// 期货账户 var height: CGFloat = 0.0 height += CGFloat(objs.count+1)*50.0 (objs as! [MoMgrTaaccount]).forEach { (ta) in ta.subacclist.forEach { (sub) in height += sub.subexpland ? 90.0 : 50.0 } } return height } } return 50.0 } } // MARK: - JXSegmentedViewDelegate extension AccountManagerViewController: JXSegmentedViewDelegate { /// didSelectedItemAt /// - Parameters: /// - segmentedView: segmentedView /// - index: index func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) { switch roleTitles[index] { case "业务账户": queryAccMgrLoginUser(1) case "交易账户": queryAccMgrLoginUser(2) case "管理账户": queryAccMgrLoginUser(3) default: /// 期货账户 queryAccMgrTaaccount() } } } // MARK: - AccountArborescenceCell class AccountArborescenceCell: BaseTableViewCell { /// 树状按钮 @IBOutlet weak var arborescence: UIImageView! /// 标题 @IBOutlet weak var titleLabel: UILabel! /// 角色设置 @IBOutlet weak var roleSet: AnimatableButton! /// 新增 @IBOutlet weak var new: UIButton! /// 子树 @IBOutlet weak var tableView: UITableView! /// 所处位置 var indexPath: IndexPath? /// 数据信息 var objs: [Any] = [] { didSet { /// 刷新数据 tableView.reloadData() } } /// 回调块 var callBack: ((_ model: Any?, _ sender: Any?) -> Void)? /// SubArborescenceCellIdentifier let SubArborescenceCellIdentifier = "SubArborescence_Cell" /// 数据 override var model: Any? { didSet { /// 异常 guard let obj = model as? String else { return } /// 标题 titleLabel.text = obj.isBlank() } } /// onButtonPressed /// - Parameter sender: sender @IBAction func onButtonPressed(_ sender: UIButton) { switch sender { case roleSet: /// 权限设置 if let bk = block { bk(model, OperatorType.roleSet) } default: /// 新增 if let bk = block { bk(model, OperatorType.add) } } } } // MARK: - AccountArborescenceCell UITableViewDelegate, UITableViewDataSource extension AccountArborescenceCell: UITableViewDelegate, UITableViewDataSource { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return objs.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: SubArborescenceCellIdentifier, for: indexPath) as! AccountSubArborescenceCell switch objs[indexPath.row].self { case is MoMgrLoginUser: /// 登录账号 cell.model = objs[indexPath.row] as! MoMgrLoginUser default: /// 期货账户 cell.model = objs[indexPath.row] as! MoMgrTaaccount } cell.indexPath = indexPath /// 操作项 cell.block = { (_ model: Any?, _ sender: Any?) in if let index = cell.indexPath?.row, let s = self.superController() as? AccountManagerViewController { if let type = sender as? OperatorType { switch type { case .expland: if let obj = model { switch obj.self { case is MoMgrLoginUser: /// 登录账号 var login = obj as! MoMgrLoginUser login.expland = !login.expland cell.parent = login s.objs.replaceSubrange(index...index, with: [login]) case is (MoSubMgrLoginUser, Int): /// 子账号 var sub = (obj as! (MoSubMgrLoginUser, Int)).0 sub.subexpland = !sub.subexpland cell.model = sub var mgr = cell.parent as! MoMgrLoginUser let row = (obj as! (MoSubMgrLoginUser, Int)).1 mgr.userlist.replaceSubrange(row...row, with: [sub]) s.objs.replaceSubrange(index...index, with: [mgr]) case is (MoSubMgrTaaccount, Int): /// 子期货账号 var sub = (obj as! (MoSubMgrTaaccount, Int)).0 sub.subexpland = !sub.subexpland cell.model = sub var mgr = cell.parent as! MoMgrTaaccount let row = (obj as! (MoSubMgrTaaccount, Int)).1 mgr.subacclist.replaceSubrange(row...row, with: [sub]) s.objs.replaceSubrange(index...index, with: [mgr]) default: /// 期货账号 var obj = cell.parent as! MoMgrTaaccount obj.expland = !obj.expland cell.parent = obj s.objs.replaceSubrange(index...index, with: [obj]) } } case .add, .update, .seeRole: /// 新增、修改 查看角色 if let bk = self.block { bk(model, type) } default: /// 操作项 if let bk = cell.callBack { bk(model, type) } } } } } /// 操作回调 cell.callBack = { (_ obj: Any?, _ sender: Any?) in if let bk = self.callBack { bk(obj, sender) } } if let index = cell.indexPath?.row, let s = self.superController() as? AccountManagerViewController { cell.parent = s.objs[index] } return cell } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { switch objs[indexPath.row].self { case is MoMgrLoginUser: /// 登录账号 let obj = objs[indexPath.row] as! MoMgrLoginUser var height: CGFloat = 50.0 if obj.expland { obj.userlist.forEach { (userlist) in height += userlist.subexpland ? 90.0 : 50.0 } } return height default: /// 期货账号 let obj = objs[indexPath.row] as! MoMgrTaaccount var height: CGFloat = 50.0 if obj.expland { obj.subacclist.forEach { (subacclist) in height += subacclist.subexpland ? 90.0 : 50.0 } } return height } } } // MARK: - AccountSubArborescenceCell class AccountSubArborescenceCell: BaseTableViewCell { /// 树状按钮 @IBOutlet weak var arborescence: UIButton! /// 标题 @IBOutlet weak var leftTitle: UILabel! /// 查看权限 @IBOutlet weak var seeRole: UIButton! /// 新增 @IBOutlet weak var add: UIButton! /// 修改 @IBOutlet weak var edit: UIButton! /// 列表 @IBOutlet weak var tableView: UITableView! /// 回调块 var callBack: ((_ model: Any?, _ sender: Any?) -> Void)? /// ThirdArborescencCellIdentifier let ThirdArborescencCellIdentifier = "ThirdArborescenc_Cell" /// 父数据 var parent: Any? /// 所处位置 var indexPath: IndexPath? /// 商品单位 var unit: String = "" /// 数据 override var model: Any? { didSet { switch model.self { case is MoMgrLoginUser: /// 登录账号 let obj = model as! MoMgrLoginUser leftTitle.attributedText = "\(obj.rolename.isBlank())".withFont(.font_16).withTextColor(.hex333())+" (\(obj.userlist.count))".withFont(.font_13).withTextColor(.hex999()) edit.isHidden = obj.querytype != 2 /// 设置图标 arborescence.setImage(UIImage(named: !obj.expland ? "unsubarborescence" : "subarborescence"), for: .normal) /// 交易用户、业务员、跟单员可以查看权限 seeRole.isHidden = !(obj.userlist.contains(where: {$0.roletype.contains("22") || $0.roletype.contains("23") || $0.roletype.contains("24")})) case is MoMgrTaaccount: /// 期货账号 if let obj = model as? MoMgrTaaccount, let main = obj.mainAcc { leftTitle.attributedText = "\(main.accountname.isBlank()) - \(main.hedgeaccountcode)".withFont(.font_15).withTextColor(.hex333())+" (\(obj.subacclist.count)) \(main.fcname) ".withFont(.font_13).withTextColor(.hex999()) /// 设置图标 arborescence.setImage(UIImage(named: !obj.expland ? "unsubarborescence" : "subarborescence"), for: .normal) } /// 修改按钮 edit.isHidden = false /// 查看权限 seeRole.isHidden = true default: break } /// 刷新数据 tableView.reloadData() } } /// onButtonPressed /// - Parameter sender: sender @IBAction func onButtonPressed(_ sender: UIButton) { switch sender { case arborescence: /// 点击按钮 if let bk = self.block { bk(self.model, OperatorType.expland) } case edit: /// 修改 if let bk = self.block { bk(self.model, OperatorType.update) } case seeRole: /// 查看权限 if let bk = self.block { bk(self.model, OperatorType.seeRole) } default: /// 新增 if let bk = self.block { bk(self.model, OperatorType.add) } } } } // MARK: - AccountSubArborescenceCell UITableViewDelegate, UITableViewDataSource extension AccountSubArborescenceCell: UITableViewDelegate, UITableViewDataSource { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { switch model.self { case is MoMgrLoginUser: /// 登录账号 return (model as! MoMgrLoginUser).userlist.count case is MoMgrTaaccount: /// 期货账户 return (model as! MoMgrTaaccount).subacclist.count default: return 0 } } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: ThirdArborescencCellIdentifier, for: indexPath) as! AccountThirdArborescenceCell switch model.self { case is MoMgrLoginUser: /// 登录账号 let obj = (model as! MoMgrLoginUser).userlist[indexPath.row] cell.parent = (model as! MoMgrLoginUser).userlist[indexPath.row] cell.model = (name: "\(obj.loginname.isBlank())", logincode: " \(obj.logincode.isBlank())", status: obj.loginstatus) case is MoMgrTaaccount: /// 期货账号 let obj = (model as! MoMgrTaaccount).subacclist[indexPath.row] cell.parent = (model as! MoMgrTaaccount).subacclist[indexPath.row] cell.model = (name: "\(obj.accountname.isBlank())", logincode: " \(obj.accountid)", status: obj.tradestatus) default: break } /// 操作回调 cell.callBack = { (_ model: Any?, _ sender: Any?) in if let bk = self.callBack { bk(model, sender) } } return cell } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { switch model.self { case is MoMgrLoginUser: /// 登录账号 let obj = (model as! MoMgrLoginUser).userlist[indexPath.row] return obj.subexpland ? 85.0 : 50.0 case is MoMgrTaaccount: /// 期货账号 let obj = (model as! MoMgrTaaccount).subacclist[indexPath.row] return obj.subexpland ? 85.0 : 50.0 default: return 85.0 } } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { switch model.self { case is MoMgrLoginUser: /// 登录账号 let obj = (model as! MoMgrLoginUser).userlist[indexPath.row] if let bk = block { bk((obj, indexPath.row), OperatorType.expland) } case is MoMgrTaaccount: /// 期货账号 let obj = (model as! MoMgrTaaccount).subacclist[indexPath.row] if let bk = block { bk((obj, indexPath.row), OperatorType.expland) } default: break } } } // MARK: - ThirdArborescenceCell class AccountThirdArborescenceCell: BaseTableViewCell<(name: String, logincode: String, status: Any)> { /// 背景视图 @IBOutlet weak var bgView: AnimatableView! /// 右边标题 @IBOutlet weak var rightTitle: UILabel! /// 左边标题 @IBOutlet weak var leftTitle: UILabel! /// 详情按钮 @IBOutlet weak var detail: UIButton! /// 修改按钮 @IBOutlet weak var update: UIButton! /// 重置密码 @IBOutlet weak var reset: UIButton! /// 冻结 @IBOutlet weak var lock: UIButton! /// 解冻 @IBOutlet weak var unlock: UIButton! /// 注销按钮 @IBOutlet weak var logout: UIButton! /// 授信 @IBOutlet weak var credit: UIButton! /// 回调块 var callBack: ((_ model: Any?, _ sender: Any?) -> Void)? /// 数据 override var model: (name: String, logincode: String, status: Any)? { didSet { guard let obj = model else { return } /// 左边值 leftTitle.text = "\(obj.name) -\(obj.logincode)" /// 登录账号 if let obj = obj.status as? ELoginStatus { /// 登录账号 rightTitle.text = "\(obj.description)" } else { /// 期货账户 rightTitle.text = "\((obj.status as! ETradeStatus).description)" } } } /// 父数据 var parent: Any? { didSet { switch parent.self { /// 登录账号 case is MoSubMgrLoginUser: if let obj = parent as? MoSubMgrLoginUser { /// bgView bgView.borderColor = UIColor.fromHex(rgbValue: obj.loginstatus != .invalid ? 0x90D7FF : 0xCCCCCC) bgView.backgroundColor = obj.loginstatus != .invalid ? .E8F3F6() : .F4F4F4() /// leftTitle leftTitle.textColor = obj.loginstatus != .invalid ? .hex333() : .hexCCC() switch obj.loginstatus { case .normal: /// 正常 /// rightTitle rightTitle.textColor = .fromHex(rgbValue: 0x2FBB4D) /// 修改按钮 update.isHidden = false /// 重置密码 reset.isHidden = false /// 冻结 lock.isHidden = false /// 解冻 unlock.isHidden = true /// 注销按钮 logout.isHidden = false case .freeze: /// 冻结 /// rightTitle rightTitle.textColor = .fromHex(rgbValue: 0xF04646) /// 修改按钮 update.isHidden = true /// 重置密码 reset.isHidden = true /// 冻结 lock.isHidden = true /// 解冻 unlock.isHidden = false /// 注销按钮 logout.isHidden = true default: /// 其他 /// 修改按钮 update.isHidden = true /// 重置密码 reset.isHidden = true /// 冻结 lock.isHidden = true /// 解冻 unlock.isHidden = true /// 注销按钮 logout.isHidden = true /// rightTitle rightTitle.textColor = .hexCCC() } credit.isHidden = true } default: /// 期货账户 if let obj = parent as? MoSubMgrTaaccount { bgView.borderColor = UIColor.fromHex(rgbValue: obj.tradestatus != .cancelled ? 0x90D7FF : 0xCCCCCC) bgView.backgroundColor = obj.tradestatus != .cancelled ? .E8F3F6() : .F4F4F4() leftTitle.textColor = obj.tradestatus != .cancelled ? .hex333() : .hexCCC() rightTitle.textColor = .fromHex(rgbValue: obj.tradestatus != .cancelled ? 0x2FBB4D : 0xCCCCCC) switch obj.tradestatus { case .normal: /// 正常状态 credit.isHidden = false update.isHidden = false logout.isHidden = false default: /// 其他状态 credit.isHidden = true update.isHidden = true logout.isHidden = true } lock.isHidden = true unlock.isHidden = true reset.isHidden = true } } } } @IBAction func onButtonPressed(_ sender: UIButton) { switch sender { case lock: /// 冻结 if let bk = self.callBack { bk(parent, OperatorType.lock) } case detail: /// 详情 if let bk = self.callBack { bk(parent, OperatorType.detail) } case update: /// 修改 if let bk = self.callBack { bk(parent, OperatorType.update) } case reset: /// 重置密码 if let bk = self.callBack { bk(parent, OperatorType.resetpwd) } case unlock: /// 解冻 if let bk = self.callBack { bk(parent, OperatorType.unlock) } case logout: /// 注销 if let bk = self.callBack { bk(parent, OperatorType.loginout) } case credit: /// 授信 if let bk = self.callBack { bk(parent, OperatorType.credit) } default: break } } }