// // HedgePlanDetailViewController.swift // MTP2_iOS // // Created by Muchinfo on 2021/1/2. // Copyright © 2021 Muchinfo. All rights reserved. // import UIKit import IBAnimatable import WHToast import NVActivityIndicatorView import ActionSheetPicker_3_0 /// 套保计划详情视图容器控制类 class HedgePlanDetailViewController: BaseViewController { // MARK: - 属性列表 /// 状态视图 @IBOutlet weak var statusView: UIView! /// 状态标记 @IBOutlet weak var statusImage: UIImageView! /// 状态 @IBOutlet weak var ststus: UILabel! /// 计划类型 @IBOutlet weak var hedgePlanType: UILabel! /// 计划名称 @IBOutlet weak var hedgePlanName: UILabel! /// 现货品种 @IBOutlet weak var goodsName: UILabel! /// 标仓系数 @IBOutlet weak var coefficient: UILabel! /// 计划量 @IBOutlet weak var planQty: UILabel! /// 审核时间 @IBOutlet weak var aduitTime: UILabel! /// 审核时间视图 @IBOutlet weak var aduitTimeView: UIView! /// 商品 @IBOutlet weak var wrstandard: UILabel! /// 审核人 @IBOutlet weak var aduiter: UILabel! /// 结算币种 @IBOutlet weak var currency: UIButton! /// 审核人视图 @IBOutlet weak var aduiterView: UIView! /// 备注 @IBOutlet weak var remark: UILabel! /// 交易用户 @IBOutlet weak var trader: UIButton! /// 审核意见 @IBOutlet weak var aduitOpinion: AnimatableTextField! /// 审核意见 @IBOutlet weak var aduitOpinionView: UIView! { didSet { aduitOpinionView.isHidden = true } } /// 操作视图 @IBOutlet weak var operatorView: UIView! { didSet { operatorView.isHidden = true } } /// 审核通过 @IBOutlet weak var approved: UIButton! { didSet { approved.isHidden = true } } /// 撤销 @IBOutlet weak var cancel: UIButton! { didSet { cancel.isHidden = true } } /// 审核拒绝 @IBOutlet weak var refused: UIButton! { didSet { refused.isHidden = true } } /// img1 @IBOutlet weak var img1: UIImageView! /// img2 @IBOutlet weak var img2: UIImageView! /// 套保计划 var hedgePlan: MoHedgePlan? /// 操作类型 var operatorType: OperatorType = .detail /// 币种枚举信息 var units: [MoEnum] { return try! DatabaseHelper.getEnumInfo(enumdiccode: "paycurrency") ?? [] } /// 选中的币种 var moUnit: MoEnum? { didSet { /// 异常 guard let obj = moUnit else { return } currency.setTitle(obj.enumdicname, for: .normal) currency.setTitleColor(.hex333(), for: .normal) } } /// 交易员用户信息 var traders: [MoMgrLoginUser] = [] /// 选中的交易员用户信息 var moTraderUser: MoMgrLoginUser? { didSet { /// 异常 guard let obj = moTraderUser else { return } trader.setTitle("\(obj.rolename)", for: .normal) trader.setTitleColor(.hex333(), for: .normal) } } // MARK: - 生命周期 override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. /// 输入框 moveView(views: [aduitOpinion]) } override func loadView() { super.loadView() /// 显示套保计划详细信息 showHedgePlanInfos() /// 查询交易用户信息 queryTraderLoginUsers() } /// 显示套保计划详细信息 fileprivate func showHedgePlanInfos() { /// 异常 guard let commonManager = MTP2BusinessCore.shared.commonManager, let obj = hedgePlan else { return } /// 计划类型 hedgePlanType.text = obj.contracttype.description /// 计划名称 hedgePlanName.text = obj.hedgeplanno.isBlank() /// 现货品种 goodsName.text = obj.deliverygoodsname.isBlank() /// 商品 wrstandard.text = obj.wrstandardname.isBlank() /// 标仓系数 coefficient.text = "\(obj.convertfactor.toString(reserve: 2, false))" /// 计划量 planQty.text = "\(obj.planqty.toString(reserve: 2, false))\(obj.wrunitidame)" /// 备注 remark.text = obj.remark.isBlank() /// 状态 ststus.text = obj.hedgeplanstatus.description ststus.textColor = .fromHex(rgbValue: obj.hedgeplanstatus == .progress ? 0x4DBB33 : 0xFE9A68) /// 视图颜色 statusView.backgroundColor = obj.hedgeplanstatus == .progress ? .D3FFE1() : .FFEBDD() /// 标记 statusImage.image = UIImage(named: obj.hedgeplanstatus == .progress ? "status_success" : "clock") /// 币种信息 moUnit = units.first(where: {$0.enumitemname == obj.currencyid}) /// 判断其权限控制 switch obj.hedgeplanstatus { case .progress, .unSubmitted: /// 执行中 approved.isHidden = true cancel.isHidden = true refused.isHidden = true aduitOpinionView.isHidden = true aduiterView.isHidden = true aduitTimeView.isHidden = true currency.isUserInteractionEnabled = false trader.isUserInteractionEnabled = false img1.isHidden = true img2.isHidden = true default: switch operatorType { case .cancel: /// 撤销操作 approved.isHidden = true cancel.isHidden = !commonManager.isContainTraderMenu(key: "client_hedgeplan_cancel") refused.isHidden = true aduitOpinionView.isHidden = false operatorView.isHidden = false aduiterView.isHidden = true aduitTimeView.isHidden = true img1.isHidden = false img2.isHidden = false case .aduit: /// 审核操作 approved.isHidden = !commonManager.isContainTraderMenu(key: "client_hedgeplan_check") cancel.isHidden = true refused.isHidden = !commonManager.isContainTraderMenu(key: "client_hedgeplan_check") aduitOpinionView.isHidden = false operatorView.isHidden = false aduiterView.isHidden = true aduitTimeView.isHidden = true img1.isHidden = false img2.isHidden = false default: /// 详情 approved.isHidden = true cancel.isHidden = true refused.isHidden = true aduitOpinionView.isHidden = true operatorView.isHidden = true aduiterView.isHidden = false aduitTimeView.isHidden = false img1.isHidden = true img2.isHidden = true currency.isUserInteractionEnabled = false trader.isUserInteractionEnabled = false } } } // MARK: - 交互相关 /// onButtonPressed /// - Parameter sender: sender @IBAction fileprivate func onButtonPressed(_ sender: UIControl) { switch sender { case currency: /// 币种 if units.count != 0 { ActionSheetStringPicker.show(withTitle: "请选择结算币种", rows: units.map({ (obj) -> String in return obj.enumdicname }), initialSelection: 0, doneBlock: { picker, value, index in self.moUnit = self.units[value] }, cancel: { picker in return }, origin: sender) } else { WHToast.showMessage("没有对应的结算币种信息", duration: 1.5, finishHandler: {}) } case trader: //// 交易用户 if traders.count != 0 { ActionSheetStringPicker.show(withTitle: "请选择交易用户", rows: traders.map({ (obj) -> String in return "\(obj.rolename)" }), initialSelection: 0, doneBlock: { picker, value, index in self.moTraderUser = self.traders[value] }, cancel: { picker in return }, origin: sender) } else { WHToast.showMessage("请先去添加交易用户信息", duration: 1.5, finishHandler: {}) } case cancel: /// 撤销 self.doCancelHedgePlanOperator(5) case refused: /// 拒绝 self.doHedgePlanOperator(5) default: /// 审核通过 self.doHedgePlanOperator(4) } } // MARK: - 接口请求 /// 查询交易用户数据信息 fileprivate func queryTraderLoginUsers() { /// 异常 guard let accountManager = MTP2BusinessCore.shared.accountManager else { return } /// 查询交易用户数据信息 accountManager.queryAccMgrLoginUser(querytype: 2) { isComplete, er, objs in DispatchQueue.main.async { /// 查询失败 if !isComplete { self.traders = [] WHToast.showMessage("数据查询失败,原因:\(er?.retMsg ?? "请求超时")", duration: 1.5, finishHandler: {}) return } self.traders = objs ?? [] /// 交易用户信息 if let id = self.hedgePlan, self.traders.count != 0 { self.moTraderUser = objs?.first(where: {$0.roleid == id.tradeuserid}) } } } } /// 套保计划操作提交 /// - Parameter operateType: 操作类型-1:保存草稿2:提交申请3:删除4审核通过5审核拒绝 fileprivate func doHedgePlanOperator(_ operateType: Int) { /// 异常 guard let planManager = MTP2BusinessCore.shared.planManager, let obj = hedgePlan, check(operateType) else { return } /// 备注 /// id let id = Int(obj.hedgeplanid) /// 交易用户id let tradeuserid = moTraderUser?.roleid /// 币种ID let currencyid = moUnit?.enumitemname /// 计划量 let planQty = obj.planqty /// 标仓系数 let factor = obj.convertfactor /// 计划类型 let type = obj.contracttype.rawValue /// deliverygoodsid let goodsid = obj.deliverygoodsid /// 开启Loading NVActivityIndicatorPresenter.sharedInstance.startAnimating(animActivityData("请求中...")) /// 删除请求 planManager.requestErmcpHedgePlan(hedgePlanID: id, hedgePlanNo: nil, contractType: type, deliveryGoodsID: goodsid, productType: nil, spotGoodsDesc: nil, planQty: planQty, convertFactor: factor, planTime: nil, operateType: operateType, accountid: nil, wrstandardID: nil, remark: aduitOpinion.text, tradeuserid: tradeuserid, currencyid: currencyid) { complete, er, rsp in DispatchQueue.main.async { /// dismisss loding..... NVActivityIndicatorPresenter.sharedInstance.stopAnimating() /// 失败 if !complete { WHToast.showMessage("请求失败,原因:\(ErrorUtils.desc(er?.retCode))", duration: 2.0, finishHandler: {}) return } WHToast.showSuccess(withMessage: "请求成功", duration: 2.0, finishHandler: { /// 执行回调 if let bk = self.popBlock { bk(nil) } /// 返回商城视图 self.navigationController?.popViewController(animated: true) }) } } } /// 套保计划操作提交 /// - Parameter operateType: 操作类型-1:保存草稿2:提交申请3:删除4审核通过5审核拒绝 fileprivate func doCancelHedgePlanOperator(_ operateType: Int) { /// 异常 guard let planManager = MTP2BusinessCore.shared.planManager, let obj = hedgePlan, check(operateType) else { return } /// 开启Loading NVActivityIndicatorPresenter.sharedInstance.startAnimating(animActivityData("请求中...")) /// 删除 planManager.hedgePlanOperate(hedgePlanID: Int(obj.hedgeplanid), operateType: operateType, remark: nil, info: nil) { complete, er, rsp in DispatchQueue.main.async { /// dismisss loding..... NVActivityIndicatorPresenter.sharedInstance.stopAnimating() /// 失败 if !complete { WHToast.showMessage("请求失败,原因:\(ErrorUtils.desc(er?.retCode))", duration: 2.0, finishHandler: {}) return } WHToast.showSuccess(withMessage: "请求成功", duration: 2.0, finishHandler: { /// 执行回调 if let bk = self.popBlock { bk(nil) } /// 返回商城视图 self.navigationController?.popViewController(animated: true) }) } } } /// 合规性校验 /// - Returns: Bool /// - Parameter operateType: 操作类型-1:保存草稿2:提交申请3:删除4审核通过5审核拒绝 fileprivate func check(_ operateType: Int) -> Bool { /// 审核通过时必须校验 if operateType != 4 { return true } /// 请选择交易用户 guard let _ = moTraderUser else { WHToast.showMessage("请选择交易用户", duration: 1.5, finishHandler: {}) return false } /// 请选择结算币种 guard let _ = moUnit else { WHToast.showMessage("请选择结算币种", duration: 1.5, finishHandler: {}) return false } return true } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { // Get the new view controller using segue.destination. // Pass the selected object to the new view controller. } */ }