MerchantsStateVC.swift 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // MerchantsStateVC.swift
  3. // xingchuangke
  4. //
  5. // Created by Apple on 2021/3/2.
  6. // Copyright © 2021 Virgil. All rights reserved.
  7. //
  8. class MerchantsStateVC: BaseViewController {
  9. var dicModel = NSMutableDictionary()
  10. override func viewDidLoad() {
  11. super.viewDidLoad()
  12. self.view.backgroundColor = UIColor.init(white: 246/255.0, alpha: 1.0)
  13. self.title = "商户状态"
  14. initNavLeftBackButton()
  15. loadData()
  16. }
  17. // MARK: - request
  18. func loadData() {
  19. let url1 = RequestURL.machineInforNum
  20. let params1 = NSMutableDictionary()
  21. params1.setValue(CommonValue.getUserId(), forKey: "userId")
  22. params1.setValue("", forKey: "machineTypeId")
  23. submitDatMachineInforNumdic(url: url1, params: params1, tag: 1001)
  24. }
  25. var w: CGFloat = 0
  26. var h: CGFloat = 15
  27. override func returnData(tag: Int) {
  28. for i in 0..<self.arrDataMj.count {
  29. let dicNew = NSMutableDictionary(dictionary: self.arrDataMj[i] as! NSDictionary)
  30. let name = (dicNew as NSDictionary).object(forKey: "name") as! String
  31. let num = "\((dicNew as NSDictionary)["num"] as! Int)"
  32. let buttonView = UIView.init()
  33. buttonView.backgroundColor = .white
  34. buttonView.layer.cornerRadius = 8.0
  35. buttonView.layer.masksToBounds = true
  36. let length = (SCREEN_WIDTH-10*3)/2
  37. buttonView.frame = CGRect(x: 10 + w, y: h, width: length, height: 80)
  38. //当button的位置超出右侧边缘时换行
  39. if 10+w+length > SCREEN_WIDTH {
  40. w = 0
  41. h = h + buttonView.frame.size.height + 10
  42. buttonView.frame = CGRect(x: 10+w, y: h, width: length, height: 80)
  43. }
  44. w = buttonView.frame.size.width + buttonView.frame.origin.x
  45. view.addSubview(buttonView)
  46. let lblt = UILabel.init()
  47. lblt.text = name
  48. lblt.textColor = UIColor.black
  49. lblt.textAlignment = .center
  50. lblt.setOrigin(x: 0, y: 15)
  51. lblt.setSizeHeight(height: 30)
  52. lblt.setSizeWidth(width: length)
  53. buttonView.addSubview(lblt)
  54. let lbld = UILabel.init()
  55. lbld.text = num
  56. lbld.textColor = UIColor.red
  57. lbld.textAlignment = .center
  58. lbld.setOrigin(x: 0, y: 15+lblt.frame.size.height)
  59. lbld.setSizeHeight(height: 30)
  60. lbld.setSizeWidth(width: length)
  61. buttonView.addSubview(lbld)
  62. let button = UIButton(type: .custom)
  63. button.backgroundColor = .clear
  64. button.setOrigin(x: 0, y: 0)
  65. button.setSizeHeight(height: 80)
  66. button.setSizeWidth(width: length)
  67. button.tag = i
  68. button.addTarget(self, action: #selector(rewardClick(sender:)), for: .touchUpInside)
  69. buttonView.addSubview(button)
  70. }
  71. }
  72. @objc func rewardClick(sender : UIButton ) {
  73. let vc = MerchantsStateDetailVC()
  74. let dic: NSDictionary = self.arrDataMj[sender.tag] as! NSDictionary
  75. vc.dicModel = dic as! NSMutableDictionary
  76. appDelegate.navController.pushViewController(vc, animated: true)
  77. }
  78. }