123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457 |
- //
- // OpenDetailViewController.swift
- // xingchuangke
- //
- // Created by Virgil on 2019/3/28.
- // Copyright © 2019 Virgil. All rights reserved.
- //
- import UIKit
- class OpenDetailViewController: BaseViewController, UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate {
- @IBOutlet weak var txtNoPassContent: UITextView!
- @IBOutlet weak var lblNoAlert: UILabel!
- var localCurrnetIndex = -1
- @IBOutlet weak var viewFooter: UIView!
- @IBOutlet weak var btnNextPage: UIButton!
- var shopOpen: ShopOpenEntity!
- var arrTitle = [["公司简称", "申请人信息", "店铺信息", "所属行业", "结算信息", "费率"], ["店铺照片", "商户合影照"]]
- var arrRemark = [["公司名称+所属行业", "请上传照片", "请填写详细地址", "请选择", "请上传照片", ""], ["选填,请上传照片", "选填,请上传照片"]]
- var arrRemarkDefault = [["公司名称+所属行业", "请上传照片", "请填写详细地址", "请选择", "请上传照片", ""], ["选填,请上传照片", "选填,请上传照片"]]
- @IBOutlet weak var tableView: UITableView!
- var isSaveLocal = false
- ///0:正常 1:审核被拒
- var type = 0
- var isMod = true
- override func viewDidLoad() {
- super.viewDidLoad()
- initNavLeftBackButton()
- title = "开通详情"
- tableView.register(UINib(nibName: "OpenDetailTableViewCell", bundle: nil), forCellReuseIdentifier: "OpenDetailTableViewCell")
- tableView.delegate = self
- tableView.dataSource = self
- tableView.separatorStyle = .none
- tableView.showsVerticalScrollIndicator = false
- tableView.estimatedRowHeight = 100
- tableView.keyboardDismissMode = .onDrag
- viewFooter.setSizeWidth(width: ScreenWidth)
- viewFooter.removeFromSuperview()
- tableView.tableFooterView = viewFooter
- if shopOpen.rate == "" {
- getFeiLv(isDefault: true)
- } else {
- arrRemark[0][5] = "\(shopOpen.rate)%"
- }
- }
- override func handleBack() {
- if shopOpen.companyName != "" && isSaveLocal {
- CommonUntils.AlertView(controller: self, title: "提示", message: "资料尚未提交,是否先保存到本地?", buttons: ["保存"], style: .alert, actionHandler: {[weak self] (_, _) in
- self!.saveInfoToLocal()
- }) {
- super.handleBack()
- }
- } else {
- super.handleBack()
- }
- }
- func initData() {
- arrRemark[0][0] = shopOpen.companyName
- reloadAlertInfo()
- }
- func saveInfoToLocal() {
- let arrLocal = NSMutableArray()
- let local = CommonValue.getDefaultUserInfoForObject(key: "common_local_businfo")
- if local != nil && (local as? NSArray) != nil && (local as! NSArray).count > 0 {
- arrLocal.addObjects(from: ((local as! NSArray) as! [Any]))
- }
- let dic = shopOpen.mj_keyValues()!
- dic.setValue(CommonDate.getStringForDate(date: Date(), dateFormat: "yyyy-MM-dd HH:mm:ss"), forKey: "createtime")
- if localCurrnetIndex != -1 && arrLocal.count > localCurrnetIndex {
- arrLocal.removeObject(at: localCurrnetIndex)
- }
- arrLocal.add(dic)
- CommonValue.setDefaultUserInfoForObject(value: arrLocal, key: "common_local_businfo")
- if localCurrnetIndex == -1 {
- if !CommonUntils.reBackView(controller: self, aclass: ShopManagerViewController.classForCoder()) {
- self.navigationController?.popToRootViewController(animated: true)
- }
- } else {
- super.handleBack()
- }
- }
- // MARK: TABLEVLEW 实现
- func numberOfSections(in tableView: UITableView) -> Int {
- return arrTitle.count
- }
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return arrTitle[section].count
- }
- func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
- return 55
- }
- func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
- let view = CommonViewUntils.getViewForXIB(xibName: "OpenDetailTableViewHeaderView") as! OpenDetailTableViewHeaderView
- view.initView(section: section)
- return view
- }
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- return 50
- }
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: "OpenDetailTableViewCell", for: indexPath as IndexPath) as! OpenDetailTableViewCell
- //cell.lblTitle.text = getString(indexPath.row, key: "Name")
- cell.lblTitle.text = arrTitle[indexPath.section][indexPath.row]
- cell.lblDesc.text = arrRemark[indexPath.section][indexPath.row]
- if arrTitle[indexPath.section][indexPath.row] == "公司简称" {
- cell.txtContent.isHidden = false
- cell.txtContent.delegate = self
- cell.txtContent.text = shopOpen.companyName
- cell.txtContent.placeholder = arrRemark[indexPath.section][indexPath.row]
- cell.lblDesc.isHidden = true
- cell.btnRight.setImage(UIImage(named: "ion_opening_merchants_02"), for: .normal)
- cell.btnRight.addTarget(self, action: #selector(btnRemarkClick), for: .touchUpInside)
- } else {
- cell.txtContent.isHidden = true
- cell.lblDesc.isHidden = false
- cell.btnRight.removeTarget(self, action: #selector(btnRemarkClick), for: .touchUpInside)
- cell.btnRight.setImage(UIImage(named: "ion_arrow_right_gray"), for: .normal)
- }
- return cell
- }
- func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
- // if(string != "")
- // {
- // shopOpen.companyName = "\(textField.text!)\(string)"
- // }
- // else
- // {
- // if(textField.text!.length() > 0)
- // {
- // shopOpen.companyName = textField.text!.substringTo(index: textField.text!.length() - 1)
- // }
- // }
- return true
- }
- func textFieldDidEndEditing(_ textField: UITextField) {
- shopOpen.companyName = textField.text!
- print(shopOpen.companyName)
- }
- @IBAction func btnSubmitClick(_ sender: Any) {
- if shopOpen.companyName.length() < 1 {
- SVProgressHUD.showError(withStatus: "请输入公司简称")
- return
- }
- if arrRemark[0][1] != "已填写" {
- SVProgressHUD.showError(withStatus: "请填写申请人信息")
- return
- }
- if arrRemark[0][2] != "已填写" {
- SVProgressHUD.showError(withStatus: "请填写店铺地址")
- return
- }
- if arrRemark[0][3] != "已填写" {
- SVProgressHUD.showError(withStatus: "请填写所属行业")
- return
- }
- if arrRemark[0][4] != "已填写" {
- SVProgressHUD.showError(withStatus: "请填写结算信息")
- return
- }
- if shopOpen.rate == "" {
- SVProgressHUD.showError(withStatus: "请选择费率")
- return
- }
- submitData()
- }
- // MARK: =============加载数据===============
- func submitData() {
- let params = NSMutableDictionary()
- var url = RequestURL.openingMerchants
- if shopOpen.id != "" {
- url = RequestURL.editMerchants
- params.setValue(shopOpen.id, forKey: "merchantsId")
- }
- params.setValue(CommonValue.getUserId(), forKey: "userId")
- params.setValue(shopOpen.posId, forKey: "machineTypeId")
- params.setValue(shopOpen.posSN, forKey: "machineSnCode")
- params.setValue(shopOpen.shopType, forKey: "busType")
- params.setValue(shopOpen.phone, forKey: "busPhone")
- params.setValue(shopOpen.companyName, forKey: "companyName")
- params.setValue(shopOpen.name, forKey: "applicantName")
- params.setValue(shopOpen.card, forKey: "applicantCard")
- params.setValue(shopOpen.cardFront, forKey: "applicantCardFront")
- params.setValue(shopOpen.cardReverse, forKey: "applicantCardReverse")
- params.setValue(shopOpen.cardHoldFront, forKey: "applicantCardHoldFront")
- params.setValue(shopOpen.otherImage, forKey: "applicantCardHoldReverse")
- params.setValue(shopOpen.addressDetail, forKey: "shopAddress")
- params.setValue(shopOpen.addressId1, forKey: "shopProvinceId")
- params.setValue(shopOpen.addressId2, forKey: "shopCityId")
- params.setValue(shopOpen.addressId3, forKey: "shopAreaId")
- params.setValue(shopOpen.addressName1, forKey: "provinceCN")
- params.setValue(shopOpen.addressName2, forKey: "cityCN")
- params.setValue(shopOpen.addressName3, forKey: "areaCN")
- params.setValue(shopOpen.typeId2, forKey: "categoryTwoId")
- params.setValue(shopOpen.typeId1, forKey: "categoryOneId")
- params.setValue(shopOpen.bankCardNo, forKey: "bankCardNumber")
- params.setValue(shopOpen.bankAddressId1, forKey: "bankProvinceId")
- params.setValue(shopOpen.bankAddressId2, forKey: "bankCityId")
- params.setValue(shopOpen.bankAddressId3, forKey: "bankAreaId")
- params.setValue(shopOpen.bankAddressName1, forKey: "bankProvinceCN")
- params.setValue(shopOpen.bankAddressName2, forKey: "bankCityCN")
- params.setValue(shopOpen.bankAddressName3, forKey: "bankAreaCN")
- //params.setValue(shopOpen.bankAddressName3, forKey: "bankAreaCN")
- params.setValue(shopOpen.bankAffiliatedBranchBank, forKey: "bankAffiliatedBranchBank")
- params.setValue(shopOpen.bankOpenName, forKey: "bankOpenName")
- params.setValue(shopOpen.bankCardImage, forKey: "bankCardImg")
- params.setValue(shopOpen.typeName1, forKey: "categoryONECN")
- params.setValue(shopOpen.typeName2, forKey: "categoryTWOCN")
- params.setValue(shopOpen.licenseImage, forKey: "licenseImage")
- params.setValue(shopOpen.licenseNum, forKey: "licenseNum")
- params.setValue(shopOpen.bankAccountType, forKey: "bankAccountType")
- params.setValue(shopOpen.openingPermitImage, forKey: "openingPermitImage")
- params.setValue(shopOpen.reservePhone, forKey: "reservePhone")
- params.setValue(shopOpen.bankName, forKey: "bankAffiliatedBankCN")
- params.setValue(shopOpen.bankAffiliatedBank, forKey: "bankAffiliatedBank")
- params.setValue(shopOpen.applicantCardFrontLocal, forKey: "applicantCardFrontLocal")
- params.setValue(shopOpen.applicantCardReverseLocal, forKey: "applicantCardReverseLocal")
- params.setValue(shopOpen.applicantCardHoldFrontLocal, forKey: "applicantCardHoldFrontLocal")
- params.setValue(shopOpen.bankCardImgLocal, forKey: "bankCardImgLocal")
- params.setValue(shopOpen.bankAffiliatedBranchBankCN, forKey: "bankAffiliatedBranchBankCN")
- params.setValue(shopOpen.dpImages, forKey: "shopPhoto")
- params.setValue(shopOpen.shhyzImages, forKey: "shopUserPhoto")
- params.setValue(shopOpen.productTypeId, forKey: "productTypeId")
- params.setValue(shopOpen.rate, forKey: "rate")
- params.setValue(shopOpen.debitCardCostRate, forKey: "debitCardCostRate")
- params.setValue(shopOpen.debitCardCapping, forKey: "debitCardCapping")
- params.setValue(shopOpen.unionpayRate, forKey: "unionpayRate")
- params.setValue(shopOpen.loanCardCapping, forKey: "loanCardCapping")
- submitData(url: url, params: params, tag: 1001)
- }
- ///费率
- let dicFL = NSMutableDictionary()
- func getFeiLv(isDefault: Bool) {
- if dicFL.count > 0 {
- returnData(tag: 1003)
- return
- }
- let params = NSMutableDictionary()
- let url = RequestURL.rateConfig
- params.setValue(shopOpen.posId, forKey: "machine_type_id")
- params.setValue(shopOpen.shopType, forKey: "merchant_type")
- params.setValue(shopOpen.productTypeId, forKey: "product_type_id")
- if isDefault {
- loadDataInfo(url: url, params: params, tag: 1002, reDic: dicFL)
- } else {
- loadDataInfo(url: url, params: params, tag: 1003, reDic: dicFL)
- }
- }
- override func returnData(tag: Int) {
- if tag == 1001 {
- let arrLocal = NSMutableArray()
- let local = CommonValue.getDefaultUserInfoForObject(key: "common_local_businfo")
- if local != nil && (local as? NSArray) != nil && (local as! NSArray).count > 0 {
- arrLocal.addObjects(from: ((local as! NSArray) as! [Any]))
- }
- if localCurrnetIndex != -1 && arrLocal.count > localCurrnetIndex {
- arrLocal.removeObject(at: localCurrnetIndex)
- }
- CommonValue.setDefaultUserInfoForObject(value: arrLocal, key: "common_local_businfo")
- if shopOpen.id == "" {
- SVProgressHUD.showSuccess(withStatus: "信息提交成功,请等待审核!")
- self.cusHandleBack()
- } else {
- self.cusHandleBack()
- }
- } else if(tag == 1002) //初始化加载默认费率
- {
- shopOpen.rate = String.init(format: "%.2f", dicFL.getDouble(key: "loan_card_rate_default"))
- shopOpen.debitCardCostRate = String.init(format: "%.2f", dicFL.getDouble(key: "debit_card_cost_rate"))
- shopOpen.debitCardCapping = String.init(format: "%.2f", dicFL.getDouble(key: "debit_card_capping"))
- shopOpen.unionpayRate = String.init(format: "%.2f", dicFL.getDouble(key: "unionpay_rate"))
- shopOpen.loanCardCapping = String.init(format: "%.2f", dicFL.getDouble(key: "loan_card_capping"))
- arrRemark[0][5] = "\(String.init(format: "%.2f", dicFL.getDouble(key: "loan_card_rate_default")))%"
- self.tableView.reloadData()
- } else if(tag == 1003) //加载费率选择框
- {
- shopOpen.rate = String.init(format: "%.2f", dicFL.getDouble(key: "loan_card_rate_default"))
- shopOpen.debitCardCostRate = String.init(format: "%.2f", dicFL.getDouble(key: "debit_card_cost_rate"))
- shopOpen.debitCardCapping = String.init(format: "%.2f", dicFL.getDouble(key: "debit_card_capping"))
- shopOpen.unionpayRate = String.init(format: "%.2f", dicFL.getDouble(key: "unionpay_rate"))
- shopOpen.loanCardCapping = String.init(format: "%.2f", dicFL.getDouble(key: "loan_card_capping"))
- var rateMin = dicFL.getDouble(key: "loan_card_rate_min") * 100
- let rateMax = dicFL.getDouble(key: "loan_card_rate_max") * 100
- arrRateContent.removeAll()
- var arrTitle = [String]()
- while Int(rateMin) <= Int(rateMax) {
- arrTitle.append("\(String.init(format: "%.2f", rateMin / 100))%")
- arrRateContent.append(String.init(format: "%.2f", rateMin / 100))
- rateMin += 1
- }
- CommonUntils.AlertView(controller: self, title: nil, message: "请选择费率", buttons: arrTitle, style: .actionSheet) {[weak self] (index, _) in
- self!.arrRemark[0][5] = "\(self!.arrRateContent[index])%"
- self!.shopOpen.rate = self!.arrRateContent[index]
- self!.tableView.reloadData()
- }
- }
- }
- var arrRateContent = [String]()
- override func returnError(tag: Int, type: String) {
- }
- func cusHandleBack() {
- if !CommonUntils.reBackView(controller: self, aclass: ShopManagerViewController.classForCoder()) {
- self.navigationController?.popToRootViewController(animated: true)
- }
- }
- @objc func btnRemarkClick(btn: UIButton) {
- let vc = CommonWebViewViewController()
- vc.strTitle = "公司名称规则"
- vc.sourceType = 1
- vc.url = "\(RequestURL.sysConfigWeb)?type=company_name"
- toViewController(viewController: vc)
- }
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- //[["公司简称","申请人信息","店铺地址","所属行业","结算信息"],["店铺照片","商户合影照"]]
- if arrTitle[indexPath.section][indexPath.row] == "公司简称" {
- } else if arrTitle[indexPath.section][indexPath.row] == "申请人信息" {
- let vc = ApplyerViewController()
- vc.shopOpen = self.shopOpen
- toViewController(viewController: vc)
- } else if arrTitle[indexPath.section][indexPath.row] == "店铺信息" {
- let vc = ShopAddressViewController()
- vc.shopOpen = self.shopOpen
- toViewController(viewController: vc)
- } else if arrTitle[indexPath.section][indexPath.row] == "所属行业" {
- let vc = ShopIndustryViewController()
- vc.shopOpen = self.shopOpen
- toViewController(viewController: vc)
- } else if arrTitle[indexPath.section][indexPath.row] == "结算信息" {
- let vc = BalanceAccountViewController()
- vc.shopOpen = self.shopOpen
- toViewController(viewController: vc)
- } else if arrTitle[indexPath.section][indexPath.row] == "店铺照片" {
- let vc = AddImagesViewController()
- vc.shopOpen = shopOpen
- vc.type = 0
- vc.initView()
- toViewController(viewController: vc)
- } else if arrTitle[indexPath.section][indexPath.row] == "费率" {
- getFeiLv(isDefault: false)
- } else if arrTitle[indexPath.section][indexPath.row] == "商户合影照" {
- let vc = AddImagesViewController()
- vc.shopOpen = shopOpen
- vc.type = 1
- vc.initView()
- toViewController(viewController: vc)
- }
- }
- func reloadAlertInfo() {
- //arrRemark = [["公司名称+所属行业","请上传照片","请填写详细地址","请选择","请上传照片"],["选填,请上传照片","选填,请上传照片"]];
- if shopOpen.cardFront != "" {
- arrRemark[0][1] = "已填写"
- } else {
- arrRemark[0][1] = arrRemarkDefault[0][1]
- }
- if shopOpen.addressId1 != "" {
- arrRemark[0][2] = "已填写"
- } else {
- arrRemark[0][2] = arrRemarkDefault[0][2]
- }
- if shopOpen.typeId1 != "" {
- arrRemark[0][3] = "已填写"
- } else {
- arrRemark[0][3] = arrRemarkDefault[0][3]
- }
- if shopOpen.bankCardImage != "" {
- arrRemark[0][4] = "已填写"
- } else {
- arrRemark[0][4] = arrRemarkDefault[0][4]
- }
- if shopOpen.dpImages != "" {
- arrRemark[1][0] = "已上传\(shopOpen.dpImages.split(s: ",").count)张"
- } else {
- arrRemark[1][0] = arrRemarkDefault[1][0]
- }
- if shopOpen.shhyzImages != "" {
- arrRemark[1][1] = "已上传\(shopOpen.shhyzImages.split(s: ",").count)张"
- } else {
- arrRemark[1][1] = arrRemarkDefault[1][1]
- }
- tableView.reloadData()
- }
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- initData()
- if isMod {
- viewFooter.isHidden = false
- } else {
- viewFooter.isHidden = true
- }
- if type == 1 {
- lblNoAlert.isHidden = false
- txtNoPassContent.isHidden = false
- txtNoPassContent.text = shopOpen.reason
- }
- }
- override func viewDidAppear(_ animated: Bool) {
- super.viewDidAppear(animated)
- closeRightBack()
- }
- override func viewWillDisappear(_ animated: Bool) {
- super.viewWillDisappear(animated)
- }
- override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
- super.init(nibName: "OpenDetailViewController", bundle: nil)
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- }
- extension UserDefaults {
- func saveCustomObj(customObject object: NSCoding, key: String) {
- let encodedObject = NSKeyedArchiver.archivedData(withRootObject: object)
- self.setValue(encodedObject, forKey: key)
- self.synchronize()
- }
- }
|