WareHouseDetailViewController.swift 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // WareHouseDetailViewController.swift
  3. // MTP2_iOS
  4. //
  5. // Created by Muchinfo on 2021/2/26.
  6. // Copyright © 2021 Muchinfo. All rights reserved.
  7. //
  8. import UIKit
  9. import WHToast
  10. import NVActivityIndicatorView
  11. /// 仓库信息详情视图容器控制类
  12. class WareHouseDetailViewController: BaseViewController {
  13. // MARK: - 属性列表
  14. /// 状态视图
  15. @IBOutlet weak var statusView: UIView!
  16. /// 状态标记
  17. @IBOutlet weak var statusImage: UIImageView!
  18. /// 状态
  19. @IBOutlet weak var status: UILabel!
  20. /// 仓库名称
  21. @IBOutlet weak var wareHouseName: UILabel!
  22. /// 仓库简称
  23. @IBOutlet weak var wareHouseShortName: UILabel!
  24. /// 仓库类型
  25. @IBOutlet weak var type: UILabel!
  26. /// 联系人
  27. @IBOutlet weak var contractName: UILabel!
  28. /// 联系电话
  29. @IBOutlet weak var contractNum: UILabel!
  30. /// 详细地址
  31. @IBOutlet weak var detailAddress: UILabel!
  32. /// 地区
  33. @IBOutlet weak var address: UILabel!
  34. /// 停用或者恢复按钮
  35. @IBOutlet weak var submit: UIButton!
  36. /// 操作类型
  37. var operatorType: OperatorType = .stop
  38. /// 仓库信息
  39. var moWareHouse: MoWarehouse?
  40. // MARK: - 生命周期
  41. override func viewDidLoad() {
  42. super.viewDidLoad()
  43. // Do any additional setup after loading the view.
  44. }
  45. override func buildView() {
  46. super.buildView()
  47. /// loding.....
  48. addLoadingView()
  49. /// 异常
  50. guard let commonManager = MTP2BusinessCore.shared.commonManager,
  51. let obj = moWareHouse else {
  52. return
  53. }
  54. /// 查询省市区
  55. queryProvincesAndCitys()
  56. /// 状态
  57. status.text = obj.warehousestatus.description
  58. /// 仓库名称
  59. wareHouseName.text = obj.warehousename.isBlank()
  60. /// 仓库简称
  61. wareHouseShortName.text = obj.warehousecode.isBlank()
  62. /// 仓库类型
  63. type.text = obj.warehousetype.description
  64. /// 联系人
  65. contractName.text = obj.contactname.isBlank()
  66. /// 联系电话
  67. contractNum.text = obj.contactnum.isBlank()
  68. /// 详细地址
  69. detailAddress.text = obj.address.isBlank()
  70. /// 状态
  71. submit.setTitle(obj.warehousestatus == .normal ? "停用" : "恢复", for: .normal)
  72. status.textColor = .fromHex(rgbValue: obj.warehousestatus == .normal ? 0x4DBB33 : 0xFE9A68)
  73. /// 图标
  74. statusImage.image = UIImage(named: obj.warehousestatus == .normal ? "status_success" : "clock")
  75. /// 判断其权限控制
  76. submit.isHidden = !commonManager.isContainTraderMenu(key: obj.warehousestatus == .normal ? "client_warehouse_stop" : "client_warehouse_restore")
  77. }
  78. // MARK: - 交互相关
  79. @IBAction func onButtonPressed(_ sender: UIButton) {
  80. switch sender {
  81. case submit: /// 停用 或者恢复
  82. doSubmit()
  83. default: break
  84. }
  85. }
  86. // MARK: - 接口请求
  87. /// 查询对应的省市区
  88. func queryProvincesAndCitys() {
  89. /// 异常
  90. guard let obj = moWareHouse else { return }
  91. /// 对应的省
  92. let province = (try? DatabaseHelper.getAllDivisions())?.first(where: {$0.autoid == obj.provinceid})
  93. /// 对应的市
  94. let city = (try? DatabaseHelper.getAllDivisions())?.first(where: {$0.autoid == obj.cityid})
  95. /// 对应的区
  96. let district = (try? DatabaseHelper.getAllDivisions())?.first(where: {$0.autoid == obj.districtid})
  97. /// 地址信息
  98. address.text = "\(province?.divisionname ?? "") \(city?.divisionname ?? "") \(district?.divisionname ?? "")"
  99. }
  100. /// 接口请求
  101. fileprivate func doSubmit() {
  102. /// 异常
  103. guard let wareHouseManager = MTP2BusinessCore.shared.wareHouseManager,
  104. let obj = moWareHouse else {
  105. return
  106. }
  107. /// 开启Loading
  108. NVActivityIndicatorPresenter.sharedInstance.startAnimating(animActivityData("请求中..."))
  109. /// 修改状态请求
  110. wareHouseManager.requestWarehouseApplyReq(warehouseid: obj.autoid, warehousestatus: obj.warehousestatus == .normal ? 2 : 1) { (isComplete, er) in
  111. DispatchQueue.main.async {
  112. /// dismisss loding.....
  113. NVActivityIndicatorPresenter.sharedInstance.stopAnimating()
  114. /// 失败
  115. if !isComplete {
  116. WHToast.showMessage("请求失败,原因:\(ErrorUtils.desc(er?.retCode))", duration: 1.5, finishHandler: {})
  117. return
  118. }
  119. WHToast.showSuccess(withMessage: "请求成功", duration: 1.5, finishHandler: {
  120. if let bolck = self.popBlock {
  121. /// 执行回调
  122. bolck(obj.warehousestatus == .normal ? OperatorType.stop : OperatorType.reused)
  123. }
  124. /// 返回上层视图
  125. self.navigationController?.popViewController(animated: true)
  126. })
  127. }
  128. }
  129. }
  130. }