123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463 |
- //
- // BalanceAccountViewController.swift
- // xingchuangke
- //
- // Created by Virgil on 2019/3/29.
- // Copyright © 2019 Virgil. All rights reserved.
- //
- import UIKit
- class BalanceAccountViewController: BaseViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextFieldDelegate {
- var shopOpen: ShopOpenEntity!
- @IBOutlet weak var viewType2: UIView!
- @IBOutlet weak var viewType1: UIView!
- @IBOutlet weak var txtPhone: UITextField!
- ///0:对私账户 1:对公账户
- var accountType = 0
- @IBOutlet weak var lblAccountTitle: UILabel!
- @IBOutlet weak var img1: UIImageView!
- @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 txtCard: UITextField!
- @IBOutlet weak var btnAccountType: UIButton!
- @IBOutlet weak var lblAccountType: UITextField!
- @IBOutlet weak var lblCardTitle: UILabel!
- @IBOutlet weak var scrollView: UIScrollView!
- @IBOutlet weak var btnFinish: UIButton!
- @IBOutlet weak var viewContent: UIView!
- @IBOutlet weak var txtName: UITextField!
- var addressIds = ["", "", ""]
- var addressNames = ["", "", ""]
- var imgUrl1 = ""
- var zhiHangId = ""
- var yinhangId = ""
- var zhiHangName = ""
- var bankCardCityName = ""
- var namem = ""
- var arrBank = NSMutableArray()
- override func viewDidLoad() {
- super.viewDidLoad()
- self.title = "结算账户信息"
- initNavLeftBackButton()
- txtName.delegate = self
- txtBank.delegate = self
- txtBankNo.delegate = self
- loadDefaultData()
- 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 {}
- txtPhone.delegate = self
- txtPhone.tag = 9009
- // Do any additional setup after loading the view.
- }
- func loadDefaultData() {
- imgUrl1 = shopOpen.bankCardImage
- addressIds[0] = shopOpen.bankAddressId1
- addressIds[1] = shopOpen.bankAddressId2
- addressIds[2] = shopOpen.bankAddressId3
- addressNames[0] = shopOpen.bankAddressName1
- addressNames[1] = shopOpen.bankAddressName2
- addressNames[2] = shopOpen.bankAddressName3
- if shopOpen.bankOpenName != "" {
- txtName.text = shopOpen.bankOpenName
- } else if shopOpen.name != "" {
- txtName.text = shopOpen.name
- }
- txtBankNo.text = shopOpen.bankCardNo
- txtBank.text = shopOpen.bankName
- txtBankAddress.text = addressNames.joined(separator: " ")// shopOpen.bankAddress
- txtBankChild.text = shopOpen.bankAffiliatedBranchBankCN
- txtPhone.text = shopOpen.reservePhone
- zhiHangId = shopOpen.bankAffiliatedBranchBank
- zhiHangName = shopOpen.bankAffiliatedBranchBankCN
- imgLocalPath = shopOpen.bankCardImgLocal
- yinhangId = shopOpen.bankAffiliatedBank
- accountType = 0
- reSetView()
- if shopOpen.bankCardImage != "" {
- img1.loadImage(imgUrl: shopOpen.bankCardImage, defaultImage: "")
- }
- // if(shopOpen.bankAccountType == "0")
- // {
- // accountType = 0
- // reSetView();
- // if(shopOpen.bankCardImage != "")
- // {
- // img1.loadImage(imgUrl: shopOpen.bankCardImage, defaultImage: "")
- // }
- // }
- // else if(shopOpen.bankAccountType == "1")
- // {
- // accountType = 1
- // reSetView();
- //
- // if(shopOpen.openingPermitImage != "")
- // {
- // img1.loadImage(imgUrl: shopOpen.openingPermitImage, defaultImage: "")
- // }
- // }
- // else
- // {
- // if(shopOpen.shopType == 0)
- // {
- // btnAccountType.isEnabled = false;
- // accountType = 0
- // reSetView();
- // }
- // else
- // {
- // btnAccountType.isEnabled = true;
- // accountType = 1
- // reSetView();
- // }
- // }
- }
- override func KeyboardHidden(gestureRecognizer: UIGestureRecognizer) {
- txtName.resignFirstResponder()
- txtBankNo.resignFirstResponder()
- txtBank.resignFirstResponder()
- txtBankChild.resignFirstResponder()
- txtBankAddress.resignFirstResponder()
- txtPhone.resignFirstResponder()
- }
- var viewSelectCity: Virgil_SelectCity!
- @IBAction func btnMenuClick(_ sender: AnyObject) {
- switch (sender as! UIButton).tag {
- case 1001: // 上传照片
- uploadImage(type: 0)
- break
- case 1002: // 所属地区
- 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 1003: // 所属支行
- // if(addressIds[1] == "")
- // {
- // SVProgressHUD.showError(withStatus: "请先选择省市区")
- // return;
- // }
- let vc = SelectBankViewController()
- vc.shopEntity = shopOpen
- 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 1004: // 完成
- if shopOpen.shopType == 0 {
- if imgUrl1 == "" {
- SVProgressHUD.showError(withStatus: "请上传银行卡照片")
- return
- }
- } else {
- if imgUrl1 == "" {
- SVProgressHUD.showError(withStatus: "请上传银行卡照片")
- return
- }
- }
- 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 txtBankChild.text! == "" || zhiHangId == "" {
- SVProgressHUD.showError(withStatus: "请选择所属支行")
- return
- }
- if shopOpen.shopType == 0 {
- if txtPhone.text! == "" {
- SVProgressHUD.showError(withStatus: "请输入预留手机号")
- return
- }
- }
- shopOpen.bankAccountType = "\(accountType)"
- if shopOpen.shopType == 0 {
- shopOpen.bankCardImage = imgUrl1
- shopOpen.reservePhone = txtPhone.text!
- } else {
- shopOpen.openingPermitImage = imgUrl1
- }
- shopOpen.bankCardImage = imgUrl1
- shopOpen.bankOpenName = txtName.text!
- shopOpen.bankCardNo = txtBankNo.text!
- shopOpen.bankName = txtBank.text!
- shopOpen.bankAddress = txtBankAddress.text!
- shopOpen.bankAffiliatedBranchBankCN = txtBankChild.text!
- shopOpen.bankAddressId1 = addressIds[0]
- shopOpen.bankAddressId2 = addressIds[1]
- shopOpen.bankAddressId3 = addressIds[2]
- shopOpen.bankAddressName1 = addressNames[0]
- shopOpen.bankAddressName2 = addressNames[1]
- shopOpen.bankAddressName3 = addressNames[2]
- shopOpen.bankAffiliatedBranchBank = zhiHangId
- shopOpen.bankCardImgLocal = imgLocalPath
- shopOpen.bankAffiliatedBranchBankCN = txtBankChild.text!
- shopOpen.bankAffiliatedBank = yinhangId
- handleBack()
- break
- case 1005: // 账户类型 0:对私 1:对公
- CommonUntils.AlertView(controller: self, title: nil, message: "请选择账户类型", buttons: ["对私账户", "对公账户"], style: .actionSheet) {[weak self] (index, _) in
- self!.accountType = index
- self!.reSetView()
- }
- break
- case 1006: //
- break
- default:
- break
- }
- }
- func reSetView() {
- if accountType == 0 {
- lblAccountType.text = "对私账户"
- lblCardTitle.text = "银行卡正面"
- lblAccountTitle.text = "结算人姓名"
- viewContent.setSizeHeight(height: 317)
- } else {
- lblAccountType.text = "对公账户"
- lblCardTitle.text = "开户许可证"
- lblAccountTitle.text = "结算账户名称"
- viewContent.setSizeHeight(height: 315)
- }
- btnFinish.marginTop(top: 40, view: viewContent)
- scrollView.contentSize.height = btnFinish.bottom() + 60
- }
- func textFieldDidEndEditing(_ textField: UITextField) {
- if textField.tag == 1003 {
- let str = textField.text!
- if str.length() > 5 {
- loadBankName()
- }
- }
- }
- 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 = "未识别银行"
- }
- }
- // MARK: ============选择头像============
- var uploadImageType = 0
- func uploadImage(type: Int) {
- uploadImageType = type
- CommonUntils.AlertView(controller: self, title: nil, message: nil, buttons: ["拍照上传", "从相册上传"], style: .actionSheet) {[weak self] (index, _) in
- let ipc = UIImagePickerController()
- if index == 0 {
- ipc.sourceType = .camera
- } else {
- ipc.sourceType = .photoLibrary
- }
- ipc.delegate = self!
- ipc.allowsEditing = false
- self!.present(ipc, animated: true, completion: nil)
- }
- }
- var imgTemp: UIImage!
- func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) {
- self.dismiss(animated: true) {[weak self] in
- var imgTemp: UIImage? = info[UIImagePickerController.InfoKey.originalImage] as? UIImage
- if picker.allowsEditing {
- imgTemp = info[UIImagePickerController.InfoKey.editedImage] as? UIImage
- }
- if imgTemp != nil {
- self!.UploadFile(img: imgTemp!)
- } else {
- SVProgressHUD.showError(withStatus: "图片选择失败,请重试")
- }
- }
- }
- func UploadFile(img: UIImage) {
- MBProgressHUD.showAdded(to: self.view, animated: true)
- let uploadFile = QiNiuUploadFile()
- uploadFile.uploadFile(img: img) {[weak self] (type, str) in
- if type == 1 {
- self!.uploadWeb(img: img)
- let userLoginUrl = RequestURL.qiNiuImageUrl + str
- self!.imgUrl1 = userLoginUrl
- self!.img1.loadImage(imgUrl: self!.imgUrl1, defaultImage: "")
- } else {
- MBProgressHUD.hide(for: self!.view, animated: true)
- SVProgressHUD.showError(withStatus: "上传失败")
- }
- }
- }
- var imgLocalPath = ""
- func uploadWeb(img: UIImage) {
- let manage = AFHTTPSessionManager()
- let param = NSMutableDictionary()
- param.setValue(8, forKey: "type")
- manage.requestSerializer.timeoutInterval = 60.0
- manage.post(RequestURL.uploadMerchantFile, parameters: param, constructingBodyWith: { (formDate) in
- formDate.appendPart(withFileData: img.jpegData(compressionQuality: 0.4)!, name: "fileInput", fileName: "fileInput", mimeType: "multipart/form-data")
- }, progress: nil, success: {[weak self] (op, json1) in
- let json = json1 as! NSDictionary
- print(json)
- let succeed = json.object(forKey: "succeed") as! String
- if succeed == "000" {
- let status = (json["dataInfo"] as! NSDictionary).getInt(key: "statusCode")
- if status == 200 {
- self!.imgLocalPath = (json["dataInfo"] as! NSDictionary).getString(key: "url")
- let haike = (json["dataInfo"] as! NSDictionary)["haike"] as! NSDictionary
- let hkResult = haike["result"] as! NSDictionary
- let hkResultData = hkResult["data"] as! NSDictionary
- self!.txtBank.text = hkResultData.getString(key: "bankName")
- self!.txtBankNo.text = hkResultData.getString(key: "cardNumber")
- } else {
- SVProgressHUD.showError(withStatus: "银行卡识别失败,请重新上传或手动输入银行卡号!")
- }
- } else {
- SVProgressHUD.showInfo(withStatus: "上传失败,请重新上传")
- //CommonUntils.alert(message: json.object(forKey: "sucInfo") as! String)
- }
- MBProgressHUD.hide(for: self!.view, animated: true)
- }) { (_, _) in
- SVProgressHUD.showInfo(withStatus: "上传失败,请重新上传")
- MBProgressHUD.hide(for: self.view, animated: true)
- }
- }
- func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
- tempTextFeild = textField
- return true
- }
- var tempTextFeild: UITextField!
- override func keyboardWasShown(noti: NSNotification) {
- if tempTextFeild == nil || tempTextFeild.tag != 9009 {
- return
- }
- DispatchQueue.main.async { [weak self] in
- 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 - (ScreenHeight - keyHe)))
- }
- }
- }
- override func keyboardWasHidden(noti: NSNotification) {
- self.scrollView.marginTop(top: 0)
- }
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- if mainViewControllerIsGo {
- if mainViewControllerIsGoType == 0 {
- zhiHangId = mainViewControllerIsGoValue1
- zhiHangName = mainViewControllerIsGoValue
- yinhangId = mainViewControllerIsGoValue2
- txtBankChild.text = zhiHangName
- }
- }
- mainViewControllerIsGo = false
- }
- override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
- super.init(nibName: "BalanceAccountViewController", bundle: nil)
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- }
|