GoodsVarietiesDetailViewController.swift 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. //
  2. // GoodsVarietiesDetailViewController.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. /// 现货品种详情视图容器控制类
  13. class GoodsVarietiesDetailViewController: BaseViewController {
  14. // MARK: - 属性列表
  15. /// 状态视图
  16. @IBOutlet weak var statusView: UIView!
  17. /// 状态标记
  18. @IBOutlet weak var statusImage: UIImageView!
  19. /// 状态
  20. @IBOutlet weak var ststus: UILabel!
  21. /// 现货品种名称
  22. @IBOutlet weak var deliveryName: UILabel!
  23. /// 现货品种代码
  24. @IBOutlet weak var deliveryCode: UILabel!
  25. /// 单位
  26. @IBOutlet weak var enumdicname: UILabel!
  27. /// 备注
  28. @IBOutlet weak var remark: UILabel!
  29. /// 审核通过
  30. @IBOutlet weak var stop: UIButton! {
  31. didSet {
  32. stop.isHidden = true
  33. }
  34. }
  35. /// 商品品牌规格列表
  36. @IBOutlet weak var tableView: UITableView!
  37. /// 商品品牌规格列表
  38. @IBOutlet weak var heightLayoutConstraint: NSLayoutConstraint! {
  39. didSet {
  40. heightLayoutConstraint.constant = 0.0
  41. }
  42. }
  43. /// CellIdentifier
  44. let CellIdentifier = "GoodsVarieties_Cell"
  45. /// 显示数据
  46. var datas: [(title: String, value: String)] = [] {
  47. didSet {
  48. /// 刷新列表数据
  49. self.tableView.reloadData()
  50. /// 高度约束
  51. heightLayoutConstraint.constant = CGFloat(datas.count)*55.0
  52. }
  53. }
  54. /// 现货品种信息
  55. var deliveryGoodsDetail: MoDeliveryGoodsDetail?
  56. // MARK: - 生命周期
  57. override func viewDidLoad() {
  58. super.viewDidLoad()
  59. // Do any additional setup after loading the view.
  60. /// loding
  61. self.addLoadingView()
  62. }
  63. override func loadView() {
  64. super.loadView()
  65. /// 显示套保计划详细信息
  66. showWrStandardInfos()
  67. }
  68. /// 显示现货品种详细信息
  69. fileprivate func showWrStandardInfos() {
  70. /// 异常
  71. guard let commonManager = MTP2BusinessCore.shared.commonManager,
  72. let obj = deliveryGoodsDetail?.data else { return }
  73. /// 现货品种名称
  74. deliveryName.text = obj.deliverygoodsname.isBlank()
  75. /// 现货品种代码
  76. deliveryCode.text = obj.deliverygoodscode.isBlank()
  77. /// 单位
  78. let ename = (try? DatabaseHelper.getEnumInfo(enumdiccode: "goodsunit")?.first(where: {$0.enumitemname == obj.goodsunitid})?.enumdicname) ?? "--"
  79. /// 单位
  80. enumdicname.text = ename
  81. /// 状态
  82. ststus.text = obj.isvalid == 0 ? "停用" : "正常"
  83. ststus.textColor = .fromHex(rgbValue: obj.isvalid == 1 ? 0x4DBB33 : 0xFE9A68)
  84. /// 视图颜色
  85. statusView.backgroundColor = obj.isvalid == 1 ? .D3FFE1() : .FFEBDD()
  86. /// 标记
  87. statusImage.image = UIImage(named: obj.isvalid == 1 ? "status_success" : "clock")
  88. /// 按钮状态
  89. stop.setTitle(obj.isvalid == 0 ? "恢复" : "停用", for: .normal)
  90. /// 备注
  91. remark.text = obj.remark.isBlank()
  92. /// 查询现货品种明细
  93. requestWrStandardDetail()
  94. /// 该账户没权限
  95. stop.isHidden = !commonManager.isContainTraderMenu(key: obj.isvalid == 1 ? "client_deliverygoods_spot_disable" : "client_deliverygoods_spot_restore")
  96. }
  97. // MARK: - 交互相关
  98. /// onButtonPressed
  99. /// - Parameter sender: sender
  100. @IBAction fileprivate func onButtonPressed(_ sender: UIControl) {
  101. switch sender {
  102. case stop: /// 停用
  103. self.doRequestStopWrStandard()
  104. default: break
  105. }
  106. }
  107. // MARK: - 接口请求
  108. /// 查询现货品种明细
  109. fileprivate func requestWrStandardDetail() {
  110. /// 异常
  111. guard let contractManager = MTP2BusinessCore.shared.contractManager,
  112. let id = deliveryGoodsDetail?.data?.deliverygoodsid else {
  113. return
  114. }
  115. /// startAnimating
  116. _anim?.startAnimating()
  117. /// 查询详情
  118. contractManager.queryDeliveryGoodsDetail(deliverygoodsid: id, qrytradegoods: nil) { (isComplete, er, objs) in
  119. DispatchQueue.main.async {
  120. /// stopAnimating
  121. self._anim?.stopAnimating()
  122. if !isComplete {
  123. WHToast.showMessage("现货品种详情查询失败", duration: 1.5, finishHandler: {})
  124. return
  125. }
  126. guard let obj = objs?.first else {
  127. WHToast.showMessage("详细数据为空", duration: 1.5, finishHandler: {})
  128. return
  129. }
  130. /// 详细数据
  131. var details: [(title: String, value: String)] = []
  132. /// 品牌数据
  133. if obj.gblist.count != 0 {
  134. for (index, obj) in obj.gblist.enumerated() {
  135. details.append((title: "品牌\(index+1)", value: obj.brandname.isBlank()))
  136. }
  137. }
  138. /// 商品数据数据
  139. if obj.gmlist.count != 0 {
  140. for (index, obj) in obj.gmlist.enumerated() {
  141. details.append((title: "商品\(index+1)", value: obj.wrstandardname.isBlank()))
  142. details.append((title: "单位\(index+1)", value: obj.enumdicname.isBlank()))
  143. details.append((title: "标仓系数\(index+1)", value: "\(obj.convertfactor)"))
  144. }
  145. }
  146. /// 套保信息
  147. if obj.mgList.count != 0 {
  148. for (index, objmg) in obj.mgList.enumerated() {
  149. if let mg = objmg.mg {
  150. details.append((title: "套保品种\(index+1)", value: mg.middlegoodsname.isBlank()))
  151. details.append((title: "单位\(index+1)", value: mg.enumdicname.isBlank()))
  152. details.append((title: "套保系数\(index+1)", value: "\(objmg.convertratio)"))
  153. }
  154. }
  155. }
  156. /// 刷新数据
  157. self.datas = details
  158. }
  159. }
  160. }
  161. /// 停用现货商品
  162. fileprivate func doRequestStopWrStandard() {
  163. /// 异常
  164. guard let contractManager = MTP2BusinessCore.shared.contractManager,
  165. let obj = deliveryGoodsDetail?.data else {
  166. return
  167. }
  168. /// 开启Loading
  169. NVActivityIndicatorPresenter.sharedInstance.startAnimating(animActivityData("请求中"))
  170. /// 发送请求
  171. contractManager.requestDeliveryGoodsCancel(deliveryGoodsid: UInt64(obj.deliverygoodsid), isvalid: obj.isvalid == 0 ? 1 : 0) { (isComplete, er) in
  172. DispatchQueue.main.async {
  173. /// dismisss loding.....
  174. NVActivityIndicatorPresenter.sharedInstance.stopAnimating()
  175. /// 请求失败
  176. if !isComplete {
  177. WHToast.showMessage("停用请求失败,原因:\(ErrorUtils.desc(er?.retCode))", duration: 1.5, finishHandler: {})
  178. return
  179. }
  180. WHToast.showSuccess(withMessage: "请求成功", duration: 1.5) {
  181. /// 执行回调
  182. if let block = self.popBlock { block(OperatorType.update) }
  183. /// 返回上层视图
  184. self.navigationController?.popViewController(animated: true)
  185. }
  186. }
  187. }
  188. }
  189. }
  190. extension GoodsVarietiesDetailViewController: UITableViewDelegate, UITableViewDataSource {
  191. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  192. return datas.count
  193. }
  194. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  195. let cell = tableView.dequeueReusableCell(withIdentifier: CellIdentifier, for: indexPath) as! GoodsVarietiesDetailCell
  196. cell.model = self.datas[indexPath.row]
  197. return cell
  198. }
  199. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  200. return 55.0
  201. }
  202. }
  203. class GoodsVarietiesDetailCell: BaseTableViewCell<(title: String, value: String)> {
  204. /// title
  205. @IBOutlet weak var title: UILabel!
  206. /// value
  207. @IBOutlet weak var value: UILabel!
  208. override var model: (title: String, value: String)? {
  209. didSet {
  210. guard let obj = model else { return }
  211. title.text = obj.title
  212. value.text = obj.value
  213. }
  214. }
  215. }