SelectPayBrandViewController.swift 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. //
  2. // ShopCreateViewController.swift
  3. // xingchuangke
  4. //
  5. // Created by Virgil on 2019/3/25.
  6. // Copyright © 2019 Virgil. All rights reserved.
  7. //
  8. import UIKit
  9. class SelectPayBrandViewController: BaseViewController, UITableViewDataSource, UITableViewDelegate {
  10. @IBOutlet weak var tableView: UITableView!
  11. var selectedIndex = 0
  12. override func viewDidLoad() {
  13. super.viewDidLoad()
  14. initNavLeftBackButton()
  15. self.title = "选择支付品牌"
  16. tableView.register(UINib(nibName: "ShopCreateTableViewCell", bundle: nil), forCellReuseIdentifier: "ShopCreateTableViewCell")
  17. tableView.delegate = self
  18. tableView.dataSource = self
  19. tableView.separatorStyle = .none
  20. tableView.showsVerticalScrollIndicator = false
  21. tableView.estimatedRowHeight = 100
  22. loadData()
  23. //initNavRightButtonForTitle(title: "下一步", color: UIColor.white);
  24. }
  25. // MARK: =============加载数据===============
  26. func loadData() {
  27. let url = RequestURL.machineTypeList
  28. let params = NSMutableDictionary()
  29. params.setValue(CommonValue.getUserId(), forKey: "userId")
  30. loadDataList(url: url, params: params, tableView: self.tableView, tag: 1001)
  31. let url1 = RequestURL.activityAuth
  32. let params1 = NSMutableDictionary()
  33. params1.setValue(CommonValue.getUserId(), forKey: "userId")
  34. params1.setValue("0001", forKey: "code")
  35. loadDataListPost(url: url1, params: params1, tag: 1002)
  36. }
  37. let arrProductType = NSMutableArray()
  38. var isLoadProductType = false
  39. func loadProductType() {
  40. arrProductType.removeAllObjects()
  41. // if(arrProductType.count > 0)
  42. // {
  43. // returnData(tag: 1002)
  44. // return;
  45. // }
  46. // if(isLoadProductType)
  47. // {
  48. // return;
  49. // }
  50. isLoadProductType = true
  51. let url = RequestURL.productTypeList
  52. let params = NSMutableDictionary()
  53. params.setValue(getString(current: selectedIndex, key: "id"), forKey: "machineTypeId")
  54. params.setValue(CommonValue.getUserId(), forKey: "userId")
  55. loadDataList(url: url, params: params, tag: 1002, array: arrProductType)
  56. }
  57. override func returnData(tag: Int) {
  58. if tag == 1001 {
  59. if arrData.count > 0 {
  60. setArrDataIntValue(current: 0, key: "isSelected", value: 1)
  61. }
  62. tableView.reloadData()
  63. } else if tag == 1002 {
  64. isLoadProductType = false
  65. var arrTitle = [String]()
  66. for i in 0 ..< arrProductType.count {
  67. arrTitle.append(getStringForArray(key: "name", arr: arrProductType, current: i))
  68. }
  69. CommonUntils.AlertView(controller: self, title: "请选择产品类型", message: nil, buttons: arrTitle, style: .actionSheet) {[weak self] (index, _) in
  70. self!.productTypeId = self!.getStringForArray(key: "id", arr: self!.arrProductType, current: index)
  71. if self!.machineTypeId == "5" {
  72. let vc = BJHKPhoneViewController()
  73. appDelegate.openMerchants.machineTypeId = self!.machineTypeId
  74. appDelegate.openMerchants.productTypeId = self!.productTypeId
  75. self!.toViewController(viewController: vc)
  76. } else {
  77. // let vc = SelectBusTypeViewController();
  78. // vc.shopOpen.posSN = "111111";
  79. // vc.shopOpen.productTypeId = self!.getStringForArray(key: "id", arr: self!.arrProductType, current: index)
  80. // vc.shopOpen.posId = self!.getString(current: self!.selectedIndex, key: "id")
  81. // vc.shopOpen.posName = self!.getString(current: self!.selectedIndex, key: "name")
  82. // self!.toViewController(viewController: vc);
  83. let vc = QuickOpenViewController()
  84. vc.shopOpen.shopType = 0
  85. vc.shopOpen.posSN = "111111"
  86. vc.shopOpen.productTypeId = self!.getStringForArray(key: "id", arr: self!.arrProductType, current: index)
  87. vc.shopOpen.posId = self!.getString(current: self!.selectedIndex, key: "id")
  88. vc.shopOpen.posName = self!.getString(current: self!.selectedIndex, key: "name")
  89. self!.toViewController(viewController: vc)
  90. }
  91. }
  92. }
  93. }
  94. override func returnError(tag: Int, type: String) {
  95. if tag == 1002 {
  96. isLoadProductType = false
  97. }
  98. }
  99. override func btnRightMenuClick() {
  100. let vc = SelectBusTypeViewController()
  101. //vc.type = 1;
  102. vc.shopOpen.posSN = "111111"
  103. vc.shopOpen.posId = getString(current: selectedIndex, key: "id")
  104. vc.shopOpen.posName = getString(current: selectedIndex, key: "name")
  105. toViewController(viewController: vc)
  106. }
  107. //btnAddTarget(view: self.view, selector: #selector(self.btnMenuClick))
  108. @IBAction func btnMenuClick(_ sender: AnyObject) {
  109. switch (sender as! UIButton).tag {
  110. case 1001: //
  111. break
  112. case 1002: //
  113. break
  114. case 1003: //
  115. break
  116. case 1004: //
  117. break
  118. case 1005: //
  119. break
  120. case 1006: //
  121. break
  122. default:
  123. break
  124. }
  125. }
  126. // MARK: TABLEVLEW 实现
  127. func numberOfSections(in tableView: UITableView) -> Int {
  128. return 1
  129. }
  130. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  131. return self.arrData.count
  132. }
  133. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  134. return 160
  135. }
  136. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  137. let cell = tableView.dequeueReusableCell(withIdentifier: "ShopCreateTableViewCell", for: indexPath as IndexPath) as! ShopCreateTableViewCell
  138. if getIntValue(current: indexPath.row, key: "isSelected") == 1 {
  139. cell.imgChecked.isHidden = false
  140. } else {
  141. cell.imgChecked.isHidden = true
  142. }
  143. cell.lblTitle.text = getString(current: indexPath.row, key: "name")
  144. cell.lblRemark.text = getString(current: indexPath.row, key: "brief")
  145. cell.img.loadImage(imgUrl: getString(current: indexPath.row, key: "icon"), defaultImage: "")
  146. cell.btnDetail.tag = indexPath.row
  147. cell.btnDetail.addTarget(self, action: #selector(btnDetailClick), for: .touchUpInside)
  148. return cell
  149. }
  150. var machineTypeId = ""
  151. var productTypeId = ""
  152. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  153. selectedIndex = indexPath.row
  154. for i in 0 ..< 2 {
  155. if i == indexPath.row {
  156. setArrDataIntValue(current: indexPath.row, key: "isSelected", value: 1)
  157. } else {
  158. setArrDataIntValue(current: i, key: "isSelected", value: 0)
  159. }
  160. }
  161. tableView.reloadData()
  162. machineTypeId = getString(current: indexPath.row, key: "id")
  163. loadProductType()
  164. // let vc = SelectBusTypeViewController();
  165. // vc.shopOpen.posSN = "111111";
  166. // vc.shopOpen.posId = getString(current: indexPath.row, key: "id")
  167. // vc.shopOpen.posName = getString(current: indexPath.row, key: "name")
  168. // toViewController(viewController: vc);
  169. }
  170. @objc func btnDetailClick(btn: UIButton) {
  171. let viewWeb = CommonWebViewViewController()
  172. viewWeb.strTitle = getString(current: btn.tag, key: "name")
  173. viewWeb.strContent = getString(current: btn.tag, key: "content")
  174. viewWeb.sourceType = 1
  175. toViewController(viewController: viewWeb)
  176. }
  177. override func viewWillAppear(_ animated: Bool) {
  178. super.viewWillAppear(animated)
  179. }
  180. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  181. super.init(nibName: "SelectPayBrandViewController", bundle: nil)
  182. }
  183. required init?(coder aDecoder: NSCoder) {
  184. fatalError("init(coder:) has not been implemented")
  185. }
  186. }