ExposureSpotFutureDetailViewController.swift 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. //
  2. // ExposureSpotFutureDetailViewController.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 ExposureSpotFutureDetailViewController: BaseCollectionViewController {
  13. // MARK: - 属性列表
  14. /// 套保品种
  15. @IBOutlet weak var hedgeType: UILabel!
  16. /// 主滚动视图
  17. @IBOutlet weak var mainScrollView: UIScrollView!
  18. /// 实时敞口数据
  19. var realExposure: MoRealExposure?
  20. /// 操作类型
  21. var operatorType: OperatorType = .cashFlow
  22. /// 敞口现货明细
  23. var exposureDetails: [MoExposureDetail] = [] {
  24. didSet {
  25. /// 左边数据
  26. leftDatas = exposureDetails.map { (obj) -> String in
  27. /// 当现货品种数量为0时,是套保系数变更导致,需在4个类型后面加“(系数变更)”,如 采购合同(系数变更),并将现货品种的数量0显示成“--”
  28. let info = obj.qty == 0 ? "(系数变更)" : ""
  29. /// 合同编号和采购销售名称
  30. return "\(obj.createtime.date(formatter: "yyyy-MM-dd HH:mm:ss")?.getString(formatter: "MMdd HH:mm") ?? "--")"+"\n\(obj.contracttype.description)\(obj.logtype == .HedgePlan ? "计划" : "合同")\(info)"
  31. }
  32. /// 右边数据
  33. rightDatas = exposureDetails.map { (obj) -> [String] in
  34. /// 数量为0 显示-- 当现货品种数量为0时,是套保系数变更导致,需在4个类型后面加“(系数变更)”,如 采购合同(系数变更),并将现货品种的数量0显示成“--”
  35. let qty = obj.qty == 0 ? "--" : "\(obj.qty.toUpString())\(obj.enumdicname.isBlank())"
  36. return ["\(obj.wrstandardname)\n\(qty)",
  37. "\(obj.changeQty.toUpString())\(obj.mgunitidname)",
  38. obj.relateNo,
  39. obj.convertratio.toUpString()]
  40. }
  41. /// 刷新右侧列表数据
  42. rightTableView.reloadData()
  43. /// 无数据按钮
  44. noDataButton.isHidden = exposureDetails.count != 0
  45. }
  46. }
  47. /// 期货明细数据信息
  48. var positions: [MoRealtimeExposurePosition] = [] {
  49. didSet {
  50. /// 左边数据
  51. leftDatas = positions.map { (obj) -> String in
  52. /// 合同编号和采购销售名称
  53. return "\(obj.goodsname)\n\(obj.goodscode)"
  54. }
  55. /// 右边数据
  56. rightDatas = positions.map { (obj) -> [String] in
  57. return ["\(obj.ydqty.toUpString())\n\(obj.curqty.toUpString())",
  58. obj.diffqty.toUpString(),
  59. obj.diffhedgeqty.toUpString(),
  60. "\(obj.agreeunit)\n\(obj.convertratio.toUpString())"]
  61. }
  62. /// 刷新右侧列表数据
  63. rightTableView.reloadData()
  64. /// 无数据按钮
  65. noDataButton.isHidden = positions.count != 0
  66. }
  67. }
  68. // MARK: - 生命周期
  69. override func viewWillAppear(_ animated: Bool) {
  70. super.viewWillAppear(animated)
  71. /// 列头高度
  72. columnWidth = 100.0
  73. }
  74. override func viewDidLoad() {
  75. super.viewDidLoad()
  76. // Do any additional setup after loading the view.
  77. /// 不需要返回按钮
  78. addBackBarButtonItem()
  79. /// 异常
  80. guard let obj = realExposure else { return }
  81. /// 不能选中
  82. canSelected = false
  83. /// 套保品种
  84. hedgeType.text = "套保品种:\(obj.middleGoodsName)(\(obj.middleGoodsCode))"
  85. /// 下拉刷新
  86. mainScrollView.gtm_addRefreshHeaderView(refreshHeader: DefaultGTMRefreshHeader()) {
  87. self.reloadData()
  88. }
  89. /// 刷新数据信息
  90. reloadData()
  91. }
  92. // MARK: - 接口请求
  93. /// 刷新数据信息
  94. /// - Parameter type: 类型
  95. fileprivate func reloadData() {
  96. /// 异常
  97. guard let commonManager = MTP2BusinessCore.shared.commonManager,
  98. let spotManager = MTP2BusinessCore.shared.spotManager,
  99. let obj = realExposure else { return }
  100. /// startAnimating
  101. _anim?.startAnimating()
  102. let group = DispatchGroup()
  103. /// 现货明细
  104. if operatorType == .cashFlow {
  105. /// 清空数据
  106. exposureDetails = []
  107. /// group
  108. group.enter()
  109. /// 查询实时敞口现货明细数据
  110. spotManager.queryExposureDetail(middleGoodsId: obj.middleGoodsID) { (isSuccess, er, objs) in
  111. DispatchQueue.main.async {
  112. /// 查询失败
  113. if !isSuccess {
  114. WHToast.showMessage("现货明细数据查询失败,原因:\(er?.retMsg ?? "查询超时")", duration: ToastTimer, finishHandler: {})
  115. return
  116. }
  117. /// 数据
  118. self.exposureDetails = objs?.sorted(by: { (obj1, obj2) -> Bool in obj1.createtime>obj2.createtime }) ?? []
  119. }
  120. group.leave()
  121. }
  122. } else {
  123. /// 清空数据
  124. positions = []
  125. /// group
  126. group.enter()
  127. /// 查询实时敞口期货明细数据
  128. spotManager.queryRealtimeExposurePosition(middleGoodsId: obj.middleGoodsID) { (isSuccess, er, objs) in
  129. DispatchQueue.main.async {
  130. /// 查询失败
  131. if !isSuccess {
  132. WHToast.showMessage("期货明细数据查询失败,原因:\(er?.retMsg ?? "查询超时")", duration: ToastTimer, finishHandler: {})
  133. return
  134. }
  135. /// 数据
  136. self.positions = objs ?? []
  137. }
  138. group.leave()
  139. }
  140. }
  141. /// tablekey
  142. let key = operatorType == .cashFlow ? "table_mobile_exposure_spot_detail" : "table_mobile_exposure_futures_detail"
  143. group.enter()
  144. /// 查询列头信息
  145. commonManager.queryTableDefine(tableKey: key) { (isSuccess, er, objs) in
  146. DispatchQueue.main.async {
  147. /// 查询失败
  148. if !isSuccess {
  149. WHToast.showMessage("数据查询失败,原因:\(er?.retMsg ?? "查询超时")", duration: ToastTimer, finishHandler: {})
  150. return
  151. }
  152. /// 数据
  153. self.columnHeaders = objs?.first?.columns.sorted(by: { (obj1, obj2) -> Bool in
  154. return obj1.orderindex<obj2.orderindex
  155. }).map({ (obj) -> String in
  156. return obj.columntitle.replacingOccurrences(of: "\\n", with: "\n")
  157. }) ?? []
  158. }
  159. group.leave()
  160. }
  161. group.notify(queue: .main) {
  162. /// 结束下拉刷新
  163. self.mainScrollView.endRefreshing()
  164. /// stopAnimating
  165. self._anim?.stopAnimating()
  166. }
  167. }
  168. }