HedgeDetailViewController.swift 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //
  2. // HedgeDetailViewController.swift
  3. // MTP2_iOS
  4. //
  5. // Created by Muchinfo on 2021/1/22.
  6. // Copyright © 2021 Muchinfo. All rights reserved.
  7. //
  8. import UIKit
  9. import JXSegmentedView
  10. import GTMRefresh
  11. import WHToast
  12. import NVActivityIndicatorView
  13. /// 套保品种详情视图容器控制类
  14. class HedgeDetailViewController: BaseViewController {
  15. // MARK: - 属性列表
  16. /// 状态视图
  17. @IBOutlet weak var statusView: UIView!
  18. /// 状态
  19. @IBOutlet weak var ststus: UILabel!
  20. /// 状态
  21. @IBOutlet weak var title2: UILabel!
  22. /// 列表
  23. @IBOutlet weak var tableView: UITableView!
  24. /// 套保品种信息
  25. var middleGoods: MoErmcpMiddleGoodsDetail?
  26. /// CellIdentifier
  27. let CellIdentifier = "MiddleGoodsChangeLog_Cell"
  28. /// 变更记录
  29. var logs: [MoMiddleGoodsChangeLogs] = [] {
  30. didSet {
  31. /// 刷新列表数据
  32. self.tableView.reloadData()
  33. /// noDataButton
  34. self.noDataButton.isHidden = !(logs.count == 0)
  35. }
  36. }
  37. // MARK: - 生命周期
  38. override func viewDidLoad() {
  39. super.viewDidLoad()
  40. // Do any additional setup after loading the view.
  41. }
  42. override func loadView() {
  43. super.loadView()
  44. /// 显示详情信息
  45. showMiddleGoodsDetail()
  46. }
  47. /// UI界面初始化
  48. override func buildView() {
  49. super.buildView()
  50. /// loding
  51. addLoadingView()
  52. /// 添加下拉刷新控件
  53. tableView.gtm_addRefreshHeaderView(refreshHeader: DefaultGTMRefreshHeader()) {
  54. /// 查询现货明细信息
  55. self.queryMiddleGoodsChangeLogs()
  56. }
  57. /// 查询现货明细信息
  58. queryMiddleGoodsChangeLogs()
  59. }
  60. /// 显示详情信息
  61. fileprivate func showMiddleGoodsDetail() {
  62. /// title2
  63. title2.text = "修改前套保比例\n修改后套保比例"
  64. /// 异常
  65. guard let obj = middleGoods?.mg else { return }
  66. /// 状态
  67. ststus.text = "套保品种:\(obj.middlegoodsname) (\(obj.enumdicname))"
  68. }
  69. // MARK: - 接口请求
  70. /// 查询套保品种变更记录(菜单:套保品种/商品详情/变更记录)
  71. fileprivate func queryMiddleGoodsChangeLogs() {
  72. /// 异常
  73. guard let planManager = MTP2BusinessCore.shared.planManager,
  74. let obj = middleGoods?.mg else {
  75. return
  76. }
  77. /// startAnimating
  78. _anim?.startAnimating()
  79. /// 查询详情
  80. planManager.queryMiddleGoodsChangeLog(middlegoodsid: obj.middlegoodsid) { (isComplete, error, objs) in
  81. DispatchQueue.main.async {
  82. /// stopAnimating
  83. self._anim?.stopAnimating()
  84. /// endRefreshing
  85. self.tableView.endRefreshing()
  86. if !isComplete {
  87. self.logs = []
  88. WHToast.showMessage("变更记录查询失败", duration: 1.5, finishHandler: {})
  89. return
  90. }
  91. /// 刷新数据
  92. self.logs = objs?.sorted(by: { (obj1, obj2) -> Bool in
  93. return obj1.updatetime>obj2.updatetime
  94. }) ?? []
  95. }
  96. }
  97. }
  98. }
  99. // MARK: - 左边 UITableViewDelegate & UITableViewDataSource
  100. extension HedgeDetailViewController: UITableViewDelegate, UITableViewDataSource {
  101. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  102. return self.logs.count
  103. }
  104. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  105. let cell = tableView.dequeueReusableCell(withIdentifier: CellIdentifier, for: indexPath) as! MiddleGoodsChangeLogCell
  106. cell.model = self.logs[indexPath.row]
  107. return cell
  108. }
  109. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  110. return 55.0
  111. }
  112. }
  113. class MiddleGoodsChangeLogCell: BaseTableViewCell<MoMiddleGoodsChangeLogs> {
  114. /// title1
  115. @IBOutlet weak var title1: UILabel!
  116. /// title2
  117. @IBOutlet weak var title2: UILabel!
  118. /// title3
  119. @IBOutlet weak var title3: UILabel!
  120. /// title4
  121. @IBOutlet weak var title4: UILabel!
  122. /// 数据
  123. override var model: MoMiddleGoodsChangeLogs? {
  124. didSet {
  125. /// 异常
  126. guard let obj = model else { return }
  127. /// 更新时间
  128. title1.text = obj.updatetime.toDateString(formatter: "MM-dd HH:mm")
  129. /// 变更前
  130. title2.text = "\(obj.beforevalue*100.0)% \n\(obj.aftervalue*100.0)%"
  131. /// 备注
  132. title3.text = "\(obj.logremark.isBlank())"
  133. /// 修改人
  134. title4.text = obj.applyname.isBlank()
  135. }
  136. }
  137. }