// // MerchantsStateDetailVC.swift // xingchuangke // // Created by Apple on 2021/3/2. // Copyright © 2021 Virgil. All rights reserved. // class MerchantsStateDetailVC: BaseViewController, UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate { @IBOutlet weak var tableView: UITableView! @IBOutlet weak var imgBackgroud: UIImageView! @IBOutlet weak var txtCode: UITextField! @IBOutlet weak var viewMenu: UIView! var queryEntity: ShopQueryModel! let contentV = CommonViewUntils.getViewForXIB(xibName: "MerchantsMenuContent") as! MerchantsMenuContent var menuView: XF_RightMenu = { let menuView = XF_RightMenu.init(frame: UIScreen.main.bounds) return menuView }() var sortType: String = "desc" var mid = "" var machineType = "" var dicModel = NSMutableDictionary() override func viewDidLoad() { super.viewDidLoad() queryEntity = ShopQueryModel() let viewNav = (CommonViewUntils.getViewForXIB(xibName: "NavView") as! NavView) let name = self.dicModel.object(forKey: "name") as! String viewNav.initView(title: name) {[weak self] (index, _) in if index == 0 { self!.handleBack() } } self.view.addSubview(viewNav) viewNav.marginTop(top: 0) viewNav.initRightBtn(title: "筛选") viewNav.btnRight.addTarget(self, action: #selector(rewardClick), for: .touchUpInside) self.view.addSubview(viewNav) viewNav.marginTop(top: 0) viewMenu.marginTop(top: viewNav.bottom()) txtCode.setCornerRadius(size: 4) txtCode.setContentMarginLeft(leftWidth: 15) txtCode.setContentMarginRight(rightWidth: 30) imgBackgroud.setSizeHeight(height: viewMenu.bottom()) tableView.marginTop(top: 0, view: imgBackgroud) tableView.setSizeHeight(height: ScreenHeight - imgBackgroud.height() - 49) tableView.register(UINib(nibName: "MerchantsStateDetailCell", bundle: nil), forCellReuseIdentifier: "MerchantsStateDetailCell") tableView.delegate = self tableView.dataSource = self tableView.separatorStyle = .none tableView.showsVerticalScrollIndicator = false tableView.estimatedRowHeight = 100 tableView.keyboardDismissMode = .onDrag txtCode.delegate = self txtCode.returnKeyType = .search tableView.mj_header = MJRefreshNormalHeader(refreshingBlock: {[weak self] in self!.currentPage = 1 self!.loadData() }) tableView.mj_header?.lastUpdatedTimeKey = "ShowTableViewCell" tableView.mj_footer = MJRefreshBackNormalFooter(refreshingBlock: {[weak self] in self!.currentPage += 1 self!.loadData() }) self.view.addSubview(menuView) loadData() loadDataActivityAuth() menuView.contentView = contentV contentV.callBackForSure = {[weak self] (queryEntityTemp) in self!.machineType = queryEntityTemp.object(forKey: "machineTypeId") as! String self!.menuView.hiddenView() self!.loadData() } } @objc func rewardClick( ) { self.menuView.showView() } func textFieldShouldReturn(_ textField: UITextField) -> Bool { self.currentPage = 1 loadData() return true } // MARK: =============加载数据=============== func loadData() { let url = RequestURL.machineInforList let params = NSMutableDictionary() params.setValue(CommonValue.getUserId(), forKey: "userId") params.setValue(self.machineType, forKey: "machineTypeId") params.setValue("", forKey: "snCode") let paramName = self.dicModel.object(forKey: "paramName") as! String let paramStatus = self.dicModel.object(forKey: "paramStatus") as! String if paramName == "isBind" { params.setValue(paramStatus, forKey: "isBind") }else if paramName == "isStandard" { params.setValue(paramStatus, forKey: "isStandard") }else if paramName == "isGrant" { params.setValue(paramStatus, forKey: "isGrant") }else if paramName == "isDeposit" { params.setValue(paramStatus, forKey: "isDeposit") } params.setValue(txtCode.text!, forKey: "findName") submitDatMachineInforList(url: url, params: params, tableView: tableView, tag: 1001) } // MARK: - request func loadDataActivityAuth() { let url = RequestURL.activityAuth let params = NSMutableDictionary() params.setValue(CommonValue.getUserId(), forKey: "userId") params.setValue("0001", forKey: "code") loadDataListPostMerchants(url: url, params: params, tag: 1003) } func submitData() { if selectedIndex == -1 { SVProgressHUD.showError(withStatus: "请选择分拨代理") return } let url = RequestURL.machineAllocation let params = NSMutableDictionary() params.setValue(getString(current: selectedIndex, key: "id"), forKey: "userId") params.setValue(mid, forKey: "machineId") submitData(url: url, params: params, tag: 1002) } override func returnData(tag: Int) { if tag == 1001 { tableView.reloadData() } else if tag == 1002 { SVProgressHUD.showSuccess(withStatus: "分拨成功!") handleBack() } else if tag == 1003 { contentV.arrDataMj = self.arrDataMj contentV.returnData() } } 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 82 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "MerchantsStateDetailCell", for: indexPath as IndexPath) as! MerchantsStateDetailCell cell.lblName.text = "\(getString(current: indexPath.row, key: "company_name"))" //是否押金 let deposit_amount = getIntValue(current: indexPath.row, key: "activation_conditions") if deposit_amount == 0 { cell.lblYJ.text = "押金" cell.lblYJ.textColor = .gray //机具状态 //区间累积消费 交易是否达标 let is_grant = getIntValue(current: indexPath.row, key: "is_grant") //总累积消费 let is_standard = getIntValue(current: indexPath.row, key: "is_standard") let standard_reward_st = getString(current: indexPath.row, key: "standard_reward_st") if is_grant == 0 && is_standard == 0{ cell.lblJD.text = "未达标" cell.lblJD.textColor = .orange if standard_reward_st == "0" { cell.lblRight.text = "押金激活奖励未发放" cell.lblRight.textColor = .red }else if standard_reward_st == "1" { cell.lblRight.text = "押金激活奖励已发放" cell.lblRight.textColor = .colorWithCustom(r: 55, g: 192, b: 102) }else { cell.lblRight.text = "押金激活奖励已发放" cell.lblRight.textColor = .colorWithCustom(r: 55, g: 192, b: 102) } } if is_grant != 0 { if standard_reward_st == "0" { cell.lblRight.text = "押金激活奖励未发放" cell.lblRight.textColor = .red }else if standard_reward_st == "1" { cell.lblRight.text = "押金激活奖励已发放" cell.lblRight.textColor = .colorWithCustom(r: 55, g: 192, b: 102) }else { cell.lblRight.text = "押金激活奖励已发放" cell.lblRight.textColor = .colorWithCustom(r: 55, g: 192, b: 102) } cell.lblJD.text = "\(is_grant)" + "阶段已达标" cell.lblJD.textColor = .colorWithCustom(r: 55, g: 192, b: 102) } if is_standard != 0 { if standard_reward_st == "0" { cell.lblRight.text = "押金激活奖励未发放" cell.lblRight.textColor = .red }else if standard_reward_st == "1" { cell.lblRight.text = "押金激活奖励已发放" cell.lblRight.textColor = .colorWithCustom(r: 55, g: 192, b: 102) }else { cell.lblRight.text = "押金激活奖励已发放" cell.lblRight.textColor = .colorWithCustom(r: 55, g: 192, b: 102) } cell.lblJD.text = "\(is_grant)" + "阶段已达标" cell.lblJD.textColor = .colorWithCustom(r: 55, g: 192, b: 102) } }else if deposit_amount == 1 { cell.lblYJ.text = "非押金" cell.lblYJ.textColor = .red //机具状态 //区间累积消费 交易是否达标 let is_grant = getIntValue(current: indexPath.row, key: "is_grant") //总累积消费 let is_standard = getIntValue(current: indexPath.row, key: "is_standard") let standard_reward_st = getString(current: indexPath.row, key: "standard_reward_st") if is_grant == 0 && is_standard == 0{ cell.lblJD.text = "未达标" cell.lblJD.textColor = .orange if standard_reward_st == "0" { cell.lblRight.text = "达标激活奖励未发放" cell.lblRight.textColor = .red }else if standard_reward_st == "1" { cell.lblRight.text = "达标激活奖励已发放" cell.lblRight.textColor = .colorWithCustom(r: 55, g: 192, b: 102) }else { cell.lblRight.text = "达标激活奖励已发放" cell.lblRight.textColor = .colorWithCustom(r: 55, g: 192, b: 102) } } if is_grant != 0 { if standard_reward_st == "0" { cell.lblRight.text = "达标激活奖励未发放" cell.lblRight.textColor = .red }else if standard_reward_st == "1" { cell.lblRight.text = "达标激活奖励已发放" cell.lblRight.textColor = .colorWithCustom(r: 55, g: 192, b: 102) }else { cell.lblRight.text = "达标激活奖励已发放" cell.lblRight.textColor = .colorWithCustom(r: 55, g: 192, b: 102) } cell.lblJD.text = "\(is_grant)" + "阶段已达标" cell.lblJD.textColor = .colorWithCustom(r: 55, g: 192, b: 102) } if is_standard != 0 { if standard_reward_st == "0" { cell.lblRight.text = "达标激活奖励未发放" cell.lblRight.textColor = .red }else if standard_reward_st == "1" { cell.lblRight.text = "达标激活奖励已发放" cell.lblRight.textColor = .colorWithCustom(r: 55, g: 192, b: 102) }else { cell.lblRight.text = "达标激活奖励已发放" cell.lblRight.textColor = .colorWithCustom(r: 55, g: 192, b: 102) } cell.lblJD.text = "\(is_grant)" + "阶段已达标" cell.lblJD.textColor = .colorWithCustom(r: 55, g: 192, b: 102) } } return cell } var selectedIndex = -1 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { if indexPath.row >= arrData.count { return } let machineTypeId = getString(current: indexPath.row, key: "machine_type_id") if (machineTypeId == "1" || machineTypeId == "777" || machineTypeId == "888" || machineTypeId == "999" || machineTypeId == "9999"){ let vc = MyShopDetailTypeViewController() vc.id = getString(current: indexPath.row, key: "bind_merchant_id") vc.dicData.setDic(dic: self.arrData[indexPath.row] as! NSDictionary) toViewController(viewController: vc) } else { let vc = MyShopDetailViewController() let index: NSInteger = brandIdList.lastIndex(of: machineTypeId) ?? 0 if index == 2 || index == 3 { vc.isKssSer = true } vc.id = getString(current: indexPath.row, key: "bind_merchant_id") vc.dicData.setDic(dic: self.arrData[indexPath.row] as! NSDictionary) toViewController(viewController: vc) } } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) appDelegate.setNavigationBarHidden(isHidden: true) } override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { super.init(nibName: "MerchantsStateDetailVC", bundle: nil) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } }