// // HisExposuresViewController.swift // MTP2_iOS // // Created by Muchinfo on 2021/2/7. // Copyright © 2021 Muchinfo. All rights reserved. // import UIKit import WHToast import AAInfographics /// 历史敞口数据信息视图容器控制类 class HisExposuresViewController: BaseViewController { // MARK: - 属性列表 /// 属性列表 @IBOutlet weak var tableView: UITableView! /// 历史敞口数据 var hisExposures: [MoHisExposure] = [] { didSet { /// 刷新列表数据 tableView.reloadData() /// 无数据按钮 noDataButton.isHidden = hisExposures.count != 0 } } /// CellIdentifier let CellIdentifier = "HisExposures_Cell" // MARK: - 生命周期 override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. /// loding addLoadingView() } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) let value = UIInterfaceOrientation.portrait.rawValue UIDevice.current.setValue(value, forKey: "orientation") } override func didMove(toParent parent: UIViewController?) { super.didMove(toParent: parent) if parent != nil { /// 获取数据 requestHisExposures() } } // MARK: - 接口请求 fileprivate func requestHisExposures() { /// 异常 guard let spotManager = MTP2BusinessCore.shared.spotManager else { return } /// startAnimating _anim?.startAnimating() /// 查询历史敞口数据信息 spotManager.queryHisExposure(lastNum: -1) { (isSuccess, er, objs) in DispatchQueue.main.async { /// stopAnimating self._anim?.stopAnimating() /// 查询失败 if !isSuccess { self.hisExposures = [] WHToast.showMessage("数据查询失败,原因:\(er?.retMsg ?? "查询超时")", duration: ToastTimer, finishHandler: {}) return } self.hisExposures = objs ?? [] } } } } // MARK: - UITableViewDelegate, UITableViewDataSource extension HisExposuresViewController: UITableViewDelegate, UITableViewDataSource { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return hisExposures.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: CellIdentifier, for: indexPath) as! HisExposuresCell cell.model = hisExposures[indexPath.row] return cell } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { return 220.0 } } // MARK: - HisExposuresCell class HisExposuresCell: BaseTableViewCell { /// 套保品种 @IBOutlet weak var middlegoodsname: UILabel! /// 图表数据 @IBOutlet weak var lineChartView: UIView! { didSet { lineChartView.addSubview(chart) } } /// 折现图 lazy var chart: AAChartView = { $0.isSeriesHidden = true $0.scrollEnabled = true $0.frame = CGRect(origin: CGPoint.zero, size: lineChartView.frame.size) return $0 }(AAChartView()) override var model: MoHisExposure? { didSet { /// 异常 guard let obj = model else { return } /// 套保名称和单位 middlegoodsname.text = "\(obj.middlegoodsname) (\(obj.enumdicname))" let dates: [String] = obj.data.map { (data) -> String in return data.reckondate.count > 7 ? (data.reckondate.substing(range: 2..<8) ?? "--") : data.reckondate } /// 总敞口 let totalexposures: [Double] = obj.data.map { (data) -> Double in return (Double(data.totalexposure.toUpString()) ?? 0.0) } /// 应套保敞口 let needhedgeexposoures: [Double] = obj.data.map { (data) -> Double in return (Double(data.needhedgeexposoure.toUpString()) ?? 0.0) } /// totalMax let totalMax = totalexposures.sorted { a, b in return a>b }.first ?? 0.0 /// totalMin let totalMin = totalexposures.sorted { a, b in return ab }.first ?? 0.0 /// needMin let needMin = needhedgeexposoures.sorted { a, b in return a