| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- //
- // 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<MoHisExposure> {
-
- /// 套保品种
- @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 a<b
- }.first ?? 0.0
- /// needMax
- let needMax = needhedgeexposoures.sorted { a, b in
- return a>b
- }.first ?? 0.0
- /// needMin
- let needMin = needhedgeexposoures.sorted { a, b in
- return a<b
- }.first ?? 0.0
-
- let chartModel = AAChartModel().chartType(.spline) /// 图表类型
- .animationType(.bounce) /// 动画类型
- .zoomType(.xy) /// 手势缩放
- .dataLabelsEnabled(false)
- .touchEventEnabled(false)
- .markerRadius(0.5)
- .yAxisMin(Swift.min(totalMin, needMin))
- .yAxisMax(Swift.max(totalMax, needMax))
- .xAxisGridLineWidth(1.0)
- .yAxisGridLineWidth(1.0)
- .legendEnabled(false) /// 是否启用图表的图例(图表底部的可点击的小圆点)
- .animationDuration(2) /// 动画时间
- .inverted(false) /// 是否翻转图形
- .tooltipValueSuffix("\(obj.enumdicname)") /// 浮动提示框单位后缀
- .colorsTheme(["#20CCF1","#FF6E47"]) /// 主题颜色数组
- .categories(dates)
- .markerSymbol(.circle)
- .markerSymbolStyle(.normal)
- .series([AASeriesElement().name("总敞口:").lineWidth(1.0).data(totalexposures),
- AASeriesElement().name("应套保敞口:").lineWidth(1.0).data(needhedgeexposoures)])
- chart.aa_drawChartWithChartModel(chartModel)
- }
- }
- }
|