PositionSpotFutureDetailViewController.swift 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. //
  2. // PositionSpotFutureDetailViewController.swift
  3. // MTP2_iOS
  4. //
  5. // Created by Muchinfo on 2021/1/6.
  6. // Copyright © 2021 Muchinfo. All rights reserved.
  7. //
  8. import UIKit
  9. import WHToast
  10. import GTMRefresh
  11. /// 期货头寸、期货头寸-明细视图容器控制类
  12. class PositionSpotFutureDetailViewController: BaseCollectionViewController {
  13. // MARK: - 属性列表
  14. /// 主滚动视图
  15. @IBOutlet weak var mainScrollView: UIScrollView!
  16. /// 现货头寸明细
  17. var exposureSpot: MoExposureSpot?
  18. /// 期货头寸明细
  19. var hedgePosition: MoExposureHedgePosition?
  20. /// 操作类型
  21. var operatorType: OperatorType = .cashFlow
  22. /// 明细数据信息
  23. var spotDetails: [MoExposureSpot] = [] {
  24. didSet {
  25. /// 左边数据
  26. leftDatas = spotDetails.map { (obj) -> String in
  27. /// 合同编号和采购销售名称
  28. return "\(obj.createtime.date(formatter: "yyyy-MM-dd HH:mm:ss")?.getString(formatter: "yyyyMMdd HH:mm") ?? "--")"+"\n\(obj.relatedno)"
  29. }
  30. /// 右边数据
  31. rightDatas = spotDetails.map { (obj) -> [String] in
  32. return ["\(obj.recordname)",
  33. "\(obj.wrstandardname)",
  34. "\(obj.qty.toUpString())\(obj.enumdicname.isBlank())"]
  35. }
  36. /// 刷新右侧列表数据
  37. rightTableView.reloadData()
  38. /// 无数据按钮
  39. noDataButton.isHidden = spotDetails.count != 0
  40. }
  41. }
  42. /// 期货明细
  43. var hedgePositionDetails: [MoExposureHedgePositionDetail] = [] {
  44. didSet {
  45. /// 左边数据
  46. leftDatas = hedgePositionDetails.map { (obj) -> String in
  47. /// 合同编号和采购销售名称
  48. return "\(obj.tradetime.date(formatter: "yyyy-MM-dd HH:mm:ss")?.getString(formatter: "yyyyMMdd HH:mm") ?? "--")"+"\n\(obj.goodsname)"
  49. }
  50. /// 右边数据
  51. rightDatas = hedgePositionDetails.map { (obj) -> [String] in
  52. return ["\(obj.buyorsell == .BUY ? "买" : "卖")",
  53. "\(obj.channelbuildtype == .BUILDTYPE_OPEN ? "开" : "平")",
  54. "\(obj.tradeqty.toUpString())手"]
  55. }
  56. /// 刷新右侧列表数据
  57. rightTableView.reloadData()
  58. /// 无数据按钮
  59. noDataButton.isHidden = hedgePositionDetails.count != 0
  60. }
  61. }
  62. // MARK: - 生命周期
  63. override func viewWillAppear(_ animated: Bool) {
  64. super.viewWillAppear(animated)
  65. /// 列头高度
  66. columnWidth = 100.0
  67. }
  68. override func viewDidLoad() {
  69. super.viewDidLoad()
  70. // Do any additional setup after loading the view.
  71. /// 不需要返回按钮
  72. addBackBarButtonItem()
  73. /// 不能选中
  74. canSelected = false
  75. /// 下拉刷新
  76. mainScrollView.gtm_addRefreshHeaderView(refreshHeader: DefaultGTMRefreshHeader()) {
  77. /// 查询待点价
  78. self.reloadData()
  79. }
  80. /// 查询待点价
  81. reloadData()
  82. }
  83. // MARK: - 接口请求
  84. /// 刷新数据信息
  85. /// - Parameter type: 类型
  86. fileprivate func reloadData() {
  87. /// 异常
  88. guard let commonManager = MTP2BusinessCore.shared.commonManager,
  89. let spotManager = MTP2BusinessCore.shared.spotManager else { return }
  90. /// startAnimating
  91. _anim?.startAnimating()
  92. /// group
  93. let group = DispatchGroup()
  94. /// 现货明细
  95. if operatorType == .cashFlow, let obj = exposureSpot {
  96. /// 清空数据
  97. spotDetails = []
  98. /// group
  99. group.enter()
  100. /// 查询现货头寸明细数据
  101. spotManager.queryExposureSpotDetail(wrstandardid: obj.wrstandardid) { (isSuccess, er, objs) in
  102. DispatchQueue.main.async {
  103. /// 查询失败
  104. if !isSuccess {
  105. self.spotDetails = []
  106. WHToast.showMessage("现货头寸明细数据查询失败,原因:\(er?.retMsg ?? "查询超时")", duration: ToastTimer, finishHandler: {})
  107. return
  108. }
  109. /// 数据
  110. self.spotDetails = objs ?? []
  111. }
  112. group.leave()
  113. }
  114. } else if let obj = hedgePosition { /// 期货明细
  115. /// 清空数据
  116. hedgePositionDetails = []
  117. /// group
  118. group.enter()
  119. spotManager.queryExposureHedgePositionDetail(goodsId: obj.goodsid) { (isSuccess, er, objs) in
  120. DispatchQueue.main.async {
  121. /// 查询失败
  122. if !isSuccess {
  123. WHToast.showMessage("期货头寸明细数据查询失败,原因:\(er?.retMsg ?? "查询超时")", duration: ToastTimer, finishHandler: {})
  124. return
  125. }
  126. /// 数据
  127. self.hedgePositionDetails = objs ?? []
  128. }
  129. group.leave()
  130. }
  131. }
  132. /// key
  133. let key = operatorType == .cashFlow ? "table_mobile_exposure_spotposition_detail" : "table_mobile_exposure_futuresposition_detail"
  134. group.enter()
  135. /// 查询列头信息
  136. commonManager.queryTableDefine(tableKey: key) { (isSuccess, er, objs) in
  137. DispatchQueue.main.async {
  138. /// 查询失败
  139. if !isSuccess {
  140. WHToast.showMessage("数据查询失败,原因:\(er?.retMsg ?? "查询超时")", duration: ToastTimer, finishHandler: {})
  141. return
  142. }
  143. /// 数据
  144. self.columnHeaders = objs?.first?.columns.sorted(by: { (obj1, obj2) -> Bool in
  145. return obj1.orderindex<obj2.orderindex
  146. }).map({ (obj) -> String in
  147. return obj.columntitle.replacingOccurrences(of: "\\n", with: "\n")
  148. }) ?? []
  149. }
  150. group.leave()
  151. }
  152. group.notify(queue: .main) {
  153. /// 结束下拉刷新
  154. self.mainScrollView.endRefreshing()
  155. /// stopAnimating
  156. self._anim?.stopAnimating()
  157. }
  158. }
  159. }