// // ShopListViewController.swift // xingchuangke // // Created by Virgil on 2019/3/30. // Copyright © 2019 Virgil. All rights reserved. // import UIKit class ShopListViewController: BaseViewController, UITableViewDataSource, UITableViewDelegate { @IBOutlet weak var tableView: UITableView! ///0:未提交 1:待修改 2:审核中 3:审核通过 var type = 0 var typeTitle = ["未提交", "待修改", "审核中", "审核通过"] var status = ["", "2", "0", "1"] override func viewDidLoad() { super.viewDidLoad() self.title = typeTitle[type] initNavLeftBackButton() tableView.register(UINib(nibName: "ShopListTableViewCell", bundle: nil), forCellReuseIdentifier: "ShopListTableViewCell") tableView.delegate = self tableView.dataSource = self tableView.separatorStyle = .none tableView.showsVerticalScrollIndicator = false tableView.estimatedRowHeight = 100 tableView.mj_header = MJRefreshNormalHeader(refreshingBlock: {[weak self] in self!.currentPage = 1 self!.loadData() }) if type != 0 { tableView.mj_header?.lastUpdatedTimeKey = "ShowTableViewCell" tableView.mj_footer = MJRefreshBackNormalFooter(refreshingBlock: {[weak self] in self!.currentPage += 1 self!.loadData() }) } tableView.mj_header?.beginRefreshing() } // MARK: =============加载数据=============== func loadData() { if type == 0 { self.arrData.removeAllObjects() let local = CommonValue.getDefaultUserInfoForObject(key: "common_local_businfo") if local != nil && (local as? NSArray) != nil && (local as! NSArray).count > 0 { self.arrData.addObjects(from: ((local as! NSArray) as! [Any])) } if self.arrData.count > 0 { self.hiddenNoDataViewForTableView(tableView: tableView) } else { self.showNoDataViewForTableView(tableView: tableView) } tableView.mj_header?.endRefreshing() returnData(tag: 1001) } else { let url = RequestURL.myMerchantList let params = NSMutableDictionary() params.setValue(CommonValue.getUserId(), forKey: "userId") params.setValue(status[type], forKey: "status") params.setValue("", forKey: "likeStr") loadDataList(url: url, params: params, tableView: tableView, tag: 1001) } } override func returnData(tag: Int) { if tag == 1001 { tableView.reloadData() } } override func returnError(tag: Int, type: String) { } // 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 75 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "ShopListTableViewCell", for: indexPath as IndexPath) as! ShopListTableViewCell if getString(current: indexPath.row, key: "machineTypeCN") != "" { cell.lblName.text = "\(getString(current: indexPath.row, key: "companyName"))(\(getString(current: indexPath.row, key: "machineTypeCN")))" } else { cell.lblName.text = "\(getString(current: indexPath.row, key: "companyName"))" } // cell.lblName.text = getString(current: indexPath.row, key: "companyName") cell.lblDate.text = getString(current: indexPath.row, key: "createtime") // if(type == 3) // { // cell.btnBind.isHidden = false; // cell.btnBind.tag = indexPath.row; // cell.btnBind.addTarget(self, action: #selector(btnBindClick), for: .touchUpInside); // } return cell } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { if indexPath.row >= arrData.count { return } let machineTypeId = getString(current: indexPath.row, key: "machineTypeId") if machineTypeId == "1" { let vc = MyShopDetailTypeViewController() vc.id = getString(current: indexPath.row, key: "id") vc.dicData.setDic(dic: self.arrData[indexPath.row] as! NSDictionary) toViewController(viewController: vc) } else { let vc = MyShopDetailViewController() vc.id = getString(current: indexPath.row, key: "id") vc.dicData.setDic(dic: self.arrData[indexPath.row] as! NSDictionary) toViewController(viewController: vc) } return ///0:未提交 1:待修改 2:审核中 3:审核通过 if type == 0 { let dic = self.arrData[indexPath.row] as! NSDictionary let entity = ShopOpenEntity() entity.mj_setKeyValues(dic) let vc = OpenDetailViewController() vc.localCurrnetIndex = indexPath.row vc.shopOpen = entity vc.isSaveLocal = true toViewController(viewController: vc) } else if type == 1 { let machineTypeId = getString(current: indexPath.row, key: "machineTypeId") if machineTypeId != "1" { let dic = self.arrData[indexPath.row] as! NSDictionary let vc = OpenDetailViewController() vc.type = 1 vc.isSaveLocal = false vc.shopOpen = getShopEntity(dic: dic) toViewController(viewController: vc) } } else if type == 2 { let machineTypeId = getString(current: indexPath.row, key: "machineTypeId") if machineTypeId == "1" { let vc = MyShopDetailTypeViewController() vc.id = getString(current: indexPath.row, key: "id") vc.dicData.setDic(dic: self.arrData[indexPath.row] as! NSDictionary) toViewController(viewController: vc) } else { let dic = self.arrData[indexPath.row] as! NSDictionary let vc = OpenDetailViewController() vc.isMod = false vc.shopOpen = getShopEntity(dic: dic) toViewController(viewController: vc) } } else if type == 3 { let machineTypeId = getString(current: indexPath.row, key: "machineTypeId") if (machineTypeId == "1" || machineTypeId == "777" || machineTypeId == "888" || machineTypeId == "999" || machineTypeId == "9999"){ let vc = MyShopDetailTypeViewController() vc.id = getString(current: indexPath.row, key: "id") vc.dicData.setDic(dic: self.arrData[indexPath.row] as! NSDictionary) toViewController(viewController: vc) } else { let vc = MyShopDetailViewController() vc.id = getString(current: indexPath.row, key: "id") vc.dicData.setDic(dic: self.arrData[indexPath.row] as! NSDictionary) toViewController(viewController: vc) } } } @objc func btnBindClick(btn: UIButton) { let vc = BindDeviceViewController() vc.merchantsId = getString(current: btn.tag, key: "id") self.toViewController(viewController: vc) } func getShopEntity(dic: NSDictionary) -> ShopOpenEntity { let shopOpen = ShopOpenEntity() shopOpen.id = dic.getString(key: "id") shopOpen.posId = dic.getString(key: "machineTypeId") shopOpen.posSN = dic.getString(key: "machineSnCode") shopOpen.shopType = dic.getInt(key: "busType") shopOpen.phone = dic.getString(key: "busPhone") shopOpen.companyName = dic.getString(key: "companyName") shopOpen.name = dic.getString(key: "applicantName") shopOpen.card = dic.getString(key: "applicantCard") shopOpen.cardFront = dic.getString(key: "applicantCardFront") shopOpen.cardReverse = dic.getString(key: "applicantCardReverse") shopOpen.cardHoldFront = dic.getString(key: "applicantCardHoldFront") shopOpen.otherImage = dic.getString(key: "applicantCardHoldReverse") shopOpen.addressDetail = dic.getString(key: "shopAddress") shopOpen.addressId1 = dic.getString(key: "shopProvinceId") shopOpen.addressId2 = dic.getString(key: "shopCityId") shopOpen.addressId3 = dic.getString(key: "shopAreaId") shopOpen.typeId2 = dic.getString(key: "categoryTwoId") shopOpen.typeId1 = dic.getString(key: "categoryOneId") shopOpen.productTypeId = dic.getString(key: "productTypeId") shopOpen.bankCardNo = dic.getString(key: "bankCardNumber") shopOpen.bankName = dic.getString(key: "bankAffiliatedBankCN") shopOpen.bankAddressId1 = dic.getString(key: "bankProvinceId") shopOpen.bankAddressId2 = dic.getString(key: "bankCityId") shopOpen.bankAddressId3 = dic.getString(key: "bankAreaId") shopOpen.bankAddress = dic.getString(key: "bankAreaId") shopOpen.bankAffiliatedBranchBank = dic.getString(key: "bankAffiliatedBranchBank") shopOpen.bankOpenName = dic.getString(key: "bankOpenName") shopOpen.bankCardImage = dic.getString(key: "bankCardImg") shopOpen.addressName1 = dic.getString(key: "provinceCN") shopOpen.addressName2 = dic.getString(key: "cityCN") shopOpen.addressName3 = dic.getString(key: "areaCN") shopOpen.typeName1 = dic.getString(key: "categoryOneCN") shopOpen.typeName2 = dic.getString(key: "categoryTwoCN") shopOpen.bankAddressName1 = dic.getString(key: "bankProvinceCN") shopOpen.bankAddressName2 = dic.getString(key: "bankCityCN") shopOpen.bankAddressName3 = dic.getString(key: "bankAreaCN") shopOpen.dpImages = dic.getString(key: "shopPhoto") shopOpen.shhyzImages = dic.getString(key: "shopUserPhoto") shopOpen.licenseImage = dic.getString(key: "licenseImage") shopOpen.licenseNum = dic.getString(key: "licenseNum") shopOpen.bankAccountType = dic.getString(key: "bankAccountType") shopOpen.openingPermitImage = dic.getString(key: "openingPermitImage") shopOpen.reservePhone = dic.getString(key: "reservePhone") shopOpen.bankAffiliatedBank = dic.getString(key: "bankAffiliatedBank") shopOpen.applicantCardFrontLocal = dic.getString(key: "applicantCardFrontLocal") shopOpen.applicantCardReverseLocal = dic.getString(key: "applicantCardReverseLocal") shopOpen.applicantCardHoldFrontLocal = dic.getString(key: "applicantCardHoldFrontLocal") shopOpen.bankCardImgLocal = dic.getString(key: "bankCardImgLocal") shopOpen.bankAffiliatedBranchBankCN = dic.getString(key: "bankAffiliatedBranchBankCN") shopOpen.reason = dic.getString(key: "reason") shopOpen.rate = "\(dic.getDouble(key: "rate"))" shopOpen.debitCardCostRate = "\(dic.getDouble(key: "debitCardCostRate"))" shopOpen.debitCardCapping = "\(dic.getDouble(key: "debitCardCapping"))" shopOpen.unionpayRate = "\(dic.getDouble(key: "unionpayRate"))" shopOpen.loanCardCapping = "\(dic.getDouble(key: "loanCardCapping"))" return shopOpen } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) if type != 3 { tableView.mj_header?.beginRefreshing() } } override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { super.init(nibName: "ShopListViewController", bundle: nil) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } }