123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- //
- // ShopCreateViewController.swift
- // xingchuangke
- //
- // Created by Virgil on 2019/3/25.
- // Copyright © 2019 Virgil. All rights reserved.
- //
- import UIKit
- class SelectPayBrandViewController: BaseViewController, UITableViewDataSource, UITableViewDelegate {
- @IBOutlet weak var tableView: UITableView!
- var selectedIndex = 0
- override func viewDidLoad() {
- super.viewDidLoad()
- initNavLeftBackButton()
- self.title = "选择支付品牌"
- tableView.register(UINib(nibName: "ShopCreateTableViewCell", bundle: nil), forCellReuseIdentifier: "ShopCreateTableViewCell")
- tableView.delegate = self
- tableView.dataSource = self
- tableView.separatorStyle = .none
- tableView.showsVerticalScrollIndicator = false
- tableView.estimatedRowHeight = 100
- loadData()
- //initNavRightButtonForTitle(title: "下一步", color: UIColor.white);
- }
- // MARK: =============加载数据===============
- func loadData() {
- let url = RequestURL.machineTypeList
- let params = NSMutableDictionary()
- params.setValue(CommonValue.getUserId(), forKey: "userId")
- loadDataList(url: url, params: params, tableView: self.tableView, tag: 1001)
- let url1 = RequestURL.activityAuth
- let params1 = NSMutableDictionary()
- params1.setValue(CommonValue.getUserId(), forKey: "userId")
- params1.setValue("0001", forKey: "code")
- loadDataListPost(url: url1, params: params1, tag: 1002)
- }
- let arrProductType = NSMutableArray()
- var isLoadProductType = false
- func loadProductType() {
- arrProductType.removeAllObjects()
- // if(arrProductType.count > 0)
- // {
- // returnData(tag: 1002)
- // return;
- // }
- // if(isLoadProductType)
- // {
- // return;
- // }
- isLoadProductType = true
- let url = RequestURL.productTypeList
- let params = NSMutableDictionary()
- params.setValue(getString(current: selectedIndex, key: "id"), forKey: "machineTypeId")
- params.setValue(CommonValue.getUserId(), forKey: "userId")
- loadDataList(url: url, params: params, tag: 1002, array: arrProductType)
- }
- override func returnData(tag: Int) {
- if tag == 1001 {
- if arrData.count > 0 {
- setArrDataIntValue(current: 0, key: "isSelected", value: 1)
- }
- tableView.reloadData()
- } else if tag == 1002 {
- isLoadProductType = false
- var arrTitle = [String]()
- for i in 0 ..< arrProductType.count {
- arrTitle.append(getStringForArray(key: "name", arr: arrProductType, current: i))
- }
- CommonUntils.AlertView(controller: self, title: "请选择产品类型", message: nil, buttons: arrTitle, style: .actionSheet) {[weak self] (index, _) in
- self!.productTypeId = self!.getStringForArray(key: "id", arr: self!.arrProductType, current: index)
- if self!.machineTypeId == "5" {
- let vc = BJHKPhoneViewController()
- appDelegate.openMerchants.machineTypeId = self!.machineTypeId
- appDelegate.openMerchants.productTypeId = self!.productTypeId
- self!.toViewController(viewController: vc)
- } else {
- // let vc = SelectBusTypeViewController();
- // vc.shopOpen.posSN = "111111";
- // vc.shopOpen.productTypeId = self!.getStringForArray(key: "id", arr: self!.arrProductType, current: index)
- // vc.shopOpen.posId = self!.getString(current: self!.selectedIndex, key: "id")
- // vc.shopOpen.posName = self!.getString(current: self!.selectedIndex, key: "name")
- // self!.toViewController(viewController: vc);
- let vc = QuickOpenViewController()
- vc.shopOpen.shopType = 0
- vc.shopOpen.posSN = "111111"
- vc.shopOpen.productTypeId = self!.getStringForArray(key: "id", arr: self!.arrProductType, current: index)
- vc.shopOpen.posId = self!.getString(current: self!.selectedIndex, key: "id")
- vc.shopOpen.posName = self!.getString(current: self!.selectedIndex, key: "name")
- self!.toViewController(viewController: vc)
- }
- }
- }
- }
- override func returnError(tag: Int, type: String) {
- if tag == 1002 {
- isLoadProductType = false
- }
- }
- override func btnRightMenuClick() {
- let vc = SelectBusTypeViewController()
- //vc.type = 1;
- vc.shopOpen.posSN = "111111"
- vc.shopOpen.posId = getString(current: selectedIndex, key: "id")
- vc.shopOpen.posName = getString(current: selectedIndex, key: "name")
- toViewController(viewController: vc)
- }
- //btnAddTarget(view: self.view, selector: #selector(self.btnMenuClick))
- @IBAction func btnMenuClick(_ sender: AnyObject) {
- switch (sender as! UIButton).tag {
- case 1001: //
- break
- case 1002: //
- break
- case 1003: //
- break
- case 1004: //
- break
- case 1005: //
- break
- case 1006: //
- break
- default:
- break
- }
- }
- // MARK: TABLEVLEW 实现
- func numberOfSections(in tableView: UITableView) -> Int {
- return 1
- }
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return self.arrData.count
- }
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- return 160
- }
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: "ShopCreateTableViewCell", for: indexPath as IndexPath) as! ShopCreateTableViewCell
- if getIntValue(current: indexPath.row, key: "isSelected") == 1 {
- cell.imgChecked.isHidden = false
- } else {
- cell.imgChecked.isHidden = true
- }
- cell.lblTitle.text = getString(current: indexPath.row, key: "name")
- cell.lblRemark.text = getString(current: indexPath.row, key: "brief")
- cell.img.loadImage(imgUrl: getString(current: indexPath.row, key: "icon"), defaultImage: "")
- cell.btnDetail.tag = indexPath.row
- cell.btnDetail.addTarget(self, action: #selector(btnDetailClick), for: .touchUpInside)
- return cell
- }
- var machineTypeId = ""
- var productTypeId = ""
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- selectedIndex = indexPath.row
- for i in 0 ..< 2 {
- if i == indexPath.row {
- setArrDataIntValue(current: indexPath.row, key: "isSelected", value: 1)
- } else {
- setArrDataIntValue(current: i, key: "isSelected", value: 0)
- }
- }
- tableView.reloadData()
- machineTypeId = getString(current: indexPath.row, key: "id")
- loadProductType()
- // let vc = SelectBusTypeViewController();
- // vc.shopOpen.posSN = "111111";
- // vc.shopOpen.posId = getString(current: indexPath.row, key: "id")
- // vc.shopOpen.posName = getString(current: indexPath.row, key: "name")
- // toViewController(viewController: vc);
- }
- @objc func btnDetailClick(btn: UIButton) {
- let viewWeb = CommonWebViewViewController()
- viewWeb.strTitle = getString(current: btn.tag, key: "name")
- viewWeb.strContent = getString(current: btn.tag, key: "content")
- viewWeb.sourceType = 1
- toViewController(viewController: viewWeb)
- }
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- }
- override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
- super.init(nibName: "SelectPayBrandViewController", bundle: nil)
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- }
|