| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- //
- // PositionSpotFutureDetailViewController.swift
- // MTP2_iOS
- //
- // Created by Muchinfo on 2021/1/6.
- // Copyright © 2021 Muchinfo. All rights reserved.
- //
- import UIKit
- import WHToast
- import GTMRefresh
- /// 期货头寸、期货头寸-明细视图容器控制类
- class PositionSpotFutureDetailViewController: BaseCollectionViewController {
- // MARK: - 属性列表
- /// 主滚动视图
- @IBOutlet weak var mainScrollView: UIScrollView!
- /// 现货头寸明细
- var exposureSpot: MoExposureSpot?
- /// 期货头寸明细
- var hedgePosition: MoExposureHedgePosition?
- /// 操作类型
- var operatorType: OperatorType = .cashFlow
- /// 明细数据信息
- var spotDetails: [MoExposureSpot] = [] {
- didSet {
- /// 左边数据
- leftDatas = spotDetails.map { (obj) -> String in
- /// 合同编号和采购销售名称
- return "\(obj.createtime.date(formatter: "yyyy-MM-dd HH:mm:ss")?.getString(formatter: "yyyyMMdd HH:mm") ?? "--")"+"\n\(obj.relatedno)"
- }
- /// 右边数据
- rightDatas = spotDetails.map { (obj) -> [String] in
- return ["\(obj.recordname)",
- "\(obj.wrstandardname)",
- "\(obj.qty.toUpString())\(obj.enumdicname.isBlank())"]
- }
- /// 刷新右侧列表数据
- rightTableView.reloadData()
- /// 无数据按钮
- noDataButton.isHidden = spotDetails.count != 0
- }
- }
-
- /// 期货明细
- var hedgePositionDetails: [MoExposureHedgePositionDetail] = [] {
- didSet {
- /// 左边数据
- leftDatas = hedgePositionDetails.map { (obj) -> String in
- /// 合同编号和采购销售名称
- return "\(obj.tradetime.date(formatter: "yyyy-MM-dd HH:mm:ss")?.getString(formatter: "yyyyMMdd HH:mm") ?? "--")"+"\n\(obj.goodsname)"
- }
- /// 右边数据
- rightDatas = hedgePositionDetails.map { (obj) -> [String] in
- return ["\(obj.buyorsell == .BUY ? "买" : "卖")",
- "\(obj.channelbuildtype == .BUILDTYPE_OPEN ? "开" : "平")",
- "\(obj.tradeqty.toUpString())手"]
- }
- /// 刷新右侧列表数据
- rightTableView.reloadData()
- /// 无数据按钮
- noDataButton.isHidden = hedgePositionDetails.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()
- /// 不能选中
- canSelected = false
- /// 下拉刷新
- 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 else { return }
-
- /// startAnimating
- _anim?.startAnimating()
- /// group
- let group = DispatchGroup()
- /// 现货明细
- if operatorType == .cashFlow, let obj = exposureSpot {
- /// 清空数据
- spotDetails = []
- /// group
- group.enter()
- /// 查询现货头寸明细数据
- spotManager.queryExposureSpotDetail(wrstandardid: obj.wrstandardid) { (isSuccess, er, objs) in
- DispatchQueue.main.async {
- /// 查询失败
- if !isSuccess {
- self.spotDetails = []
- WHToast.showMessage("现货头寸明细数据查询失败,原因:\(er?.retMsg ?? "查询超时")", duration: ToastTimer, finishHandler: {})
- return
- }
- /// 数据
- self.spotDetails = objs ?? []
- }
- group.leave()
- }
- } else if let obj = hedgePosition { /// 期货明细
- /// 清空数据
- hedgePositionDetails = []
- /// group
- group.enter()
- spotManager.queryExposureHedgePositionDetail(goodsId: obj.goodsid) { (isSuccess, er, objs) in
- DispatchQueue.main.async {
- /// 查询失败
- if !isSuccess {
- WHToast.showMessage("期货头寸明细数据查询失败,原因:\(er?.retMsg ?? "查询超时")", duration: ToastTimer, finishHandler: {})
- return
- }
- /// 数据
- self.hedgePositionDetails = objs ?? []
- }
- group.leave()
- }
- }
-
- /// key
- let key = operatorType == .cashFlow ? "table_mobile_exposure_spotposition_detail" : "table_mobile_exposure_futuresposition_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()
- }
- }
- }
|