123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547 |
- //
- // ShopAuthViewController.swift
- // xingchuangke
- //
- // Created by Virgil on 2019/8/12.
- // Copyright © 2019 Virgil. All rights reserved.
- //
- import UIKit
- class BJBusinessViewController: BaseViewController, AVCaptureViewControllerDelegate, CommonDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIScrollViewDelegate, UITextFieldDelegate {
- @IBOutlet weak var viewTitle1: UIView!
- @IBOutlet weak var viewTitle2: UIView!
- @IBOutlet weak var viewTitle4: UIView!
- @IBOutlet weak var view1: UIView!
- @IBOutlet weak var view2: UIView!
- @IBOutlet weak var view3: UIView!
- @IBOutlet weak var view4: UIView!
- @IBOutlet weak var view5: UIView!
- @IBOutlet weak var view6: UIView!
- @IBOutlet weak var view7: UIView!
- @IBOutlet weak var view8: UIView!
- @IBOutlet weak var view9: UIView!
- @IBOutlet weak var scrollView: UIScrollView!
- @IBOutlet weak var btnMenu1: UIButton!
- @IBOutlet weak var btnMenu2: UIButton!
- @IBOutlet weak var btnMenu3: UIButton!
- @IBOutlet weak var imgCard3: UIImageView!
- @IBOutlet weak var imgCard1: UIImageView!
- @IBOutlet weak var imgCard2: UIImageView!
- @IBOutlet weak var txtAddress: UITextField!
- @IBOutlet weak var txtChildBankName: UITextField!
- @IBOutlet weak var txtBankName: UITextField!
- @IBOutlet weak var txtJSYHYXQ: UITextField!
- @IBOutlet weak var txtFRYXQ: UITextField!
- @IBOutlet weak var viewContentHeight: NSLayoutConstraint!
- @IBOutlet weak var viewContentWidth: NSLayoutConstraint!
- @IBOutlet weak var viewContent: UIView!
- @IBOutlet weak var txtPhone: UITextField!
- @IBOutlet weak var txtBankCard: UITextField!
- @IBOutlet weak var txtIDCard: UITextField!
- @IBOutlet weak var txtName: UITextField!
-
- override func viewDidLoad() {
- super.viewDidLoad()
- self.title = "结算信息"
- initNavLeftBackButton()
- viewContentWidth.constant = ScreenWidth
- scrollView.delegate = self
- txtChildBankName.delegate = self
- txtPhone.delegate = self
- }
- override func KeyboardHidden(gestureRecognizer: UIGestureRecognizer) {
- txtName.resignFirstResponder()
- txtIDCard.resignFirstResponder()
- txtBankCard.resignFirstResponder()
- txtPhone.resignFirstResponder()
- txtChildBankName.resignFirstResponder()
- }
- var bankCardProvCode = ""
- var bankCardCityCode = ""
- var bankCardCityName = ""
- var namem = ""
- /// 0:选择结算银行
- var commonSelectType = 0
- //btnAddTarget(view: self.view, selector: #selector(self.btnMenuClick))
- @IBAction func btnMenuClick(_ sender: AnyObject) {
- KeyboardHidden(gestureRecognizer: UIGestureRecognizer())
- switch (sender as! UIButton).tag {
- case 1001: // 识别身份证号
- let vc = AVCaptureViewController()
- vc.delegate = self
- self.present(vc, animated: true) {
- }
- break
- case 1013: // 识别身份证号
- let vc = AVCaptureViewController()
- vc.delegate = self
- vc.cardType = 1
- self.present(vc, animated: true) {
- }
- break
- case 1012://银行卡识别
- uploadImage(type: 3)
- break
- case 1002: // 法人证件有效期
- let viewDatePicer = (CommonViewUntils.getViewForXIB(anyClass: Virgil_SelectDateForPickerView.self) as! Virgil_SelectDateForPickerView)
- var defaultDate: Date!
- if self.txtFRYXQ.text! == "" || self.txtFRYXQ.text!.length() != 10 {
- defaultDate = Date()
- } else {
- defaultDate = CommonDate.getDateForString(dateStr: self.txtFRYXQ.text!, dateFormat: "yyyy-MM-dd")
- }
- //viewDatePicer.datePicker.maximumDate = Date();
- viewDatePicer.showDatePickerView(defaultDate: defaultDate) {[weak self] (str) in
- self!.txtFRYXQ.text = str
- }
- break
- case 1003: // 下一步
- if txtName.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: "请输入结算卡姓名")
- return
- }
- if txtIDCard.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: "请输入法人证件号")
- return
- }
- if self.txtFRYXQ.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: "请选择法人证件有效期")
- return
- }
- // if(txtJSYHYXQ.text!.length() < 1)
- // {
- // SVProgressHUD.showError(withStatus: "请选择结算银行证件有效期")
- // return;
- // }
- if txtBankCard.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: "请输入结算卡号")
- return
- }
- if txtPhone.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: "请输入银行预留手机号")
- return
- }
- if txtBankName.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: "请选择结算银行名称")
- return
- }
- if txtChildBankName.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: "请输入结算银行支行名称")
- return
- }
- if bankCardCityCode.length() < 1 {
- SVProgressHUD.showError(withStatus: "请选择开户地区")
- return
- }
- if !btnMenu1.isSelected {
- SVProgressHUD.showError(withStatus: "请上传身份证正面")
- return
- }
- if !btnMenu2.isSelected {
- SVProgressHUD.showError(withStatus: "请上传身份证背面")
- return
- }
- if !btnMenu3.isSelected {
- SVProgressHUD.showError(withStatus: "请上传手持身份证照")
- return
- }
- appDelegate.openMerchants.settleName = txtName.text!
- appDelegate.openMerchants.bankcardID = txtIDCard.text!
- appDelegate.openMerchants.idCardNum = txtIDCard.text!
- appDelegate.openMerchants.legalcardValidityPeroid = txtFRYXQ.text!
- appDelegate.openMerchants.bankcardValidityPeroid = txtFRYXQ.text!//txtJSYHYXQ.text!
- appDelegate.openMerchants.accNum = txtBankCard.text!
- appDelegate.openMerchants.phoneShow = txtPhone.text!
- appDelegate.openMerchants.bankName = txtBankName.text!
- appDelegate.openMerchants.bankNameBranchCode = bankNameBranchCode
- appDelegate.openMerchants.bankNameBranchNo = bankNameBranchNo
- appDelegate.openMerchants.bankNameBranch = txtChildBankName.text!
- appDelegate.openMerchants.bankCardProvCode = bankCardProvCode
- appDelegate.openMerchants.bankCardCityCode = bankCardCityCode
- appDelegate.openMerchants.verifyDebitCardNum = ""
- appDelegate.openMerchants.verifyDebitPhoneYL = ""
- appDelegate.openMerchants.cardPositivePhoto = arrImages[0]
- appDelegate.openMerchants.cardNegativePhoto = arrImages[1]
- appDelegate.openMerchants.cardHandHoldPhoto = arrImages[2]
- appDelegate.openMerchants.cardPositivePhotoLocal = arrImagesLocal[0]
- appDelegate.openMerchants.cardNegativePhotoLocal = arrImagesLocal[1]
- appDelegate.openMerchants.cardHandHoldPhotoLocal = arrImagesLocal[2]
- toViewController(viewController: BJShopInfoViewController())
- break
- case 1004: // 结算银行证件有效期
- let viewDatePicer = (CommonViewUntils.getViewForXIB(anyClass: Virgil_SelectDateForPickerView.self) as! Virgil_SelectDateForPickerView)
- var defaultDate: Date!
- if self.txtJSYHYXQ.text! == "" || self.txtJSYHYXQ.text!.length() != 10 {
- defaultDate = Date()
- } else {
- defaultDate = CommonDate.getDateForString(dateStr: self.txtJSYHYXQ.text!, dateFormat: "yyyy-MM-dd")
- }
- //viewDatePicer.datePicker.maximumDate = Date();
- viewDatePicer.showDatePickerView(defaultDate: defaultDate) {[weak self] (str) in
- self!.txtJSYHYXQ.text = str
- }
- break
- case 1005: // 结算银行名称
- // commonSelectType = 0;
- // let vc = CommonSelectViewController();
- // vc.delegate = self;
- // vc.type = 2;
- // toViewController(viewController: vc);
- let vc = BJSelectBankViewController()
- vc.provinceId = ""//addressIds[0]
- vc.cityId = ""//addressIds[1];
- vc.bankName = "" //txtBank.text!;
- toViewController(viewController: vc)
- break
- case 1006: // 开户地区
- btnSelectAddressClick()
- break
- case 1007: // 正面
- uploadImage(type: 0)
- break
- case 1008: // 反面
- uploadImage(type: 1)
- break
- case 1009: // 手持身份证照
- uploadImage(type: 2)
- break
- case 1010: // 选择支行名称
- let vc = SelectBankViewController()
- vc.provinceId = self.bankCardProvCode//addressIds[0]
- vc.cityId = self.bankCardCityCode//addressIds[1];
- var substr = ""
- if self.bankCardCityName.contains("市") {
- let arr = self.bankCardCityName.components(separatedBy: "市")
- substr = arr[0]
- }else {
- substr = self.bankCardCityName
- }
- namem = self.txtBankName.text! + substr
- vc.bankName = namem //txtBank.text!;
- toViewController(viewController: vc)
- break
- default:
- break
- }
- }
- func avCaptureViewReData(_ iDInfo: IDInfo!, img: UIImage!) {
- if iDInfo.type == 1 {
- txtIDCard.text = iDInfo.num!
- }
- if iDInfo.type == 2 {
- txtFRYXQ.text = iDInfo.valid!
- }
- //imgShow.image = img;
- }
- var bankNameBranchCode = ""
- var bankNameBranchNo = ""
- func rebackFunction(dic: NSMutableDictionary) {
- if commonSelectType == 0 {
- txtBankName.text = dic.getString(key: "issuser_name")
- bankNameBranchCode = dic.getString(key: "bank_code")
- bankNameBranchNo = dic.getString(key: "bank_link_no")
- } else if commonSelectType == 1 {
- }
- }
- ///选择所在地区
- var viewSelectCity: Virgil_SelectCity!
- func btnSelectAddressClick() {
- //var viewSelectCity:Virgil_SelectCity!
- 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!.bankCardProvCode = self!.getString(key: "addressId1", dic: dic)
- self!.bankCardCityCode = self!.getString(key: "addressId2", dic: dic)
- self!.bankCardCityName = self!.getString(key: "addressName2", dic: dic)
- //self!.shopOpen.addressName1 = self!.getString(key: "addressName1", dic: dic) ;
- self!.txtAddress.text = dic.getString(key: "address")
- }
- self.view.addSubview(viewSelectCity)
- }
- viewSelectCity.showPickerView()
- }
- // MARK: ============上传图片============
- var isUpload = false
- var uploadImageType = 0
- func uploadImage(type: Int) {
- scrollView.contentOffset.y = (viewContentHeight.constant - (ScreenHeight - common_nav_status_height - common_bottom_height))
- if isUpload {
- return
- }
- CommonUntils.AlertView(controller: self, title: nil, message: nil, buttons: ["拍照上传", "从相册上传"], style: .actionSheet) {[weak self] (index, _) in
- self!.isUpload = true
- self!.uploadImageType = type
- 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 {
- self!.isUpload = false
- SVProgressHUD.showError(withStatus: "图片选择失败,请重试")
- }
- }
- }
- func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
- self.isUpload = false
- self.dismiss(animated: true) {
- }
- }
- var arrImages = ["", "", "", ""]
- var arrImagesLocal = ["", "", "", ""]
- 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 {
- let userLoginUrl = RequestURL.qiNiuImageUrl + str
- self!.arrImages[self!.uploadImageType] = userLoginUrl
- self!.uploadWeb(img: img)
- } else {
- self!.isUpload = false
- MBProgressHUD.hide(for: self!.view, animated: true)
- SVProgressHUD.showError(withStatus: "上传失败")
- }
- }
- }
- func uploadWeb(img: UIImage) {
- let manage = CommonValue.getHttp()
- let param = NSMutableDictionary()
- var url = RequestURL.uploadFile
- if self.uploadImageType == 0 {
- url = RequestURL.uploadMerchantFile
- param.setValue("2", forKey: "type")
- } else if self.uploadImageType == 1 {
- url = RequestURL.uploadMerchantFile
- param.setValue("3", forKey: "type")
- } else if self.uploadImageType == 2 {
- param.setValue("7", forKey: "type")
- }else if self.uploadImageType == 3 {
- url = RequestURL.uploadMerchantFile
- param.setValue("8", forKey: "type")
- }
- manage.requestSerializer.timeoutInterval = 60.0
- manage.post(url, 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
- self!.isUpload = false
- let json = json1 as! NSDictionary
- print(json)
- let succeed = json.object(forKey: "succeed") as! String
- if succeed == "000" {
- if self!.uploadImageType == 0 {
- let status = (json["dataInfo"] as! NSDictionary).getInt(key: "statusCode")
- if status == 200 {
- let haike = (json["dataInfo"] as! NSDictionary)["haike"] as! NSDictionary
- let hkResult = haike["result"] as! NSDictionary
- let hkResultData = hkResult["data"] as! NSDictionary
- self!.txtName.text = hkResultData.getString(key: "name")
- self!.txtIDCard.text = hkResultData.getString(key: "idNumber")
- self!.uploadWebImg(img: img)
- } else {
- SVProgressHUD.showError(withStatus: "身份证识别失败,请重新上传!")
- }
- } else if self!.uploadImageType == 1 {
- let status = (json["dataInfo"] as! NSDictionary).getInt(key: "statusCode")
- if status == 200 {
- let haike = (json["dataInfo"] as! NSDictionary)["haike"] as! NSDictionary
- let hkResult = haike["result"] as! NSDictionary
- let hkResultData = hkResult["data"] as! NSDictionary
- let str = hkResultData.getString(key: "validity") as NSString
- let saleArray = str.components(separatedBy: "-")
- if saleArray.count > 1 {
- let strNew = saleArray[1]
- let newArray = strNew.components(separatedBy: ".")
- if newArray.count > 1 {
- self!.txtFRYXQ.text = "\(newArray[0])"+"-"+"\(newArray[1])"+"-"+"\(newArray[2])"
- }else {
- SVProgressHUD.showInfo(withStatus: "识别身份证有效期为长期,请自己再手动选择日期哦")
- self!.txtFRYXQ.text = ""
- }
- }else {
- SVProgressHUD.showError(withStatus: "身份证识别失败,请重新上传!")
- }
- self!.uploadWebImg(img: img)
- } else {
- SVProgressHUD.showError(withStatus: "身份证识别失败,请重新上传!")
- }
- } else if self!.uploadImageType == 2 {
- self!.btnMenu3.isSelected = true
- self!.imgCard3.loadImage(imgUrl: self!.arrImages[self!.uploadImageType], defaultImage: "")
- self!.arrImagesLocal[self!.uploadImageType] = (json["dataInfo"] as! NSDictionary).getString(key: "url")
- }else if self!.uploadImageType == 3 {
- let status = (json["dataInfo"] as! NSDictionary).getInt(key: "statusCode")
- if status == 200 {
- let haike = (json["dataInfo"] as! NSDictionary)["haike"] as! NSDictionary
- let hkResult = haike["result"] as! NSDictionary
- let hkResultData = hkResult["data"] as! NSDictionary
- // self!.txtBankName.text = hkResultData.getString(key: "bankName")
- self!.txtBankCard.text = hkResultData.getString(key: "cardNumber")
- self!.loadData(key: hkResultData.getString(key: "bankName"))
- } else {
- SVProgressHUD.showError(withStatus: "银行卡识别失败,请重新上传或手动输入")
- }
- }
- } else {
- SVProgressHUD.showInfo(withStatus: "上传失败,请重新上传")
- }
- MBProgressHUD.hide(for: self!.view, animated: true)
- }) {[weak self] (_, _) in
- self!.isUpload = false
- SVProgressHUD.showInfo(withStatus: "上传失败,请重新上传")
- MBProgressHUD.hide(for: self!.view, animated: true)
- }
- }
- func loadData(key: String) //str:String
- {
- if (self.txtBankName.text == "未识别银行"){
- return
- }
- let url = RequestURL.qybFindBankList
- let params = NSMutableDictionary()
- if key != "" {
- params.setValue(key, forKey: "issuser_name")
- } else {
- params.setValue(self.txtBankName.text!, forKey: "issuser_name")
- }
- loadDataList(url: url, params: params, tag: 1001)
- }
- override func returnData(tag: Int) {
- if self.arrData.count > 0 {
- let dicNew = NSMutableDictionary(dictionary: self.arrData[0] as! NSDictionary)
- mainViewControllerIsGoValue = dicNew.getString(key: "issuser_name")
- mainViewControllerIsGoValue1 = dicNew.getString(key: "bank_code")
- mainViewControllerIsGoValue2 = dicNew.getString(key: "bank_link_no")
- txtBankName.text = mainViewControllerIsGoValue
- bankNameBranchCode = mainViewControllerIsGoValue1
- bankNameBranchNo = mainViewControllerIsGoValue2
- }else{
- txtBankName.text = ""
- SVProgressHUD.showInfo(withStatus: "请手动选择结算银行名称")
- }
- }
- func uploadWebImg(img: UIImage) {
- let manage = CommonValue.getHttp()
- let param = NSMutableDictionary()
- let url = RequestURL.uploadFile
- if self.uploadImageType == 0 {
- param.setValue("2", forKey: "type")
- } else if self.uploadImageType == 1 {
- param.setValue("3", forKey: "type")
- }
- manage.requestSerializer.timeoutInterval = 60.0
- manage.post(url, 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
- self!.isUpload = false
- let json = json1 as! NSDictionary
- print(json)
- let succeed = json.object(forKey: "succeed") as! String
- if succeed == "000" {
- if self!.uploadImageType == 0 {
- self!.btnMenu1.isSelected = true
- self!.imgCard1.loadImage(imgUrl: self!.arrImages[self!.uploadImageType], defaultImage: "")
- self!.arrImagesLocal[self!.uploadImageType] = (json["dataInfo"] as! NSDictionary).getString(key: "url")
- } else if self!.uploadImageType == 1 {
- self!.btnMenu2.isSelected = true
- self!.imgCard2.loadImage(imgUrl: self!.arrImages[self!.uploadImageType], defaultImage: "")
- self!.arrImagesLocal[self!.uploadImageType] = (json["dataInfo"] as! NSDictionary).getString(key: "url")
- }
- } else {
- SVProgressHUD.showInfo(withStatus: "上传失败,请重新上传")
- }
- MBProgressHUD.hide(for: self!.view, animated: true)
- }) {[weak self] (_, _) in
- self!.isUpload = false
- SVProgressHUD.showInfo(withStatus: "上传失败,请重新上传")
- MBProgressHUD.hide(for: self!.view, animated: true)
- }
- }
- func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
- var top: CGFloat = 0
- if textField.tag == 2001 {
- top = 406
- } else if textField.tag == 20011 {
- top = 457
- } else if textField.tag == 2002 {
- top = 558
- } else if textField.tag == 2003 {
- top = 609
- }
- scrollView.contentOffset.y = top - (viewContentHeight.constant - (ScreenHeight - common_nav_status_height - common_bottom_height)) / 2
- // scrollView.contentOffset.y = (viewContentHeight.constant - (ScreenHeight - common_nav_status_height - common_bottom_height));
- //top - (viewContentHeight.constant - (ScreenHeight - common_nav_status_height - common_bottom_height)) / 2
- return true
- }
- func scrollViewDidScroll(_ scrollView: UIScrollView) {
- print("==\(scrollView.contentOffset.y)===")
- }
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- if mainViewControllerIsGo {
- mainViewControllerIsGo = false
- if mainViewControllerIsGoType == 0 {
- txtChildBankName.text = mainViewControllerIsGoValue
- } else if mainViewControllerIsGoType == 9901 {
- txtBankName.text = mainViewControllerIsGoValue
- bankNameBranchCode = mainViewControllerIsGoValue1
- bankNameBranchNo = mainViewControllerIsGoValue2
- }
- }
- }
- override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
- super.init(nibName: "BJBusinessViewController", bundle: nil)
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- }
|