| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368 |
- //
- // HedgePlanViewController.swift
- // MTP2_iOS
- //
- // Created by Muchinfo on 2021/1/2.
- // Copyright © 2021 Muchinfo. All rights reserved.
- //
- import UIKit
- import JXSegmentedView
- import IBAnimatable
- import WHToast
- import GTMRefresh
- import NVActivityIndicatorView
- /// 套保计划视图容器控制类
- class HedgePlanViewController: BaseCollectionViewController {
- // MARK: - 属性列表
- /// 新增合同按钮
- @IBOutlet weak var new: UIBarButtonItem!
- /// 主滚动视图
- @IBOutlet weak var mainScrollView: UIScrollView!
- /// 客户资料数据
- var plans: [MoHedgePlan] = [] {
- didSet {
- /// 左边数据
- leftDatas = plans.map { (obj) -> String in
- /// 计划类型/\n计划名称
- return obj.contracttype.description+"\n\(obj.hedgeplanno)"
- }
- /// 右边数据
- rightDatas = plans.map { (obj) -> [String] in
- return ["\(obj.deliverygoodsname)\n\(obj.wrstandardname)",
- "\(obj.convertfactor.toString(reserve: 2, false))\n\(obj.planqty)\(obj.wrunitidame)",
- "\(obj.tradeusername)\n\(obj.hedgeplanstatus.description)",
- obj.currencyname]
- }
- /// 刷新右侧列表数据
- rightTableView.reloadData()
- /// 无数据按钮
- noDataButton.isHidden = plans.count != 0
- }
- }
-
- /// 类别
- var roleTitles: [String] {
- get {
- var titles: [String] = []
- /// 权限控制
- guard let commonManager = MTP2BusinessCore.shared.commonManager else {
- return titles
- }
- if commonManager.isContainTraderMenu(key: "client_hedgeplan_unsubmit") {
- titles.append("未提交")
- }
- if commonManager.isContainTraderMenu(key: "client_hedgeplan_unaduit") {
- titles.append("待审核")
- }
- if commonManager.isContainTraderMenu(key: "client_hedgeplan_inprogress") {
- titles.append("执行中")
- }
- return titles
- }
- }
-
- // MARK: - 生命周期
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view.
- }
-
- /// UI界面初始化
- override func buildView() {
- super.buildView()
-
- /// addLoadingView
- addLoadingView()
- /// 需要返回按钮
- addBackBarButtonItem(false)
- }
-
- override func loadView() {
- super.loadView()
-
- /// 判断其权限控制
- guard let commonManager = MTP2BusinessCore.shared.commonManager else { return }
- /// 没有新增套保计划权限
- if !commonManager.isContainTraderMenu(key: "client_hedgeplan_add") {
- self.navigationItem.rightBarButtonItem?.image = nil
- self.navigationItem.rightBarButtonItem?.isEnabled = false
- } else {
- self.navigationItem.rightBarButtonItem?.image = UIImage(named: "new_contract")
- self.navigationItem.rightBarButtonItem?.isEnabled = true
- }
-
- /// titles
- dataSource.titles = roleTitles
- segmentedView.dataSource = dataSource
- segmentedView.reloadData()
-
- /// 操作回调
- operatorBlock = { (_ type: OperatorType, _ takeInfo: Any?, _ row: Int?) in
- if type == .delete, let index = row {
- /// 待提交状态下的套保计划删除操作
- self.doHedgePlanOperator(3, self.plans[index])
- }
- }
-
- /// 分页切换回调
- segmentBlock = { (_ index: Int, _ segment: JXSegmentedView) in
- switch self.roleTitles[index] {
- case "未提交": /// 未提交
- self.queryHedgePlans("0,6")
- case "待审核": /// 待审核
- self.queryHedgePlans("1,4")
- default: /// 查询全部
- self.queryHedgePlans("2")
- }
- self.selectedIndex = nil
- }
-
- /// 请求数据
- if roleTitles.count != 0 {
- /// 添加下拉刷新控件
- mainScrollView.gtm_addRefreshHeaderView(refreshHeader: DefaultGTMRefreshHeader()) {
- switch self.roleTitles[self.segmentedView.selectedIndex] {
- case "未提交":
- /// 未提交
- self.queryHedgePlans("0,6")
- case "待审核":
- /// 待审核
- self.queryHedgePlans("1,4")
- default:
- /// 执行中
- self.queryHedgePlans("2")
- }
- self.selectedIndex = nil
- }
- /// 默认选中第一个
- segmentedView.defaultSelectedIndex = 0
- segmentedView.delegate?.segmentedView(segmentedView, didSelectedItemAt: 0)
- }
- }
-
- // MARK: - 接口请求
- /// 查询套保计划
- /// - Parameter status: 套保计划状态 - 0:未提交 1:待审核 2:执行中 3:正常完结 4:审核拒绝 5:异常完结 6:已撤销
- fileprivate func queryHedgePlans(_ status: String) {
- /// 异常
- guard let planManager = MTP2BusinessCore.shared.planManager,
- let commonManager = MTP2BusinessCore.shared.commonManager else { return }
- /// group
- let group = DispatchGroup()
- /// startAnimating
- _anim?.startAnimating()
-
- /// enter
- group.enter()
- planManager.queryHedgePlan(status: status) { isComplete, er, objs in
- DispatchQueue.main.async {
- /// 查询失败
- if !isComplete {
- self.plans = []
- WHToast.showMessage("数据查询失败,原因:\(er?.retMsg ?? "请求超时")", duration: 1.5, finishHandler: {})
- return
- }
- /// 数据赋值
- self.plans = objs ?? []
- }
- group.leave()
- }
-
- /// 查询列头
- group.enter()
- commonManager.queryTableDefine(tableKey: "table_mobile_hedgeplan") { isComplete, er, objs in
- DispatchQueue.main.async {
- /// 查询失败
- if !isComplete {
- WHToast.showMessage("数据查询失败,原因:\(ErrorUtils.desc(er?.retCode))", duration: 1.5, 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) {
- /// stopAnimating
- self._anim?.stopAnimating()
- /// endRefreshing
- self.mainScrollView.endRefreshing()
- }
- }
-
- /// 套保计划取消提交
- /// - Parameters:
- /// - operateType: operateType
- /// - hedgePlan: hedgePlan
- fileprivate func doHedgePlanOperator(_ operateType: Int, _ hedgePlan: MoHedgePlan?) {
- /// 异常
- guard let planManager = MTP2BusinessCore.shared.planManager,
- let obj = hedgePlan else { return }
-
- /// id
- let id = Int(obj.hedgeplanid)
- /// 开启Loading
- NVActivityIndicatorPresenter.sharedInstance.startAnimating(animActivityData("请求中..."))
- /// 发送请求
- planManager.requestErmcpHedgePlan(hedgePlanID: id, hedgePlanNo: nil, contractType: nil, deliveryGoodsID: nil, productType: nil, spotGoodsDesc: nil, planQty: obj.planqty, convertFactor: obj.convertfactor, planTime: nil, operateType: 3, accountid: nil, wrstandardID: nil, remark: nil, tradeuserid: nil, currencyid: 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: {
- /// 刷新数据
- self.mainScrollView.triggerRefreshing()
- })
- }
- }
- }
-
- // MARK: - UIScrollViewDegelate
- override func scrollViewDidScroll(_ scrollView: UIScrollView) {
- super.scrollViewDidScroll(scrollView)
- /// 设置滚动位置
- headerCollectionView.contentOffset.x = scrollView.contentOffset.x
- /// 左侧 防止边界溢出
- if scrollView.contentOffset.x<=0 {
- headerCollectionView.contentOffset.x = 0.0
- }
- if let index = selectedIndex,
- index.isExpland,
- index.row < rightTableView.visibleCells.count,
- let cell = rightTableView.visibleCells[index.row] as? RightCell {
- cell.stackView.right = self.view.right-12.0-leftTableView.width+headerCollectionView.contentOffset.x
- cell.stackView.left = rightTableView.left+12.0+headerCollectionView.contentOffset.x
- }
- }
-
- // 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.
- /// 客户详情信息
- if segue.identifier == "ShowHedgePlanDetail",
- let plan = segue.destination as? HedgePlanDetailViewController,
- let row = selectedIndex?.row {
- /// 审核 详情 撤销
- plan.hedgePlan = plans[row]
- switch (sender as? UIButton)?.currentTitle {
- case "审核":
- plan.title = "审核"
- plan.operatorType = .aduit
- case "撤销":
- plan.title = "撤销"
- plan.operatorType = .cancel
- default:
- plan.title = "套保计划详情"
- plan.operatorType = .detail
- }
- plan.popBlock = { (_ takeInfo: Any?) in
- self.mainScrollView.triggerRefreshing()
- }
- } else if segue.identifier == "ShowNewHedgePlan",
- let new = segue.destination as? NewHedgePlanViewController,
- let row = selectedIndex?.row {
- /// 新增、修改
- if let _ = sender as? UIBarButtonItem {
- new.operatorType = .add
- } else {
- new.operatorType = .update
- new.hedgePlan = plans[row]
- }
- new.popBlock = { (_ takeInfo: Any?) in
- self.mainScrollView.triggerRefreshing()
- }
- }
- }
- }
- class HedgePlanCell: RightCell {
- /// 审核
- @IBOutlet weak var aduit: UIButton!
- /// 重新提交
- @IBOutlet weak var reSubmit: UIButton!
- /// 修改
- @IBOutlet weak var update: UIButton!
- /// 撤销
- @IBOutlet weak var cancel: UIButton!
- /// 删除
- @IBOutlet weak var delete: UIButton!
- /// 详情
- @IBOutlet weak var detail: UIButton!
- /// model
- override var model: [String]? {
- didSet {
- /// 异常
- guard let commonManager = MTP2BusinessCore.shared.commonManager,
- let row = rowNum,
- let superVC = self.superController() as? HedgePlanViewController,
- row <= superVC.plans.count-1 else {
- return
- }
-
- let obj = superVC.plans[row]
- /// 判断其权限控制
- switch obj.hedgeplanstatus {
- case .unSubmitted:
- /// 未提交
- update.isHidden = !commonManager.isContainTraderMenu(key: "client_hedgeplan_update")
- cancel.isHidden = true
- aduit.isHidden = true
- reSubmit.isHidden = true
- delete.isHidden = false
- case .reviewed:
- /// 待审核
- update.isHidden = true
- cancel.isHidden = !commonManager.isContainTraderMenu(key: "client_hedgeplan_cancel")
- aduit.isHidden = !commonManager.isContainTraderMenu(key: "client_hedgeplan_check")
- reSubmit.isHidden = true
- delete.isHidden = true
- case .withDrawn, .reviewRejected:
- /// 已撤销 审核拒绝
- reSubmit.isHidden = !commonManager.isContainTraderMenu(key: "client_hedgeplan_recommit")
- update.isHidden = true
- aduit.isHidden = true
- cancel.isHidden = true
- delete.isHidden = obj.hedgeplanstatus != .withDrawn
- case .progress:
- /// 执行中
- update.isHidden = true
- cancel.isHidden = true
- aduit.isHidden = true
- reSubmit.isHidden = true
- delete.isHidden = true
- default:
- break
- }
- }
- }
- // MARK: - 交互相关
- /// onButtonPressed
- /// - Parameter sender: sender
- @IBAction fileprivate func onButtonPressed(_ sender: UIControl) {
- switch sender {
- case delete:
- /// 删除
- if let bk = operatorBlock { bk(OperatorType.delete, model, rowNum) }
- default: break
- }
- }
- }
|