HedgePlanDetailViewController.swift 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. //
  2. // HedgePlanDetailViewController.swift
  3. // MTP2_iOS
  4. //
  5. // Created by Muchinfo on 2021/1/2.
  6. // Copyright © 2021 Muchinfo. All rights reserved.
  7. //
  8. import UIKit
  9. import IBAnimatable
  10. import WHToast
  11. import NVActivityIndicatorView
  12. import ActionSheetPicker_3_0
  13. /// 套保计划详情视图容器控制类
  14. class HedgePlanDetailViewController: BaseViewController {
  15. // MARK: - 属性列表
  16. /// 状态视图
  17. @IBOutlet weak var statusView: UIView!
  18. /// 状态标记
  19. @IBOutlet weak var statusImage: UIImageView!
  20. /// 状态
  21. @IBOutlet weak var ststus: UILabel!
  22. /// 计划类型
  23. @IBOutlet weak var hedgePlanType: UILabel!
  24. /// 计划名称
  25. @IBOutlet weak var hedgePlanName: UILabel!
  26. /// 现货品种
  27. @IBOutlet weak var goodsName: UILabel!
  28. /// 标仓系数
  29. @IBOutlet weak var coefficient: UILabel!
  30. /// 计划量
  31. @IBOutlet weak var planQty: UILabel!
  32. /// 审核时间
  33. @IBOutlet weak var aduitTime: UILabel!
  34. /// 审核时间视图
  35. @IBOutlet weak var aduitTimeView: UIView!
  36. /// 商品
  37. @IBOutlet weak var wrstandard: UILabel!
  38. /// 审核人
  39. @IBOutlet weak var aduiter: UILabel!
  40. /// 结算币种
  41. @IBOutlet weak var currency: UIButton!
  42. /// 审核人视图
  43. @IBOutlet weak var aduiterView: UIView!
  44. /// 备注
  45. @IBOutlet weak var remark: UILabel!
  46. /// 交易用户
  47. @IBOutlet weak var trader: UIButton!
  48. /// 审核意见
  49. @IBOutlet weak var aduitOpinion: AnimatableTextField!
  50. /// 审核意见
  51. @IBOutlet weak var aduitOpinionView: UIView! {
  52. didSet {
  53. aduitOpinionView.isHidden = true
  54. }
  55. }
  56. /// 操作视图
  57. @IBOutlet weak var operatorView: UIView! {
  58. didSet {
  59. operatorView.isHidden = true
  60. }
  61. }
  62. /// 审核通过
  63. @IBOutlet weak var approved: UIButton! {
  64. didSet {
  65. approved.isHidden = true
  66. }
  67. }
  68. /// 撤销
  69. @IBOutlet weak var cancel: UIButton! {
  70. didSet {
  71. cancel.isHidden = true
  72. }
  73. }
  74. /// 审核拒绝
  75. @IBOutlet weak var refused: UIButton! {
  76. didSet {
  77. refused.isHidden = true
  78. }
  79. }
  80. /// img1
  81. @IBOutlet weak var img1: UIImageView!
  82. /// img2
  83. @IBOutlet weak var img2: UIImageView!
  84. /// 套保计划
  85. var hedgePlan: MoHedgePlan?
  86. /// 操作类型
  87. var operatorType: OperatorType = .detail
  88. /// 币种枚举信息
  89. var units: [MoEnum] {
  90. return try! DatabaseHelper.getEnumInfo(enumdiccode: "paycurrency") ?? []
  91. }
  92. /// 选中的币种
  93. var moUnit: MoEnum? {
  94. didSet {
  95. /// 异常
  96. guard let obj = moUnit else { return }
  97. currency.setTitle(obj.enumdicname, for: .normal)
  98. currency.setTitleColor(.hex333(), for: .normal)
  99. }
  100. }
  101. /// 交易员用户信息
  102. var traders: [MoMgrLoginUser] = []
  103. /// 选中的交易员用户信息
  104. var moTraderUser: MoMgrLoginUser? {
  105. didSet {
  106. /// 异常
  107. guard let obj = moTraderUser else { return }
  108. trader.setTitle("\(obj.rolename)", for: .normal)
  109. trader.setTitleColor(.hex333(), for: .normal)
  110. }
  111. }
  112. // MARK: - 生命周期
  113. override func viewDidLoad() {
  114. super.viewDidLoad()
  115. // Do any additional setup after loading the view.
  116. /// 输入框
  117. moveView(views: [aduitOpinion])
  118. }
  119. override func loadView() {
  120. super.loadView()
  121. /// 显示套保计划详细信息
  122. showHedgePlanInfos()
  123. /// 查询交易用户信息
  124. queryTraderLoginUsers()
  125. }
  126. /// 显示套保计划详细信息
  127. fileprivate func showHedgePlanInfos() {
  128. /// 异常
  129. guard let commonManager = MTP2BusinessCore.shared.commonManager, let obj = hedgePlan else { return }
  130. /// 计划类型
  131. hedgePlanType.text = obj.contracttype.description
  132. /// 计划名称
  133. hedgePlanName.text = obj.hedgeplanno.isBlank()
  134. /// 现货品种
  135. goodsName.text = obj.deliverygoodsname.isBlank()
  136. /// 商品
  137. wrstandard.text = obj.wrstandardname.isBlank()
  138. /// 标仓系数
  139. coefficient.text = "\(obj.convertfactor.toString(reserve: 2, false))"
  140. /// 计划量
  141. planQty.text = "\(obj.planqty.toString(reserve: 2, false))\(obj.wrunitidame)"
  142. /// 备注
  143. remark.text = obj.remark.isBlank()
  144. /// 状态
  145. ststus.text = obj.hedgeplanstatus.description
  146. ststus.textColor = .fromHex(rgbValue: obj.hedgeplanstatus == .progress ? 0x4DBB33 : 0xFE9A68)
  147. /// 视图颜色
  148. statusView.backgroundColor = obj.hedgeplanstatus == .progress ? .D3FFE1() : .FFEBDD()
  149. /// 标记
  150. statusImage.image = UIImage(named: obj.hedgeplanstatus == .progress ? "status_success" : "clock")
  151. /// 币种信息
  152. moUnit = units.first(where: {$0.enumitemname == obj.currencyid})
  153. /// 判断其权限控制
  154. switch obj.hedgeplanstatus {
  155. case .progress, .unSubmitted:
  156. /// 执行中
  157. approved.isHidden = true
  158. cancel.isHidden = true
  159. refused.isHidden = true
  160. aduitOpinionView.isHidden = true
  161. aduiterView.isHidden = true
  162. aduitTimeView.isHidden = true
  163. currency.isUserInteractionEnabled = false
  164. trader.isUserInteractionEnabled = false
  165. img1.isHidden = true
  166. img2.isHidden = true
  167. default:
  168. switch operatorType {
  169. case .cancel:
  170. /// 撤销操作
  171. approved.isHidden = true
  172. cancel.isHidden = !commonManager.isContainTraderMenu(key: "client_hedgeplan_cancel")
  173. refused.isHidden = true
  174. aduitOpinionView.isHidden = false
  175. operatorView.isHidden = false
  176. aduiterView.isHidden = true
  177. aduitTimeView.isHidden = true
  178. img1.isHidden = false
  179. img2.isHidden = false
  180. case .aduit:
  181. /// 审核操作
  182. approved.isHidden = !commonManager.isContainTraderMenu(key: "client_hedgeplan_check")
  183. cancel.isHidden = true
  184. refused.isHidden = !commonManager.isContainTraderMenu(key: "client_hedgeplan_check")
  185. aduitOpinionView.isHidden = false
  186. operatorView.isHidden = false
  187. aduiterView.isHidden = true
  188. aduitTimeView.isHidden = true
  189. img1.isHidden = false
  190. img2.isHidden = false
  191. default:
  192. /// 详情
  193. approved.isHidden = true
  194. cancel.isHidden = true
  195. refused.isHidden = true
  196. aduitOpinionView.isHidden = true
  197. operatorView.isHidden = true
  198. aduiterView.isHidden = false
  199. aduitTimeView.isHidden = false
  200. img1.isHidden = true
  201. img2.isHidden = true
  202. currency.isUserInteractionEnabled = false
  203. trader.isUserInteractionEnabled = false
  204. }
  205. }
  206. }
  207. // MARK: - 交互相关
  208. /// onButtonPressed
  209. /// - Parameter sender: sender
  210. @IBAction fileprivate func onButtonPressed(_ sender: UIControl) {
  211. switch sender {
  212. case currency: /// 币种
  213. if units.count != 0 {
  214. ActionSheetStringPicker.show(withTitle: "请选择结算币种", rows: units.map({ (obj) -> String in
  215. return obj.enumdicname
  216. }), initialSelection: 0, doneBlock: { picker, value, index in
  217. self.moUnit = self.units[value]
  218. },
  219. cancel: { picker in
  220. return
  221. },
  222. origin: sender)
  223. } else {
  224. WHToast.showMessage("没有对应的结算币种信息", duration: 1.5, finishHandler: {})
  225. }
  226. case trader: //// 交易用户
  227. if traders.count != 0 {
  228. ActionSheetStringPicker.show(withTitle: "请选择交易用户", rows: traders.map({ (obj) -> String in
  229. return "\(obj.rolename)"
  230. }), initialSelection: 0, doneBlock: { picker, value, index in
  231. self.moTraderUser = self.traders[value]
  232. },
  233. cancel: { picker in
  234. return
  235. },
  236. origin: sender)
  237. } else {
  238. WHToast.showMessage("请先去添加交易用户信息", duration: 1.5, finishHandler: {})
  239. }
  240. case cancel: /// 撤销
  241. self.doCancelHedgePlanOperator(5)
  242. case refused: /// 拒绝
  243. self.doHedgePlanOperator(5)
  244. default: /// 审核通过
  245. self.doHedgePlanOperator(4)
  246. }
  247. }
  248. // MARK: - 接口请求
  249. /// 查询交易用户数据信息
  250. fileprivate func queryTraderLoginUsers() {
  251. /// 异常
  252. guard let accountManager = MTP2BusinessCore.shared.accountManager else {
  253. return
  254. }
  255. /// 查询交易用户数据信息
  256. accountManager.queryAccMgrLoginUser(querytype: 2) { isComplete, er, objs in
  257. DispatchQueue.main.async {
  258. /// 查询失败
  259. if !isComplete {
  260. self.traders = []
  261. WHToast.showMessage("数据查询失败,原因:\(er?.retMsg ?? "请求超时")", duration: 1.5, finishHandler: {})
  262. return
  263. }
  264. self.traders = objs ?? []
  265. /// 交易用户信息
  266. if let id = self.hedgePlan,
  267. self.traders.count != 0 {
  268. self.moTraderUser = objs?.first(where: {$0.roleid == id.tradeuserid})
  269. }
  270. }
  271. }
  272. }
  273. /// 套保计划操作提交
  274. /// - Parameter operateType: 操作类型-1:保存草稿2:提交申请3:删除4审核通过5审核拒绝
  275. fileprivate func doHedgePlanOperator(_ operateType: Int) {
  276. /// 异常
  277. guard let planManager = MTP2BusinessCore.shared.planManager,
  278. let obj = hedgePlan,
  279. check(operateType) else {
  280. return
  281. }
  282. /// 备注
  283. /// id
  284. let id = Int(obj.hedgeplanid)
  285. /// 交易用户id
  286. let tradeuserid = moTraderUser?.roleid
  287. /// 币种ID
  288. let currencyid = moUnit?.enumitemname
  289. /// 计划量
  290. let planQty = obj.planqty
  291. /// 标仓系数
  292. let factor = obj.convertfactor
  293. /// 计划类型
  294. let type = obj.contracttype.rawValue
  295. /// deliverygoodsid
  296. let goodsid = obj.deliverygoodsid
  297. /// 开启Loading
  298. NVActivityIndicatorPresenter.sharedInstance.startAnimating(animActivityData("请求中..."))
  299. /// 删除请求
  300. 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
  301. DispatchQueue.main.async {
  302. /// dismisss loding.....
  303. NVActivityIndicatorPresenter.sharedInstance.stopAnimating()
  304. /// 失败
  305. if !complete {
  306. WHToast.showMessage("请求失败,原因:\(ErrorUtils.desc(er?.retCode))", duration: 2.0, finishHandler: {})
  307. return
  308. }
  309. WHToast.showSuccess(withMessage: "请求成功", duration: 2.0, finishHandler: {
  310. /// 执行回调
  311. if let bk = self.popBlock { bk(nil) }
  312. /// 返回商城视图
  313. self.navigationController?.popViewController(animated: true)
  314. })
  315. }
  316. }
  317. }
  318. /// 套保计划操作提交
  319. /// - Parameter operateType: 操作类型-1:保存草稿2:提交申请3:删除4审核通过5审核拒绝
  320. fileprivate func doCancelHedgePlanOperator(_ operateType: Int) {
  321. /// 异常
  322. guard let planManager = MTP2BusinessCore.shared.planManager, let obj = hedgePlan, check(operateType) else {
  323. return
  324. }
  325. /// 开启Loading
  326. NVActivityIndicatorPresenter.sharedInstance.startAnimating(animActivityData("请求中..."))
  327. /// 删除
  328. planManager.hedgePlanOperate(hedgePlanID: Int(obj.hedgeplanid), operateType: operateType, remark: nil, info: nil) { complete, er, rsp in
  329. DispatchQueue.main.async {
  330. /// dismisss loding.....
  331. NVActivityIndicatorPresenter.sharedInstance.stopAnimating()
  332. /// 失败
  333. if !complete {
  334. WHToast.showMessage("请求失败,原因:\(ErrorUtils.desc(er?.retCode))", duration: 2.0, finishHandler: {})
  335. return
  336. }
  337. WHToast.showSuccess(withMessage: "请求成功", duration: 2.0, finishHandler: {
  338. /// 执行回调
  339. if let bk = self.popBlock { bk(nil) }
  340. /// 返回商城视图
  341. self.navigationController?.popViewController(animated: true)
  342. })
  343. }
  344. }
  345. }
  346. /// 合规性校验
  347. /// - Returns: Bool
  348. /// - Parameter operateType: 操作类型-1:保存草稿2:提交申请3:删除4审核通过5审核拒绝
  349. fileprivate func check(_ operateType: Int) -> Bool {
  350. /// 审核通过时必须校验
  351. if operateType != 4 {
  352. return true
  353. }
  354. /// 请选择交易用户
  355. guard let _ = moTraderUser else {
  356. WHToast.showMessage("请选择交易用户", duration: 1.5, finishHandler: {})
  357. return false
  358. }
  359. /// 请选择结算币种
  360. guard let _ = moUnit else {
  361. WHToast.showMessage("请选择结算币种", duration: 1.5, finishHandler: {})
  362. return false
  363. }
  364. return true
  365. }
  366. /*
  367. // MARK: - Navigation
  368. // In a storyboard-based application, you will often want to do a little preparation before navigation
  369. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  370. // Get the new view controller using segue.destination.
  371. // Pass the selected object to the new view controller.
  372. }
  373. */
  374. }