AccountManagerViewController.swift 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906
  1. //
  2. // AccountManagerViewController.swift
  3. // MTP2_iOS
  4. //
  5. // Created by Muchinfo on 2021/3/26.
  6. // Copyright © 2021 Muchinfo. All rights reserved.
  7. //
  8. import UIKit
  9. import GTMRefresh
  10. import WHToast
  11. import JXSegmentedView
  12. import IBAnimatable
  13. import SwiftyAttributes
  14. import NVActivityIndicatorView
  15. /// 账户管理主视图容器控制类
  16. class AccountManagerViewController: BaseViewController {
  17. // MARK: - 属性列表
  18. /// 类目
  19. @IBOutlet weak var segmentedView: JXSegmentedView! {
  20. didSet {
  21. segmentedView.dataSource = dataSource
  22. segmentedView.indicators = [indicator]
  23. segmentedView.delegate = self
  24. }
  25. }
  26. /// 数据列表
  27. @IBOutlet weak var tableView: UITableView!
  28. /// 登录账户信息
  29. var objs: [Any] = [] {
  30. didSet {
  31. /// noDataButton
  32. noDataButton.isHidden = objs.count != 0
  33. /// 刷新列表
  34. self.tableView.reloadData()
  35. }
  36. }
  37. /// 选中的位置
  38. var selectedIndex: (row: Int, isExpland: Bool)? {
  39. didSet {
  40. if let index = selectedIndex {
  41. /// 刷新某一行
  42. tableView.reloadRows(at: [IndexPath(row: index.row, section: 0)], with: .automatic)
  43. }
  44. }
  45. }
  46. /// CellIdentifier
  47. let CellIdentifier = "AccountManager_Cell"
  48. /// 权限功能
  49. var roleTitles: [String] {
  50. get {
  51. var titles: [String] = []
  52. /// 权限控制
  53. guard let commonManager = MTP2BusinessCore.shared.commonManager else {
  54. return titles
  55. }
  56. if commonManager.containMenu(key: "client_accountmanage_business") {
  57. titles.append("业务账户")
  58. }
  59. if commonManager.containMenu(key: "client_accountmanage_trade") {
  60. titles.append("交易账户")
  61. }
  62. if commonManager.containMenu(key: "client_accountmanage_manage") {
  63. titles.append("管理账户")
  64. }
  65. if commonManager.containMenu(key: "client_accountmanage_ta") {
  66. titles.append("期货账户")
  67. }
  68. return titles
  69. }
  70. }
  71. // MARK: - 生命周期
  72. override func viewDidLoad() {
  73. super.viewDidLoad()
  74. // Do any additional setup after loading the view.
  75. /// addLoadingView
  76. addLoadingView()
  77. /// titles
  78. dataSource.titles = roleTitles
  79. segmentedView.reloadData()
  80. /// 请求数据
  81. if roleTitles.count != 0 {
  82. /// 添加下拉刷新
  83. tableView.gtm_addRefreshHeaderView(refreshHeader: DefaultGTMRefreshHeader()) {
  84. switch self.roleTitles[self.segmentedView.selectedIndex] {
  85. case "业务账户":
  86. self.queryAccMgrLoginUser(1)
  87. case "交易账户":
  88. self.queryAccMgrLoginUser(2)
  89. case "管理账户":
  90. self.queryAccMgrLoginUser(3)
  91. default: /// 期货账户
  92. self.queryAccMgrTaaccount()
  93. }
  94. }
  95. /// 默认选中第一个
  96. segmentedView.defaultSelectedIndex = 0
  97. segmentedView.delegate?.segmentedView(segmentedView, didSelectedItemAt: 0)
  98. }
  99. }
  100. // MARK: - 接口查询
  101. /// 查询账户管理登录账号
  102. /// - Parameter querytype: 查询类型 1-业务账户 2-交易账户 3-管理账户
  103. fileprivate func queryAccMgrLoginUser(_ querytype: Int) {
  104. /// 异常
  105. guard let accountManager = MTP2BusinessCore.shared.accountManager else { return }
  106. /// startAnimating
  107. _anim?.startAnimating()
  108. /// 查询登录账户信息
  109. accountManager.queryAccMgrLoginUser(querytype: querytype, callback: { isSuccess, er, users in
  110. DispatchQueue.main.async {
  111. /// stopAnimating
  112. self._anim?.stopAnimating()
  113. /// endRefreshing
  114. self.tableView.endRefreshing()
  115. /// 查询失败
  116. if !isSuccess {
  117. self.objs = []
  118. WHToast.showMessage("数据查询失败,原因:\(er?.retMsg ?? "请求超时")", duration: ToastTimer, finishHandler: {})
  119. return
  120. }
  121. /// 过滤掉注销账户
  122. var array: [MoMgrLoginUser] = []
  123. users?.forEach({ obj in
  124. var u = MoMgrLoginUser()
  125. u.roleid = obj.roleid
  126. u.rolename = obj.rolename
  127. u.accountstatus = obj.accountstatus
  128. u.mobile = obj.mobile
  129. u.querytype = obj.querytype
  130. u.userlist = obj.userlist.filter({$0.loginstatus != .invalid})
  131. array.append(u)
  132. })
  133. /// 数据赋值
  134. self.objs = array
  135. }
  136. })
  137. }
  138. /// 查询期货账户
  139. fileprivate func queryAccMgrTaaccount() {
  140. /// 异常
  141. guard let accountManager = MTP2BusinessCore.shared.accountManager else { return }
  142. /// startAnimating
  143. _anim?.startAnimating()
  144. /// queryAccMgrTaaccount
  145. accountManager.queryAccMgrTaaccount { (isSuccess, er, tas) in
  146. DispatchQueue.main.async {
  147. /// stopAnimating
  148. self._anim?.stopAnimating()
  149. /// endRefreshing
  150. self.tableView.endRefreshing()
  151. /// 查询失败
  152. if !isSuccess {
  153. self.objs = []
  154. WHToast.showMessage("数据查询失败,原因:\(er?.retMsg ?? "请求超时")", duration: ToastTimer, finishHandler: {})
  155. return
  156. }
  157. /// 数据赋值
  158. self.objs = tas ?? []
  159. }
  160. }
  161. }
  162. /// 登录账户操作请求方法
  163. /// - Parameters:
  164. /// - obj: 数据
  165. /// - type: 操作类型-1:新增 2:修改 3:新增管理员 4:修改管理员 5:冻结 6:解冻 7:注销 8:恢复 9:重置密码
  166. fileprivate func doLoginAccountOperator(_ obj: MoSubMgrLoginUser, _ type: Int) {
  167. /// 异常
  168. guard let accountManager = MTP2BusinessCore.shared.accountManager else { return }
  169. /// startAnimating
  170. NVActivityIndicatorPresenter.sharedInstance.startAnimating(animData("请求中..."))
  171. /// 发送请求
  172. 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
  173. DispatchQueue.main.async {
  174. /// stopAnimating
  175. NVActivityIndicatorPresenter.sharedInstance.stopAnimating()
  176. /// 请求失败
  177. if !isSuccess {
  178. WHToast.showMessage("请求失败,原因:\(er?.retMsg ?? "请求超时")", duration: ToastTimer, finishHandler: {})
  179. return
  180. }
  181. /// 请求成功
  182. WHToast.showSuccess(withMessage: "请求成功", duration: ToastTimer, finishHandler: {
  183. /// 重新请求数据
  184. self.tableView.triggerRefreshing()
  185. })
  186. }
  187. }
  188. }
  189. /// 期货账户子账户操作
  190. /// - Parameters:
  191. /// - obj: 子账户
  192. /// - type: 操作类型
  193. fileprivate func doFutureAccountOperator(_ obj: MoSubMgrTaaccount, _ type: Int) {
  194. /// 异常
  195. guard let accountManager = MTP2BusinessCore.shared.accountManager else { return }
  196. /// startAnimating
  197. NVActivityIndicatorPresenter.sharedInstance.startAnimating(animData("请求中..."))
  198. /// 期货账户注销操作
  199. accountManager.requestTaaccountOperate(accountid: obj.accountid, tradestatus: type) { (isSuccess, er) in
  200. DispatchQueue.main.async {
  201. /// stopAnimating
  202. NVActivityIndicatorPresenter.sharedInstance.stopAnimating()
  203. /// 请求失败
  204. if !isSuccess {
  205. WHToast.showMessage("请求失败,原因:\(er?.retMsg ?? "请求超时")", duration: ToastTimer, finishHandler: {})
  206. return
  207. }
  208. /// 请求成功
  209. WHToast.showSuccess(withMessage: "请求成功", duration: ToastTimer, finishHandler: {
  210. /// 重新请求数据
  211. self.tableView.triggerRefreshing()
  212. })
  213. }
  214. }
  215. }
  216. // MARK: - Navigation
  217. // In a storyboard-based application, you will often want to do a little preparation before navigation
  218. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  219. // Get the new view controller using segue.destination.
  220. // Pass the selected object to the new view controller.
  221. switch segue.identifier {
  222. case "ShowNewFuturesAccount": /// 新增期货主账户
  223. if let n = segue.destination as? NewFuturesAccountViewController, let obj = sender as? (Any?, Any?) {
  224. n.popBlock = { (_ takeInfo: Any?) in
  225. /// 刷新数据
  226. self.tableView.triggerRefreshing()
  227. }
  228. n.moMgrTaaccount = obj.0 as? MoMgrTaaccount
  229. n.operatorType = obj.1 as! OperatorType
  230. }
  231. case "ShowNewSubFutureAccount": /// 增加期货子账户
  232. if let n = segue.destination as? NewSubFutureAccountViewController, let obj = sender as? (Any?, Any?) {
  233. if let type = obj.1 as? OperatorType {
  234. if type == .update || type == .detail { /// 修改
  235. /// 主账户信息
  236. n.moMgrTaaccount = (obj.0 as? (Any, Any))?.0 as? MoMgrTaaccount
  237. /// 子账户信息
  238. n.subMgrTaaccount = (obj.0 as? (Any, Any))?.1 as? MoSubMgrTaaccount
  239. } else {
  240. n.moMgrTaaccount = obj.0 as? MoMgrTaaccount
  241. }
  242. n.operatorType = type
  243. }
  244. n.popBlock = { (_ takeInfo: Any?) in
  245. /// 刷新数据
  246. self.tableView.triggerRefreshing()
  247. }
  248. }
  249. case "ShowNewAdministratorAccount": /// 新增管理员账户
  250. if let n = segue.destination as? NewAdministratorAccountViewController, let obj = sender as? (Any, OperatorType) {
  251. n.popBlock = { (_ takeInfo: Any?) in
  252. /// 刷新数据
  253. self.tableView.triggerRefreshing()
  254. }
  255. /// 新增
  256. if let loginUser = obj.0 as? MoMgrLoginUser {
  257. n.loginUser = loginUser
  258. } else if let subLoginUser = obj.0 as? MoSubMgrLoginUser {
  259. n.subLoginUser = subLoginUser
  260. }
  261. n.operatorType = obj.1
  262. }
  263. case "ShowNewLoginAccount": /// 新增登录账号
  264. if let n = segue.destination as? NewLoginAccountViewController, let obj = sender as? (Any, OperatorType) {
  265. n.popBlock = { (_ takeInfo: Any?) in
  266. /// 刷新数据
  267. self.tableView.triggerRefreshing()
  268. }
  269. if let loginUser = obj.0 as? MoMgrLoginUser {
  270. n.loginUser = loginUser
  271. /// 判断其是否是交易员
  272. n.isTrader = loginUser.querytype == 2
  273. } else if let sub = obj.0 as? MoSubMgrLoginUser {
  274. n.subLoginUser = sub
  275. n.isTrader = sub.roletype.contains("24")
  276. }
  277. n.operatorType = obj.1
  278. }
  279. case "ShowCredit": /// 授信
  280. if let c = segue.destination as? CreditViewController, let obj = sender as? (Any?, Any?) {
  281. c.popBlock = { (_ takeInfo: Any?) in
  282. /// 刷新数据
  283. self.tableView.triggerRefreshing()
  284. }
  285. c.subTaaccount = obj.0 as? MoSubMgrTaaccount
  286. }
  287. case "ShowNewTraderUser": /// 交易用户
  288. if let n = segue.destination as? NewTraderUserViewController, let obj = sender as? (Any?, OperatorType) {
  289. n.operatorType = obj.1
  290. n.traderUser = obj.0 as? MoMgrLoginUser
  291. n.popBlock = { (_ model: Any?) in
  292. /// 请求数据
  293. self.tableView.triggerRefreshing()
  294. }
  295. }
  296. case "ShowSeeRole": /// 查看权限
  297. if let n = segue.destination as? NewRoleSetViewController, let obj = sender as? (MoMgrLoginUser?, OperatorType) {
  298. n.operatorType = .detail
  299. n.loginUser = obj.0
  300. n.navigationItem.title = "权限模板详情"
  301. }
  302. default: break
  303. }
  304. }
  305. }
  306. // MARK: - UITableViewDelegate, UITableViewDataSource
  307. extension AccountManagerViewController: UITableViewDelegate, UITableViewDataSource {
  308. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  309. return 1
  310. }
  311. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  312. let cell = tableView.dequeueReusableCell(withIdentifier: CellIdentifier, for: indexPath) as! AccountArborescenceCell
  313. cell.indexPath = indexPath
  314. var count = 0
  315. self.objs.forEach { (obj) in
  316. if let login = obj as? MoMgrLoginUser {
  317. count += login.userlist.count
  318. } else if let ta = obj as? MoMgrTaaccount {
  319. count += ta.subacclist.count
  320. }
  321. }
  322. /// 显示机构名称
  323. if let name = MTP2BusinessCore.shared.accountManager?.userAccountInfo?.accountname {
  324. /// 傻逼人做傻逼事
  325. cell.model = name+(roleTitles[segmentedView.selectedIndex] == "期货账户" ? "" : " (\(count))")
  326. }
  327. if roleTitles.count != 0 {
  328. /// 设置按钮
  329. switch roleTitles[segmentedView.selectedIndex] {
  330. case "业务账户": /// 业务账户
  331. cell.roleSet.isHidden = true
  332. cell.new.isHidden = true
  333. case "交易账户": /// 交易账户
  334. cell.roleSet.isHidden = true
  335. cell.new.isHidden = false
  336. case "管理账户": /// 管理账户
  337. cell.roleSet.isHidden = false
  338. cell.new.isHidden = true
  339. default: /// 期货账户
  340. cell.roleSet.isHidden = true
  341. cell.new.isHidden = false
  342. }
  343. }
  344. cell.objs = self.objs
  345. /// 回调块
  346. cell.block = { (_ model: Any?, _ sender: Any?) in
  347. switch (model.self, sender.self) {
  348. case (is MoMgrLoginUser, is OperatorType): /// 新增登录账号主账户、管理员账户
  349. if let obj = model as? MoMgrLoginUser, let type = sender as? OperatorType, type == .add {
  350. switch obj.querytype {
  351. case 1: /// 业务账户
  352. self.performSegue(withIdentifier: "ShowNewLoginAccount", sender: (obj, type))
  353. case 3: /// 管理账户
  354. self.performSegue(withIdentifier: "ShowNewAdministratorAccount", sender: (obj, type))
  355. default: /// 交易账户
  356. self.performSegue(withIdentifier: "ShowNewLoginAccount", sender: (obj, type))
  357. }
  358. } else if let obj = model as? MoMgrLoginUser, let type = sender as? OperatorType, type == .update {
  359. self.performSegue(withIdentifier: "ShowNewTraderUser", sender: (obj, type))
  360. } else if let obj = model as? MoMgrLoginUser, let type = sender as? OperatorType, type == .seeRole {
  361. self.performSegue(withIdentifier: "ShowSeeRole", sender: (obj, type))
  362. }
  363. case (is String, is OperatorType): /// 角色设置 账户设置
  364. if self.roleTitles.count != 0 {
  365. if let type = sender as? OperatorType, type == .roleSet {
  366. self.performSegue(withIdentifier: self.roleTitles[self.segmentedView.selectedIndex] == "期货账户" ? "ShowFuturesAccountSet" : "ShowRoleSet", sender: (model, sender))
  367. } else if let type = sender as? OperatorType, type == .add { /// 新增角色、期货账户信息
  368. self.performSegue(withIdentifier: self.roleTitles[self.segmentedView.selectedIndex] == "期货账户" ? "ShowNewFuturesAccount" : "ShowNewTraderUser", sender: (model, sender))
  369. }
  370. }
  371. case (is MoMgrTaaccount, is OperatorType): /// 新增期货子账户、修改期货账户
  372. if let type = sender as? OperatorType {
  373. self.performSegue(withIdentifier: type == .add ? "ShowNewSubFutureAccount" : "ShowNewFuturesAccount", sender: (model, sender))
  374. }
  375. default: break
  376. }
  377. }
  378. /// 回调块
  379. cell.callBack = { (_ model: Any?, _ sender: Any?) in
  380. switch (model.self, sender.self) {
  381. case (is MoSubMgrLoginUser, is OperatorType): /// 登录账户
  382. if let login = model as? MoSubMgrLoginUser, let type = sender as? OperatorType {
  383. switch type {
  384. case .lock: /// 冻结
  385. self.doLoginAccountOperator(login, 5)
  386. case .loginout: /// 注销
  387. self.doLoginAccountOperator(login, 7)
  388. case .unlock: /// 解冻
  389. self.doLoginAccountOperator(login, 6)
  390. case .resetpwd: /// 重置密码
  391. let rp = self.viewController("Settings", "LoginPasswordUpdateFirst") as! LoginPasswordUpdateViewController
  392. rp.navigationItem.title = "重置登录密码"
  393. rp.takeInfo = login
  394. self.navigationController?.pushViewController(rp, animated: true)
  395. case .update, .detail: /// 修改
  396. self.performSegue(withIdentifier: login.usertype == 2 ? "ShowNewAdministratorAccount" : "ShowNewLoginAccount", sender: (model, sender))
  397. default: break
  398. }
  399. }
  400. case (is MoMgrTaaccount, is OperatorType): /// 期货账户 添加子账户
  401. if let taAccount = model as? MoMgrTaaccount, let type = sender as? OperatorType, type == .add {
  402. self.performSegue(withIdentifier: "ShowNewSubFutureAccount", sender: taAccount)
  403. }
  404. case (is MoSubMgrTaaccount, is OperatorType): /// 期货账户子账户操作
  405. if let obj = model as? MoSubMgrTaaccount, let type = sender as? OperatorType {
  406. switch type {
  407. case .credit: /// 授信
  408. self.performSegue(withIdentifier: "ShowCredit", sender: (model, sender))
  409. case .loginout: /// 注销
  410. self.doFutureAccountOperator(obj, 7)
  411. case .update: /// 修改
  412. self.performSegue(withIdentifier: "ShowNewSubFutureAccount", sender: ((self.objs[indexPath.row], obj), sender))
  413. default: /// 详细
  414. self.performSegue(withIdentifier: "ShowNewSubFutureAccount", sender: ((self.objs[indexPath.row], obj), sender))
  415. }
  416. }
  417. default: break
  418. }
  419. }
  420. return cell
  421. }
  422. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  423. if objs.count != 0 {
  424. switch objs[indexPath.row].self {
  425. case is MoMgrLoginUser: /// 登录账号
  426. var height: CGFloat = 0.0
  427. height += CGFloat(objs.count+1)*50.0
  428. (objs as! [MoMgrLoginUser]).forEach { (user) in
  429. user.userlist.forEach { (sub) in
  430. height += sub.subexpland ? 90.0 : 50.0
  431. }
  432. }
  433. return height
  434. default: /// 期货账户
  435. var height: CGFloat = 0.0
  436. height += CGFloat(objs.count+1)*50.0
  437. (objs as! [MoMgrTaaccount]).forEach { (ta) in
  438. ta.subacclist.forEach { (sub) in
  439. height += sub.subexpland ? 90.0 : 50.0
  440. }
  441. }
  442. return height
  443. }
  444. }
  445. return 50.0
  446. }
  447. }
  448. // MARK: - JXSegmentedViewDelegate
  449. extension AccountManagerViewController: JXSegmentedViewDelegate {
  450. /// didSelectedItemAt
  451. /// - Parameters:
  452. /// - segmentedView: segmentedView
  453. /// - index: index
  454. func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {
  455. switch roleTitles[index] {
  456. case "业务账户":
  457. queryAccMgrLoginUser(1)
  458. case "交易账户":
  459. queryAccMgrLoginUser(2)
  460. case "管理账户":
  461. queryAccMgrLoginUser(3)
  462. default: /// 期货账户
  463. queryAccMgrTaaccount()
  464. }
  465. }
  466. }
  467. // MARK: - AccountArborescenceCell
  468. class AccountArborescenceCell: BaseTableViewCell<Any> {
  469. /// 树状按钮
  470. @IBOutlet weak var arborescence: UIImageView!
  471. /// 标题
  472. @IBOutlet weak var titleLabel: UILabel!
  473. /// 角色设置
  474. @IBOutlet weak var roleSet: AnimatableButton!
  475. /// 新增
  476. @IBOutlet weak var new: UIButton!
  477. /// 子树
  478. @IBOutlet weak var tableView: UITableView!
  479. /// 所处位置
  480. var indexPath: IndexPath?
  481. /// 数据信息
  482. var objs: [Any] = [] {
  483. didSet {
  484. /// 刷新数据
  485. tableView.reloadData()
  486. }
  487. }
  488. /// 回调块
  489. var callBack: ((_ model: Any?, _ sender: Any?) -> Void)?
  490. /// SubArborescenceCellIdentifier
  491. let SubArborescenceCellIdentifier = "SubArborescence_Cell"
  492. /// 数据
  493. override var model: Any? {
  494. didSet {
  495. /// 异常
  496. guard let obj = model as? String else { return }
  497. /// 标题
  498. titleLabel.text = obj.isBlank()
  499. }
  500. }
  501. /// onButtonPressed
  502. /// - Parameter sender: sender
  503. @IBAction func onButtonPressed(_ sender: UIButton) {
  504. switch sender {
  505. case roleSet: /// 权限设置
  506. if let bk = block { bk(model, OperatorType.roleSet) }
  507. default: /// 新增
  508. if let bk = block { bk(model, OperatorType.add) }
  509. }
  510. }
  511. }
  512. // MARK: - AccountArborescenceCell UITableViewDelegate, UITableViewDataSource
  513. extension AccountArborescenceCell: UITableViewDelegate, UITableViewDataSource {
  514. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  515. return objs.count
  516. }
  517. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  518. let cell = tableView.dequeueReusableCell(withIdentifier: SubArborescenceCellIdentifier, for: indexPath) as! AccountSubArborescenceCell
  519. switch objs[indexPath.row].self {
  520. case is MoMgrLoginUser: /// 登录账号
  521. cell.model = objs[indexPath.row] as! MoMgrLoginUser
  522. default: /// 期货账户
  523. cell.model = objs[indexPath.row] as! MoMgrTaaccount
  524. }
  525. cell.indexPath = indexPath
  526. /// 操作项
  527. cell.block = { (_ model: Any?, _ sender: Any?) in
  528. if let index = cell.indexPath?.row, let s = self.superController() as? AccountManagerViewController {
  529. if let type = sender as? OperatorType {
  530. switch type {
  531. case .expland:
  532. if let obj = model {
  533. switch obj.self {
  534. case is MoMgrLoginUser: /// 登录账号
  535. var login = obj as! MoMgrLoginUser
  536. login.expland = !login.expland
  537. cell.parent = login
  538. s.objs.replaceSubrange(index...index, with: [login])
  539. case is (MoSubMgrLoginUser, Int): /// 子账号
  540. var sub = (obj as! (MoSubMgrLoginUser, Int)).0
  541. sub.subexpland = !sub.subexpland
  542. cell.model = sub
  543. var mgr = cell.parent as! MoMgrLoginUser
  544. let row = (obj as! (MoSubMgrLoginUser, Int)).1
  545. mgr.userlist.replaceSubrange(row...row, with: [sub])
  546. s.objs.replaceSubrange(index...index, with: [mgr])
  547. case is (MoSubMgrTaaccount, Int): /// 子期货账号
  548. var sub = (obj as! (MoSubMgrTaaccount, Int)).0
  549. sub.subexpland = !sub.subexpland
  550. cell.model = sub
  551. var mgr = cell.parent as! MoMgrTaaccount
  552. let row = (obj as! (MoSubMgrTaaccount, Int)).1
  553. mgr.subacclist.replaceSubrange(row...row, with: [sub])
  554. s.objs.replaceSubrange(index...index, with: [mgr])
  555. default: /// 期货账号
  556. var obj = cell.parent as! MoMgrTaaccount
  557. obj.expland = !obj.expland
  558. cell.parent = obj
  559. s.objs.replaceSubrange(index...index, with: [obj])
  560. }
  561. }
  562. case .add, .update, .seeRole:
  563. /// 新增、修改 查看角色
  564. if let bk = self.block { bk(model, type) }
  565. default:
  566. /// 操作项
  567. if let bk = cell.callBack { bk(model, type) }
  568. }
  569. }
  570. }
  571. }
  572. /// 操作回调
  573. cell.callBack = { (_ obj: Any?, _ sender: Any?) in
  574. if let bk = self.callBack { bk(obj, sender) }
  575. }
  576. if let index = cell.indexPath?.row, let s = self.superController() as? AccountManagerViewController {
  577. cell.parent = s.objs[index]
  578. }
  579. return cell
  580. }
  581. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  582. switch objs[indexPath.row].self {
  583. case is MoMgrLoginUser: /// 登录账号
  584. let obj = objs[indexPath.row] as! MoMgrLoginUser
  585. var height: CGFloat = 50.0
  586. if obj.expland {
  587. obj.userlist.forEach { (userlist) in
  588. height += userlist.subexpland ? 90.0 : 50.0
  589. }
  590. }
  591. return height
  592. default: /// 期货账号
  593. let obj = objs[indexPath.row] as! MoMgrTaaccount
  594. var height: CGFloat = 50.0
  595. if obj.expland {
  596. obj.subacclist.forEach { (subacclist) in
  597. height += subacclist.subexpland ? 90.0 : 50.0
  598. }
  599. }
  600. return height
  601. }
  602. }
  603. }
  604. // MARK: - AccountSubArborescenceCell
  605. class AccountSubArborescenceCell: BaseTableViewCell<Any> {
  606. /// 树状按钮
  607. @IBOutlet weak var arborescence: UIButton!
  608. /// 标题
  609. @IBOutlet weak var leftTitle: UILabel!
  610. /// 查看权限
  611. @IBOutlet weak var seeRole: UIButton!
  612. /// 新增
  613. @IBOutlet weak var add: UIButton!
  614. /// 修改
  615. @IBOutlet weak var edit: UIButton!
  616. /// 列表
  617. @IBOutlet weak var tableView: UITableView!
  618. /// 回调块
  619. var callBack: ((_ model: Any?, _ sender: Any?) -> Void)?
  620. /// ThirdArborescencCellIdentifier
  621. let ThirdArborescencCellIdentifier = "ThirdArborescenc_Cell"
  622. /// 父数据
  623. var parent: Any?
  624. /// 所处位置
  625. var indexPath: IndexPath?
  626. /// 商品单位
  627. var unit: String = ""
  628. /// 数据
  629. override var model: Any? {
  630. didSet {
  631. switch model.self {
  632. case is MoMgrLoginUser: /// 登录账号
  633. let obj = model as! MoMgrLoginUser
  634. leftTitle.attributedText = "\(obj.rolename.isBlank())".withFont(.font_16).withTextColor(.hex333())+" (\(obj.userlist.count))".withFont(.font_13).withTextColor(.hex999())
  635. edit.isHidden = obj.querytype != 2
  636. /// 设置图标
  637. arborescence.setImage(UIImage(named: !obj.expland ? "unsubarborescence" : "subarborescence"), for: .normal)
  638. /// 交易用户、业务员、跟单员可以查看权限
  639. seeRole.isHidden = !(obj.userlist.contains(where: {$0.roletype.contains("22") || $0.roletype.contains("23") || $0.roletype.contains("24")}))
  640. case is MoMgrTaaccount: /// 期货账号
  641. if let obj = model as? MoMgrTaaccount, let main = obj.mainAcc {
  642. leftTitle.attributedText = "\(main.accountname.isBlank()) - \(main.hedgeaccountcode)".withFont(.font_15).withTextColor(.hex333())+" (\(obj.subacclist.count)) \(main.fcname) ".withFont(.font_13).withTextColor(.hex999())
  643. /// 设置图标
  644. arborescence.setImage(UIImage(named: !obj.expland ? "unsubarborescence" : "subarborescence"), for: .normal)
  645. }
  646. /// 修改按钮
  647. edit.isHidden = false
  648. /// 查看权限
  649. seeRole.isHidden = true
  650. default: break
  651. }
  652. /// 刷新数据
  653. tableView.reloadData()
  654. }
  655. }
  656. /// onButtonPressed
  657. /// - Parameter sender: sender
  658. @IBAction func onButtonPressed(_ sender: UIButton) {
  659. switch sender {
  660. case arborescence: /// 点击按钮
  661. if let bk = self.block { bk(self.model, OperatorType.expland) }
  662. case edit: /// 修改
  663. if let bk = self.block { bk(self.model, OperatorType.update) }
  664. case seeRole: /// 查看权限
  665. if let bk = self.block { bk(self.model, OperatorType.seeRole) }
  666. default: /// 新增
  667. if let bk = self.block { bk(self.model, OperatorType.add) }
  668. }
  669. }
  670. }
  671. // MARK: - AccountSubArborescenceCell UITableViewDelegate, UITableViewDataSource
  672. extension AccountSubArborescenceCell: UITableViewDelegate, UITableViewDataSource {
  673. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  674. switch model.self {
  675. case is MoMgrLoginUser: /// 登录账号
  676. return (model as! MoMgrLoginUser).userlist.count
  677. case is MoMgrTaaccount: /// 期货账户
  678. return (model as! MoMgrTaaccount).subacclist.count
  679. default:
  680. return 0
  681. }
  682. }
  683. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  684. let cell = tableView.dequeueReusableCell(withIdentifier: ThirdArborescencCellIdentifier, for: indexPath) as! AccountThirdArborescenceCell
  685. switch model.self {
  686. case is MoMgrLoginUser: /// 登录账号
  687. let obj = (model as! MoMgrLoginUser).userlist[indexPath.row]
  688. cell.parent = (model as! MoMgrLoginUser).userlist[indexPath.row]
  689. cell.model = (name: "\(obj.loginname.isBlank())", logincode: " \(obj.logincode.isBlank())", status: obj.loginstatus)
  690. case is MoMgrTaaccount: /// 期货账号
  691. let obj = (model as! MoMgrTaaccount).subacclist[indexPath.row]
  692. cell.parent = (model as! MoMgrTaaccount).subacclist[indexPath.row]
  693. cell.model = (name: "\(obj.accountname.isBlank())", logincode: " \(obj.accountid)", status: obj.tradestatus)
  694. default: break
  695. }
  696. /// 操作回调
  697. cell.callBack = { (_ model: Any?, _ sender: Any?) in
  698. if let bk = self.callBack {
  699. bk(model, sender)
  700. }
  701. }
  702. return cell
  703. }
  704. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  705. switch model.self {
  706. case is MoMgrLoginUser: /// 登录账号
  707. let obj = (model as! MoMgrLoginUser).userlist[indexPath.row]
  708. return obj.subexpland ? 85.0 : 50.0
  709. case is MoMgrTaaccount: /// 期货账号
  710. let obj = (model as! MoMgrTaaccount).subacclist[indexPath.row]
  711. return obj.subexpland ? 85.0 : 50.0
  712. default: return 85.0
  713. }
  714. }
  715. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  716. switch model.self {
  717. case is MoMgrLoginUser: /// 登录账号
  718. let obj = (model as! MoMgrLoginUser).userlist[indexPath.row]
  719. if let bk = block { bk((obj, indexPath.row), OperatorType.expland) }
  720. case is MoMgrTaaccount: /// 期货账号
  721. let obj = (model as! MoMgrTaaccount).subacclist[indexPath.row]
  722. if let bk = block { bk((obj, indexPath.row), OperatorType.expland) }
  723. default: break
  724. }
  725. }
  726. }
  727. // MARK: - ThirdArborescenceCell
  728. class AccountThirdArborescenceCell: BaseTableViewCell<(name: String, logincode: String, status: Any)> {
  729. /// 背景视图
  730. @IBOutlet weak var bgView: AnimatableView!
  731. /// 右边标题
  732. @IBOutlet weak var rightTitle: UILabel!
  733. /// 左边标题
  734. @IBOutlet weak var leftTitle: UILabel!
  735. /// 详情按钮
  736. @IBOutlet weak var detail: UIButton!
  737. /// 修改按钮
  738. @IBOutlet weak var update: UIButton!
  739. /// 重置密码
  740. @IBOutlet weak var reset: UIButton!
  741. /// 冻结
  742. @IBOutlet weak var lock: UIButton!
  743. /// 解冻
  744. @IBOutlet weak var unlock: UIButton!
  745. /// 注销按钮
  746. @IBOutlet weak var logout: UIButton!
  747. /// 授信
  748. @IBOutlet weak var credit: UIButton!
  749. /// 回调块
  750. var callBack: ((_ model: Any?, _ sender: Any?) -> Void)?
  751. /// 数据
  752. override var model: (name: String, logincode: String, status: Any)? {
  753. didSet {
  754. guard let obj = model else { return }
  755. /// 左边值
  756. leftTitle.text = "\(obj.name) -\(obj.logincode)"
  757. /// 登录账号
  758. if let obj = obj.status as? ELoginStatus { /// 登录账号
  759. rightTitle.text = "\(obj.description)"
  760. } else { /// 期货账户
  761. rightTitle.text = "\((obj.status as! ETradeStatus).description)"
  762. }
  763. }
  764. }
  765. /// 父数据
  766. var parent: Any? {
  767. didSet {
  768. switch parent.self { /// 登录账号
  769. case is MoSubMgrLoginUser:
  770. if let obj = parent as? MoSubMgrLoginUser {
  771. /// bgView
  772. bgView.borderColor = UIColor.fromHex(rgbValue: obj.loginstatus != .invalid ? 0x90D7FF : 0xCCCCCC)
  773. bgView.backgroundColor = obj.loginstatus != .invalid ? .E8F3F6() : .F4F4F4()
  774. /// leftTitle
  775. leftTitle.textColor = obj.loginstatus != .invalid ? .hex333() : .hexCCC()
  776. switch obj.loginstatus {
  777. case .normal: /// 正常
  778. /// rightTitle
  779. rightTitle.textColor = .fromHex(rgbValue: 0x2FBB4D)
  780. /// 修改按钮
  781. update.isHidden = false
  782. /// 重置密码
  783. reset.isHidden = false
  784. /// 冻结
  785. lock.isHidden = false
  786. /// 解冻
  787. unlock.isHidden = true
  788. /// 注销按钮
  789. logout.isHidden = false
  790. case .freeze: /// 冻结
  791. /// rightTitle
  792. rightTitle.textColor = .fromHex(rgbValue: 0xF04646)
  793. /// 修改按钮
  794. update.isHidden = true
  795. /// 重置密码
  796. reset.isHidden = true
  797. /// 冻结
  798. lock.isHidden = true
  799. /// 解冻
  800. unlock.isHidden = false
  801. /// 注销按钮
  802. logout.isHidden = true
  803. default: /// 其他
  804. /// 修改按钮
  805. update.isHidden = true
  806. /// 重置密码
  807. reset.isHidden = true
  808. /// 冻结
  809. lock.isHidden = true
  810. /// 解冻
  811. unlock.isHidden = true
  812. /// 注销按钮
  813. logout.isHidden = true
  814. /// rightTitle
  815. rightTitle.textColor = .hexCCC()
  816. }
  817. credit.isHidden = true
  818. }
  819. default: /// 期货账户
  820. if let obj = parent as? MoSubMgrTaaccount {
  821. bgView.borderColor = UIColor.fromHex(rgbValue: obj.tradestatus != .cancelled ? 0x90D7FF : 0xCCCCCC)
  822. bgView.backgroundColor = obj.tradestatus != .cancelled ? .E8F3F6() : .F4F4F4()
  823. leftTitle.textColor = obj.tradestatus != .cancelled ? .hex333() : .hexCCC()
  824. rightTitle.textColor = .fromHex(rgbValue: obj.tradestatus != .cancelled ? 0x2FBB4D : 0xCCCCCC)
  825. switch obj.tradestatus {
  826. case .normal: /// 正常状态
  827. credit.isHidden = false
  828. update.isHidden = false
  829. logout.isHidden = false
  830. default: /// 其他状态
  831. credit.isHidden = true
  832. update.isHidden = true
  833. logout.isHidden = true
  834. }
  835. lock.isHidden = true
  836. unlock.isHidden = true
  837. reset.isHidden = true
  838. }
  839. }
  840. }
  841. }
  842. @IBAction func onButtonPressed(_ sender: UIButton) {
  843. switch sender {
  844. case lock: /// 冻结
  845. if let bk = self.callBack { bk(parent, OperatorType.lock) }
  846. case detail: /// 详情
  847. if let bk = self.callBack { bk(parent, OperatorType.detail) }
  848. case update: /// 修改
  849. if let bk = self.callBack { bk(parent, OperatorType.update) }
  850. case reset: /// 重置密码
  851. if let bk = self.callBack { bk(parent, OperatorType.resetpwd) }
  852. case unlock: /// 解冻
  853. if let bk = self.callBack { bk(parent, OperatorType.unlock) }
  854. case logout: /// 注销
  855. if let bk = self.callBack { bk(parent, OperatorType.loginout) }
  856. case credit: /// 授信
  857. if let bk = self.callBack { bk(parent, OperatorType.credit) }
  858. default: break
  859. }
  860. }
  861. }