| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- //
- // ExposureSpotFutureDetailViewController.swift
- // MTP2_iOS
- //
- // Created by Muchinfo on 2021/1/6.
- // Copyright © 2021 Muchinfo. All rights reserved.
- //
- import UIKit
- import WHToast
- import GTMRefresh
- /// 实时敞口-现货、期货-明细视图容器控制类
- class ExposureSpotFutureDetailViewController: BaseCollectionViewController {
- // MARK: - 属性列表
- /// 套保品种
- @IBOutlet weak var hedgeType: UILabel!
- /// 主滚动视图
- @IBOutlet weak var mainScrollView: UIScrollView!
- /// 实时敞口数据
- var realExposure: MoRealExposure?
- /// 操作类型
- var operatorType: OperatorType = .cashFlow
- /// 敞口现货明细
- var exposureDetails: [MoExposureDetail] = [] {
- didSet {
- /// 左边数据
- leftDatas = exposureDetails.map { (obj) -> String in
- /// 当现货品种数量为0时,是套保系数变更导致,需在4个类型后面加“(系数变更)”,如 采购合同(系数变更),并将现货品种的数量0显示成“--”
- let info = obj.qty == 0 ? "(系数变更)" : ""
- /// 合同编号和采购销售名称
- return "\(obj.createtime.date(formatter: "yyyy-MM-dd HH:mm:ss")?.getString(formatter: "MMdd HH:mm") ?? "--")"+"\n\(obj.contracttype.description)\(obj.logtype == .HedgePlan ? "计划" : "合同")\(info)"
- }
- /// 右边数据
- rightDatas = exposureDetails.map { (obj) -> [String] in
- /// 数量为0 显示-- 当现货品种数量为0时,是套保系数变更导致,需在4个类型后面加“(系数变更)”,如 采购合同(系数变更),并将现货品种的数量0显示成“--”
- let qty = obj.qty == 0 ? "--" : "\(obj.qty.toUpString())\(obj.enumdicname.isBlank())"
- return ["\(obj.wrstandardname)\n\(qty)",
- "\(obj.changeQty.toUpString())\(obj.mgunitidname)",
- obj.relateNo,
- obj.convertratio.toUpString()]
- }
- /// 刷新右侧列表数据
- rightTableView.reloadData()
- /// 无数据按钮
- noDataButton.isHidden = exposureDetails.count != 0
- }
- }
-
- /// 期货明细数据信息
- var positions: [MoRealtimeExposurePosition] = [] {
- didSet {
- /// 左边数据
- leftDatas = positions.map { (obj) -> String in
- /// 合同编号和采购销售名称
- return "\(obj.goodsname)\n\(obj.goodscode)"
- }
- /// 右边数据
- rightDatas = positions.map { (obj) -> [String] in
- return ["\(obj.ydqty.toUpString())\n\(obj.curqty.toUpString())",
- obj.diffqty.toUpString(),
- obj.diffhedgeqty.toUpString(),
- "\(obj.agreeunit)\n\(obj.convertratio.toUpString())"]
- }
- /// 刷新右侧列表数据
- rightTableView.reloadData()
- /// 无数据按钮
- noDataButton.isHidden = positions.count != 0
- }
- }
-
- // MARK: - 生命周期
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- /// 列头高度
- columnWidth = 100.0
- }
-
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view.
- /// 不需要返回按钮
- addBackBarButtonItem()
- /// 异常
- guard let obj = realExposure else { return }
- /// 不能选中
- canSelected = false
- /// 套保品种
- hedgeType.text = "套保品种:\(obj.middleGoodsName)(\(obj.middleGoodsCode))"
- /// 下拉刷新
- mainScrollView.gtm_addRefreshHeaderView(refreshHeader: DefaultGTMRefreshHeader()) {
- self.reloadData()
- }
- /// 刷新数据信息
- reloadData()
- }
-
- // MARK: - 接口请求
- /// 刷新数据信息
- /// - Parameter type: 类型
- fileprivate func reloadData() {
- /// 异常
- guard let commonManager = MTP2BusinessCore.shared.commonManager,
- let spotManager = MTP2BusinessCore.shared.spotManager,
- let obj = realExposure else { return }
-
- /// startAnimating
- _anim?.startAnimating()
-
- let group = DispatchGroup()
- /// 现货明细
- if operatorType == .cashFlow {
- /// 清空数据
- exposureDetails = []
- /// group
- group.enter()
- /// 查询实时敞口现货明细数据
- spotManager.queryExposureDetail(middleGoodsId: obj.middleGoodsID) { (isSuccess, er, objs) in
- DispatchQueue.main.async {
- /// 查询失败
- if !isSuccess {
- WHToast.showMessage("现货明细数据查询失败,原因:\(er?.retMsg ?? "查询超时")", duration: ToastTimer, finishHandler: {})
- return
- }
- /// 数据
- self.exposureDetails = objs?.sorted(by: { (obj1, obj2) -> Bool in obj1.createtime>obj2.createtime }) ?? []
- }
- group.leave()
- }
- } else {
- /// 清空数据
- positions = []
- /// group
- group.enter()
- /// 查询实时敞口期货明细数据
- spotManager.queryRealtimeExposurePosition(middleGoodsId: obj.middleGoodsID) { (isSuccess, er, objs) in
- DispatchQueue.main.async {
- /// 查询失败
- if !isSuccess {
- WHToast.showMessage("期货明细数据查询失败,原因:\(er?.retMsg ?? "查询超时")", duration: ToastTimer, finishHandler: {})
- return
- }
- /// 数据
- self.positions = objs ?? []
- }
- group.leave()
- }
- }
-
- /// tablekey
- let key = operatorType == .cashFlow ? "table_mobile_exposure_spot_detail" : "table_mobile_exposure_futures_detail"
- group.enter()
- /// 查询列头信息
- commonManager.queryTableDefine(tableKey: key) { (isSuccess, er, objs) in
- DispatchQueue.main.async {
- /// 查询失败
- if !isSuccess {
- WHToast.showMessage("数据查询失败,原因:\(er?.retMsg ?? "查询超时")", duration: ToastTimer, finishHandler: {})
- return
- }
- /// 数据
- self.columnHeaders = objs?.first?.columns.sorted(by: { (obj1, obj2) -> Bool in
- return obj1.orderindex<obj2.orderindex
- }).map({ (obj) -> String in
- return obj.columntitle.replacingOccurrences(of: "\\n", with: "\n")
- }) ?? []
- }
- group.leave()
- }
-
- group.notify(queue: .main) {
- /// 结束下拉刷新
- self.mainScrollView.endRefreshing()
- /// stopAnimating
- self._anim?.stopAnimating()
- }
- }
- }
|