123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336 |
- //
- // TiXianViewController.swift
- // xingchuangke
- //
- // Created by Virgil on 2019/4/21.
- // Copyright © 2019 Virgil. All rights reserved.
- //
- import UIKit
- @objcMembers
- class TiXianViewController: BaseViewController, UITextFieldDelegate {
- @IBOutlet weak var btnTXXY: UIButton!
- @IBOutlet weak var btnFBType: UIButton!
- @IBOutlet weak var earnBtn: UIButton!
- @IBOutlet weak var lblContent1: UILabel!
- @IBOutlet weak var lblContent2: UILabel!
- @IBOutlet weak var lblRemark2: UILabel!
- @IBOutlet weak var view1Width: NSLayoutConstraint!
- @IBOutlet weak var view3: UIView!
- @IBOutlet weak var view2: UIView!
- @IBOutlet weak var view1: UIView!
- @IBOutlet weak var viewTopHeight: NSLayoutConstraint!
- @IBOutlet weak var lblType: UILabel!
- @IBOutlet weak var lblBankChildName: UILabel!
- @IBOutlet weak var lblBankName: UILabel!
- @IBOutlet weak var lblCardNo: UILabel!
- @IBOutlet weak var lblName: UILabel!
- @IBOutlet weak var txtMoney: UITextField!
- var withdraw: String?
- var dataInfo: Double?
- ///是否开发票 0:否 1:是
- var isFaPiao = 0
- var cashFee: Double = 0.0
- /// machineTypeId
- var machineTypeId: String = ""
- ///发票类型 : 0:普通 1专用3% 2专用6% 3不开发票
- var fType = 0
- // 选择品牌设置的金额
- var brandEarnArr: NSArray?
- override func viewDidLoad() {
- super.viewDidLoad()
- initNavLeftBackButton()
- self.title = "提现"
- txtMoney.delegate = self
- // initNavRightButtonForTitle(title: "提现记录", color: UIColor.white);
- view1Width.constant = ScreenWidth
- btnTXXY.setAttributedTitle(CommonViewUntils.getAttributedString(str: "同意《提现协议》", left: 2, right: 0, color: CommonUntils.getUIColorFromRGB(rgbValue: 0x2A92F7, alpha: 1.0), otherColor: CommonUntils.getUIColorFromRGB(rgbValue: 0x333333, alpha: 1.0)), for: .normal)
- loadData()
- loadDataNew()
- }
- override func btnRightMenuClick() {
- toViewController(viewController: TiXianRecordListViewController())
- }
- override func KeyboardHidden(gestureRecognizer: UIGestureRecognizer) {
- txtMoney.resignFirstResponder()
- }
- @IBAction func btnMenuClick(_ sender: AnyObject) {
- switch (sender as! UIButton).tag {
- case 1001: // 下一步
- if !btnTXXY.isSelected {
- SVProgressHUD.showError(withStatus: "请先同意《提现协议》")
- return
- }
- if txtMoney.text!.length() < 1 {
- SVProgressHUD.showError(withStatus: "请输入提现金额!")
- return
- }
- if !CommonValidate.isDouble(str: txtMoney.text!) {
- SVProgressHUD.showError(withStatus: "提现金额格式不正确,请重新输入!")
- return
- }
- if Double(txtMoney.text!)! < dataInfo! {
- let s = "提现金额必须大于等于"
- SVProgressHUD.showError(withStatus: s + String(dataInfo!))
- return
- }
- if Double(txtMoney.text!)! > CommonValue.getUserProfitBalance() {
- SVProgressHUD.showError(withStatus: "提现金额大于可提现余额,请重新输入!")
- return
- }
- CommonUntils.AlertView(controller: self, title: "提示", message: "确认提现?", buttons: ["提现"], style: .alert) {[weak self] (_, _) in
- if self!.isFaPiao == 1 {
- let vc = TiXianFaPiaoViewController()
- vc.isFaPiao = self!.isFaPiao
- vc.money = self!.txtMoney.text!
- vc.fbType = self!.fType
- vc.machineTypeId = self!.machineTypeId
- vc.brandEarnArr = self!.brandEarnArr
- self!.toViewController(viewController: vc)
- } else {
- self!.submitData()
- }
- }
- break
- case 1002: // 全部/品牌
- if machineTypeId.length() == 0 {
- let vc = BrandForWithdrawViewController()
- vc.withdrawBlock = {[weak self] (arr, earn) in
- self?.txtMoney.text = "\(String(format: "%.2f", earn))"
- self?.brandEarnArr = arr
- }
- self.navigationController?.pushViewController(vc, animated: true)
- } else {
- txtMoney.text = "\(withdraw ?? "0")"
- }
- break
- case 1003: // 提现规则
- // let viewWeb = CommonWebViewViewController()
- // viewWeb.strTitle = "提现规则"
- // viewWeb.url = "\(RequestURL.sysConfigWeb)?type=cash_rules"
- // viewWeb.sourceType = 0
- // appDelegate.navController.pushViewController(viewWeb, animated: true)
- let viewWeb = WithdrawalRuleVC()
- GB_Nav.pushViewController(viewWeb, animated: true)
- break
- case 1004: // 发票类型
- CommonUntils.AlertView(controller: self, title: nil, message: "请选择开票类型", buttons: ["增值税普通发票", "增值税专用发票(3%)", "增值税专用发票(6%)"], style: .actionSheet) {[weak self] (index, _) in
- self!.lblContent1.text = ["增值税普通发票", "增值税专用发票(3%)", "增值税专用发票(6%)"][index]
- self!.fType = index
- self!.lblRemark2.text = "实开发票金额"
- self!.moneyChange(money: self!.txtMoney.text!)
- }
- break
- case 1005: // 开票规则
- let viewWeb = CommonWebViewViewController()
- viewWeb.strTitle = "开票规则"
- viewWeb.url = "\(RequestURL.sysConfigWeb)?type=invoice_rules"
- viewWeb.sourceType = 0
- appDelegate.navController.pushViewController(viewWeb, animated: true)
- break
- case 1006: // 同意提现协议
- btnTXXY.isSelected = !btnTXXY.isSelected
- break
- case 1007: // 查看提现协议
- let viewWeb = CommonWebViewViewController()
- viewWeb.strTitle = "提现协议"
- viewWeb.url = CommonValue.getDefaultValueForKey(key: "payment_agreement")
- viewWeb.sourceType = 0
- appDelegate.navController.pushViewController(viewWeb, animated: true)
- break
- default:
- break
- }
- }
- func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
- if textField.text!.length() >= 10 && string != "" {
- return false
- }
- if string != "." && string != "" && string != "0" && string != "1" && string != "2" && string != "3" && string != "4" && string != "5" && string != "6" && string != "7" && string != "8" && string != "9" {
- return false
- }
- if textField.text!.has(s: ".") && string == "." {
- return false
- }
- if textField.text!.has(s: ".") && string != "" && range.location > textField.text!.indexOf(s: ".") {
- let strs = "\(textField.text!)\(string)".split(s: ".")
- if strs[1].length() > 2 {
- return false
- }
- }
- if string == "" {
- if textField.text!.length() > 0 {
- moneyChange(money: "\(textField.text!.substringTo(index: textField.text!.length() - 1))")
- } else {
- moneyChange(money: "")
- }
- } else {
- moneyChange(money: "\(textField.text!)\(string)")
- }
- return true
- }
- func moneyChange(money: String) {
- if money == "" {
- lblContent2.text = ""
- } else {
- let dMoney = Double(money)!
- if fType == 0 {
- lblContent2.text = String.init(format: "¥%.2f", dMoney * 0.94)
- } else if fType == 1 {
- lblContent2.text = String.init(format: "¥%.2f", dMoney * 0.97)
- } else if fType == 2 {
- lblContent2.text = String.init(format: "¥%.2f", dMoney)
- } else if fType == 3 {
- lblContent2.text = String.init(format: "¥%.2f", dMoney * 0.92 - cashFee)
- }
- }
- }
- // MARK: =============加载数据===============
- func loadData() {
- let url = RequestURL.mySettlementCard
- let params = NSMutableDictionary()
- loadDataInfo(url: url, params: params, tag: 1002)
-
- }
- func loadDataNew(){
- let url = RequestURL.cashApplicationSet
- let params = NSMutableDictionary()
- params.setValue(CommonValue.getUserId(), forKey: "userId")
- isAlertError = true
- let http = CommonValue.getHttp()
- MBProgressHUD.showAdded(to: self.view, animated: true)
- http.get(url, parameters: params, progress: nil, success: { (_, json1) -> Void in
- let json = json1 as! NSDictionary
- print(json)
- let succeed = json.object(forKey: "succeed") as! String
- if succeed == "000"||succeed == "0000" {
- self.dataInfo = Double(truncating: json["sucInfo"] as! NSNumber)
-
- } else {
- if self.isAlertError {
- SVProgressHUD.showError(withStatus: json.object(forKey: "sucInfo") as? String)
- }
- }
- MBProgressHUD.hide(for: self.view, animated: true)
- }, failure: { (_, err) -> Void in
- MBProgressHUD.hide(for: self.view, animated: true)
- CommonUntils.alertError(error: err as NSError)
- })
- }
- func submitData() {
- let money = txtMoney.text!
- var url = RequestURL.cashApplicationWithMachineTypeId
- let params = NSMutableDictionary()
- if machineTypeId == "" {
- url = RequestURL.cashApplicationWithMachineTypeIdAll
- let data = (try? JSONSerialization.data(withJSONObject: brandEarnArr!, options: .prettyPrinted))!
- let strJson = NSString(data: data, encoding: String.Encoding.utf8.rawValue)
- params.setValue(strJson, forKey: "machineTypeAndAtm")
- }
- params.setValue(machineTypeId, forKey: "machineTypeId")
- params.setValue(money, forKey: "amountMoney")
- params.setValue(isFaPiao, forKey: "type")
- params.setValue("", forKey: "invoicePhoto")
- params.setValue("", forKey: "expressName")
- params.setValue("", forKey: "expressNumber")
- params.setValue("", forKey: "invoiceType")
- params.setValue("", forKey: "reteType")
- params.setValue("1", forKey: "phoneType")
- submitData(url: url, params: params, tag: 1001)
- }
- override func returnData(tag: Int) {
- if tag == 1001 {
- appDelegate.reloadUserInfo()
- let vc = TiXianAlertViewController()
- vc.machineTypeId = machineTypeId
- toViewController(viewController: vc)
- } else if tag == 1002 {
- let dic: NSDictionary = self.dicData["cardInfo"] as! NSDictionary
- lblName.text = dic.getString(key: "bank_account_name")
- lblCardNo.text = dic.getString(key: "card_number")
- lblBankName.text = dic.getString(key: "affiliated_bank")
- lblBankChildName.text = dic.getString(key: "affiliated_branch_bank")
- if getIntValue(key: "type", dic: dic) == 1 {
- fType = 2
- isFaPiao = 1
- self.lblRemark2.text = "实开发票金额"
- lblType.text = "对公账户"
- self.lblContent1.text = "增值税专用发票(6%)"
- btnFBType.isEnabled = true
- } else {
- isFaPiao = 0
- lblType.text = "个人账户"
- fType = 3
- self.lblRemark2.text = "实际到账"
- btnFBType.isEnabled = false
- self.lblContent1.text = "不开发票"
- }
- }else {
-
- }
- }
- override func returnError(tag: Int, type: String) {
- }
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- appDelegate.setNavigationBarHidden(isHidden: false)
- if machineTypeId.length() == 0 {
- earnBtn.setTitle("选择品牌", for: .normal)
- txtMoney.isUserInteractionEnabled = false
- txtMoney.placeholder = "可提现金额\(withdraw ?? "0")元"
- } else {
- txtMoney.isUserInteractionEnabled = true
- earnBtn.setTitle("全部", for: .normal)
- txtMoney.placeholder = "可提现金额\(withdraw ?? "0")元"
- }
- // lblName.text = dicData.getString(key: "bank_account_name")
- // lblCardNo.text = dicData.getString(key: "card_number")
- // lblBankName.text = dicData.getString(key: "affiliated_bank")
- // lblBankChildName.text = dicData.getString(key: "affiliated_branch_bank")
- // if(getIntValue(key: "type", dic: self.dicData["cardInfo"] as! NSDictionary) == 1)
- // {
- // fType = 2;
- // isFaPiao = 1;
- // self.lblRemark2.text = "实开发票金额"
- // lblType.text = "对公账户"
- // self.lblContent1.text = "增值税专用发票(6%)"
- // btnFBType.isEnabled = true;
- // }
- // else
- // {
- // isFaPiao = 0;
- // lblType.text = "个人账户"
- // fType = 3;
- // self.lblRemark2.text = "实际到账"
- // btnFBType.isEnabled = false;
- // self.lblContent1.text = "不开发票"
- // }
- }
- override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
- super.init(nibName: "TiXianViewController", bundle: nil)
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- }
|