123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- //
- // ApplyerViewController.swift
- // xingchuangke
- //
- // Created by Virgil on 2019/3/28.
- // Copyright © 2019 Virgil. All rights reserved.
- //
- import UIKit
- class ModBankCardViewController: BaseViewController, UITextFieldDelegate {
- @IBOutlet weak var txtType: UITextField!
- @IBOutlet weak var txtName: UITextField!
- @IBOutlet weak var txtBankChild: UITextField!
- @IBOutlet weak var txtBankAddress: UITextField!
- @IBOutlet weak var txtBank: UITextField!
- @IBOutlet weak var txtBankNo: UITextField!
- @IBOutlet weak var txtPhone: UITextField!
- @IBOutlet weak var btnFinish: UIButton!
- @IBOutlet weak var viewContent2: UIView!
- @IBOutlet weak var scrollView: UIScrollView!
- var addressIds = ["", "", ""]
- var addressNames = ["", "", ""]
- var zhiHangId = ""
- var zhiHangName = ""
- var bankCardCityName = ""
- var namem = ""
- var type = 0
- var arrBank = NSMutableArray()
- override func viewDidLoad() {
- super.viewDidLoad()
- self.title = "修改结算卡"
- initNavLeftBackButton()
- scrollView.setSizeWidth(width: ScreenWidth)
- // Do any additional setup after loading the view.
- scrollView.contentSize.height = btnFinish.bottom() + 80
- txtBank.delegate = self
- txtBankNo.delegate = self
- txtPhone.delegate = self
- scrollView.keyboardDismissMode = .onDrag
- let jsonPath = Bundle.main.path(forResource: "bankData", ofType: "json")
- do {
- let arrTemp = try CommonJSON.jsonToArray(json: String(contentsOfFile: jsonPath!))
- if arrTemp != nil {
- arrBank.setArray(arrTemp! as! [Any])
- }
- print(arrBank.count)
- } catch {}
- txtName.text = CommonValue.getUserRealName()
- }
- func initData() {
- let dicTemp = dicData["cardInfo"] as! NSDictionary
- txtBankAddress.text = "\(dicTemp.getString(key: "provincecn")) \(dicTemp.getString(key: "citycn")) \(dicTemp.getString(key: "areacn"))"
- txtBankNo.text = dicTemp.getString(key: "card_number")
- txtBankChild.text = dicTemp.getString(key: "affiliated_branch_bank")
- txtBank.text = dicTemp.getString(key: "affiliated_bank")
- txtPhone.text = dicTemp.getString(key: "reserve_phone")
- addressIds[0] = dicTemp.getString(key: "provinceid")
- addressIds[1] = dicTemp.getString(key: "cityid")
- addressIds[2] = dicTemp.getString(key: "areaid")
- zhiHangName = dicTemp.getString(key: "affiliated_branch_bank")
- addressNames[0] = dicTemp.getString(key: "provincecn")
- addressNames[1] = dicTemp.getString(key: "citycn")
- addressNames[2] = dicTemp.getString(key: "areacn")
- txtName.text = dicTemp.getString(key: "bank_account_name")
- self.bankCardCityName = dicTemp.getString(key: "citycn")
- type = dicTemp.getInt(key: "type")
- if type == 0 {
- txtName.isEnabled = false
- }
- }
- var viewSelectCity: Virgil_SelectCity!
- @IBAction func btnMenuClick(_ sender: AnyObject) {
- KeyboardHidden(gestureRecognizer: UIGestureRecognizer())
- switch (sender as! UIButton).tag {
- case 1001: // 身份证正面
- break
- case 1002: // 身份证背面
- break
- case 1003: // 手持身份证证件照
- break
- case 1004: // 辅助证明材料
- break
- case 1005: // 完成
- if txtName.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: "请输入开户名")
- return
- }
- if txtBankNo.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: "请输入银行卡号")
- return
- }
- // if(txtBank.text!.length() < 1 || txtBank.text! == "未识别银行")
- // {
- // SVProgressHUD.showError(withStatus: "请正确输入银行卡号");
- // return;
- // }
- if addressIds[1] == "" {
- SVProgressHUD.showError(withStatus: "请选择银行所在地区")
- return
- }
- if zhiHangName == "" {
- SVProgressHUD.showError(withStatus: "请选择所属支行")
- return
- }
- if txtPhone.text!.length() < 1 && type == 0 {
- SVProgressHUD.showError(withStatus: "请输入预留手机号")
- return
- }
- submitData()
- break
- case 1006: // 所属地区
- let addressList = CommonUntils.getPlistArrayForName(fileName: "AddressNew")
- if viewSelectCity == nil {
- viewSelectCity = Virgil_SelectCity(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: view.height()))
- viewSelectCity.modelType = 2
- viewSelectCity.initView(arrAddress: addressList) {[weak self] (dic) in
- self!.addressIds[0] = self!.getString(key: "addressId1", dic: dic)
- self!.addressIds[1] = self!.getString(key: "addressId2", dic: dic)
- self!.addressIds[2] = self!.getString(key: "addressId3", dic: dic)
- self!.addressNames[0] = self!.getString(key: "addressName1", dic: dic)
- self!.addressNames[1] = self!.getString(key: "addressName2", dic: dic)
- self!.addressNames[2] = self!.getString(key: "addressName3", dic: dic)
- self!.bankCardCityName = self!.getString(key: "addressName2", dic: dic)
- self!.txtBankAddress.text = self!.getString(key: "address", dic: dic)
- }
- self.view.addSubview(viewSelectCity)
- }
- viewSelectCity.showPickerView()
- break
- case 1007: // 所属支行
- if addressIds[1] == "" {
- SVProgressHUD.showError(withStatus: "请先选择省市区")
- return
- }
- let vc = SelectBankViewController()
- vc.provinceId = addressIds[0]
- vc.cityId = addressIds[1]
- var substr = ""
- if self.bankCardCityName.contains("市") {
- let arr = self.bankCardCityName.components(separatedBy: "市")
- substr = arr[0]
- }else {
- substr = self.bankCardCityName
- }
- namem = self.txtBank.text! + substr
- vc.bankName = namem //txtBank.text!;
- toViewController(viewController: vc)
- break
- case 1008: // 账户类型
- CommonUntils.AlertView(controller: self, title: nil, message: "请选择账户类型", buttons: ["个人账户", "对公账户"], style: .actionSheet) {[weak self] (index, _) in
- self!.type = index
- self!.txtType.text = ["个人账户", "对公账户"][index]
- if index == 1 {
- self!.viewContent2.setSizeHeight(height: 211)
- self!.txtName.isEnabled = true
- self!.txtName.text = ""
- } else {
- self!.txtName.isEnabled = false
- self!.txtName.text = CommonValue.getUserRealName()
- self!.viewContent2.setSizeHeight(height: 265)
- }
- }
- break
- default:
- break
- }
- }
- // MARK: =============加载数据===============
- func submitData() {
- let url = RequestURL.settlementCardUpdate
- let params = NSMutableDictionary()
- let dicTemp = dicData["cardInfo"] as? NSDictionary
- if dicTemp != nil {
- params.setValue(dicTemp!.getString(key: "id"), forKey: "id")
- }
- params.setValue(txtBankNo.text!, forKey: "cardNumber")
- params.setValue(txtBank.text!, forKey: "affiliatedBank")
- params.setValue(addressIds[0], forKey: "provinceId")
- params.setValue(addressIds[1], forKey: "cityId")
- params.setValue(addressIds[2], forKey: "areaId")
- params.setValue(addressNames[0], forKey: "provincecn")
- params.setValue(addressNames[1], forKey: "citycn")
- params.setValue(addressNames[2], forKey: "areacn")
- params.setValue(zhiHangName, forKey: "affiliatedBranchBank")
- params.setValue(txtPhone.text!, forKey: "reservePhone")
- params.setValue(type, forKey: "type")
- params.setValue(txtName.text!, forKey: "bankAccountName")
- submitData(url: url, params: params, tag: 1001)
- }
- func loadData() {
- let url = RequestURL.mySettlementCard
- let params = NSMutableDictionary()
- loadDataInfo(url: url, params: params, tag: 1002)
- }
- override func returnData(tag: Int) {
- if tag == 1001 {
- appDelegate.reloadUserInfo()
- SVProgressHUD.showSuccess(withStatus: "修改成功")
- handleBack()
- } else if tag == 1002 {
- if dicData["cardInfo"] as? NSDictionary != nil {
- initData()
- }
- }
- }
- override func returnError(tag: Int, type: String) {
- }
- override func handleBack() {
- self.navigationController?.popViewController(animated: true)
- }
- override func KeyboardHidden(gestureRecognizer: UIGestureRecognizer) {
- txtBankNo.resignFirstResponder()
- txtBank.resignFirstResponder()
- txtBankChild.resignFirstResponder()
- txtBankAddress.resignFirstResponder()
- txtPhone.resignFirstResponder()
- txtName.resignFirstResponder()
- }
- func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
- tempTextFeild = textField
- return true
- }
- func textFieldDidEndEditing(_ textField: UITextField) {
- if textField.tag == 1003 {
- let str = textField.text!
- if str.length() > 5 {
- loadBankName()
- }
- }
- }
- func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
- return true
- }
- func loadBankName() {
- var str8 = ""
- var str6 = ""
- if txtBankNo.text!.length() >= 8 {
- str8 = txtBankNo.text!.substringTo(index: 8)
- str6 = txtBankNo.text!.substringTo(index: 6)
- }
- if txtBankNo.text!.length() >= 6 {
- str6 = txtBankNo.text!.substringTo(index: 6)
- } else {
- txtBank.text = "未识别银行"
- return
- }
- if arrBank.count > 0 {
- var isFined = false
- for dic in arrBank {
- let bin = (dic as! NSDictionary).getString(key: "bin")
- if bin == str8 || bin == str6 {
- isFined = true
- txtBank.text = (dic as! NSDictionary).getString(key: "bankName").split(s: "-")[0]
- break
- }
- }
- if !isFined {
- txtBank.text = "未识别银行"
- }
- } else {
- txtBank.text = "未识别银行"
- }
- }
- var tempTextFeild: UITextField!
- override func keyboardWasShown(noti: NSNotification) {
- DispatchQueue.main.async { [weak self] in
- if self!.tempTextFeild == nil {
- return
- }
- let info = noti.userInfo
- let keyHe = (info![UIResponder.keyboardFrameEndUserInfoKey] as! NSValue).cgRectValue.size.height
- //文本框距上的高度
- let viewTop = CommonViewUntils.getControlRectForScreen(view: self!.tempTextFeild).origin.y + self!.tempTextFeild.height()
- if viewTop + 64 > (ScreenHeight - keyHe) {
- self!.scrollView.marginTop(top: -(viewTop - (self!.viewHeight - keyHe)) - 64)
- }
- }
- }
- override func keyboardWasHidden(noti: NSNotification) {
- DispatchQueue.main.async { [weak self] in
- UIView.animate(withDuration: 0.3, animations: {
- self!.scrollView.marginTop(top: 0)
- })
- }
- }
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- if mainViewControllerIsGo {
- if mainViewControllerIsGoType == 0 {
- zhiHangId = mainViewControllerIsGoValue1
- zhiHangName = mainViewControllerIsGoValue
- txtBankChild.text = zhiHangName
- }
- }
- mainViewControllerIsGo = false
- if !isLoad {
- loadData()
- isLoad = true
- }
- }
- override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
- super.init(nibName: "ModBankCardViewController", bundle: nil)
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- }
|