TiXianViewController.swift 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. //
  2. // TiXianViewController.swift
  3. // xingchuangke
  4. //
  5. // Created by Virgil on 2019/4/21.
  6. // Copyright © 2019 Virgil. All rights reserved.
  7. //
  8. import UIKit
  9. @objcMembers
  10. class TiXianViewController: BaseViewController, UITextFieldDelegate {
  11. @IBOutlet weak var btnTXXY: UIButton!
  12. @IBOutlet weak var btnFBType: UIButton!
  13. @IBOutlet weak var earnBtn: UIButton!
  14. @IBOutlet weak var lblContent1: UILabel!
  15. @IBOutlet weak var lblContent2: UILabel!
  16. @IBOutlet weak var lblRemark2: UILabel!
  17. @IBOutlet weak var view1Width: NSLayoutConstraint!
  18. @IBOutlet weak var view3: UIView!
  19. @IBOutlet weak var view2: UIView!
  20. @IBOutlet weak var view1: UIView!
  21. @IBOutlet weak var viewTopHeight: NSLayoutConstraint!
  22. @IBOutlet weak var lblType: UILabel!
  23. @IBOutlet weak var lblBankChildName: UILabel!
  24. @IBOutlet weak var lblBankName: UILabel!
  25. @IBOutlet weak var lblCardNo: UILabel!
  26. @IBOutlet weak var lblName: UILabel!
  27. @IBOutlet weak var txtMoney: UITextField!
  28. var withdraw: String?
  29. var dataInfo: Double?
  30. ///是否开发票 0:否 1:是
  31. var isFaPiao = 0
  32. var cashFee: Double = 0.0
  33. /// machineTypeId
  34. var machineTypeId: String = ""
  35. ///发票类型 : 0:普通 1专用3% 2专用6% 3不开发票
  36. var fType = 0
  37. // 选择品牌设置的金额
  38. var brandEarnArr: NSArray?
  39. override func viewDidLoad() {
  40. super.viewDidLoad()
  41. initNavLeftBackButton()
  42. self.title = "提现"
  43. txtMoney.delegate = self
  44. // initNavRightButtonForTitle(title: "提现记录", color: UIColor.white);
  45. view1Width.constant = ScreenWidth
  46. 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)
  47. loadData()
  48. loadDataNew()
  49. }
  50. override func btnRightMenuClick() {
  51. toViewController(viewController: TiXianRecordListViewController())
  52. }
  53. override func KeyboardHidden(gestureRecognizer: UIGestureRecognizer) {
  54. txtMoney.resignFirstResponder()
  55. }
  56. @IBAction func btnMenuClick(_ sender: AnyObject) {
  57. switch (sender as! UIButton).tag {
  58. case 1001: // 下一步
  59. if !btnTXXY.isSelected {
  60. SVProgressHUD.showError(withStatus: "请先同意《提现协议》")
  61. return
  62. }
  63. if txtMoney.text!.length() < 1 {
  64. SVProgressHUD.showError(withStatus: "请输入提现金额!")
  65. return
  66. }
  67. if !CommonValidate.isDouble(str: txtMoney.text!) {
  68. SVProgressHUD.showError(withStatus: "提现金额格式不正确,请重新输入!")
  69. return
  70. }
  71. if Double(txtMoney.text!)! < dataInfo! {
  72. let s = "提现金额必须大于等于"
  73. SVProgressHUD.showError(withStatus: s + String(dataInfo!))
  74. return
  75. }
  76. if Double(txtMoney.text!)! > CommonValue.getUserProfitBalance() {
  77. SVProgressHUD.showError(withStatus: "提现金额大于可提现余额,请重新输入!")
  78. return
  79. }
  80. CommonUntils.AlertView(controller: self, title: "提示", message: "确认提现?", buttons: ["提现"], style: .alert) {[weak self] (_, _) in
  81. if self!.isFaPiao == 1 {
  82. let vc = TiXianFaPiaoViewController()
  83. vc.isFaPiao = self!.isFaPiao
  84. vc.money = self!.txtMoney.text!
  85. vc.fbType = self!.fType
  86. vc.machineTypeId = self!.machineTypeId
  87. vc.brandEarnArr = self!.brandEarnArr
  88. self!.toViewController(viewController: vc)
  89. } else {
  90. self!.submitData()
  91. }
  92. }
  93. break
  94. case 1002: // 全部/品牌
  95. if machineTypeId.length() == 0 {
  96. let vc = BrandForWithdrawViewController()
  97. vc.withdrawBlock = {[weak self] (arr, earn) in
  98. self?.txtMoney.text = "\(String(format: "%.2f", earn))"
  99. self?.brandEarnArr = arr
  100. }
  101. self.navigationController?.pushViewController(vc, animated: true)
  102. } else {
  103. txtMoney.text = "\(withdraw ?? "0")"
  104. }
  105. break
  106. case 1003: // 提现规则
  107. // let viewWeb = CommonWebViewViewController()
  108. // viewWeb.strTitle = "提现规则"
  109. // viewWeb.url = "\(RequestURL.sysConfigWeb)?type=cash_rules"
  110. // viewWeb.sourceType = 0
  111. // appDelegate.navController.pushViewController(viewWeb, animated: true)
  112. let viewWeb = WithdrawalRuleVC()
  113. GB_Nav.pushViewController(viewWeb, animated: true)
  114. break
  115. case 1004: // 发票类型
  116. CommonUntils.AlertView(controller: self, title: nil, message: "请选择开票类型", buttons: ["增值税普通发票", "增值税专用发票(3%)", "增值税专用发票(6%)"], style: .actionSheet) {[weak self] (index, _) in
  117. self!.lblContent1.text = ["增值税普通发票", "增值税专用发票(3%)", "增值税专用发票(6%)"][index]
  118. self!.fType = index
  119. self!.lblRemark2.text = "实开发票金额"
  120. self!.moneyChange(money: self!.txtMoney.text!)
  121. }
  122. break
  123. case 1005: // 开票规则
  124. let viewWeb = CommonWebViewViewController()
  125. viewWeb.strTitle = "开票规则"
  126. viewWeb.url = "\(RequestURL.sysConfigWeb)?type=invoice_rules"
  127. viewWeb.sourceType = 0
  128. appDelegate.navController.pushViewController(viewWeb, animated: true)
  129. break
  130. case 1006: // 同意提现协议
  131. btnTXXY.isSelected = !btnTXXY.isSelected
  132. break
  133. case 1007: // 查看提现协议
  134. let viewWeb = CommonWebViewViewController()
  135. viewWeb.strTitle = "提现协议"
  136. viewWeb.url = CommonValue.getDefaultValueForKey(key: "payment_agreement")
  137. viewWeb.sourceType = 0
  138. appDelegate.navController.pushViewController(viewWeb, animated: true)
  139. break
  140. default:
  141. break
  142. }
  143. }
  144. func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
  145. if textField.text!.length() >= 10 && string != "" {
  146. return false
  147. }
  148. if string != "." && string != "" && string != "0" && string != "1" && string != "2" && string != "3" && string != "4" && string != "5" && string != "6" && string != "7" && string != "8" && string != "9" {
  149. return false
  150. }
  151. if textField.text!.has(s: ".") && string == "." {
  152. return false
  153. }
  154. if textField.text!.has(s: ".") && string != "" && range.location > textField.text!.indexOf(s: ".") {
  155. let strs = "\(textField.text!)\(string)".split(s: ".")
  156. if strs[1].length() > 2 {
  157. return false
  158. }
  159. }
  160. if string == "" {
  161. if textField.text!.length() > 0 {
  162. moneyChange(money: "\(textField.text!.substringTo(index: textField.text!.length() - 1))")
  163. } else {
  164. moneyChange(money: "")
  165. }
  166. } else {
  167. moneyChange(money: "\(textField.text!)\(string)")
  168. }
  169. return true
  170. }
  171. func moneyChange(money: String) {
  172. if money == "" {
  173. lblContent2.text = ""
  174. } else {
  175. let dMoney = Double(money)!
  176. if fType == 0 {
  177. lblContent2.text = String.init(format: "¥%.2f", dMoney * 0.94)
  178. } else if fType == 1 {
  179. lblContent2.text = String.init(format: "¥%.2f", dMoney * 0.97)
  180. } else if fType == 2 {
  181. lblContent2.text = String.init(format: "¥%.2f", dMoney)
  182. } else if fType == 3 {
  183. lblContent2.text = String.init(format: "¥%.2f", dMoney * 0.92 - cashFee)
  184. }
  185. }
  186. }
  187. // MARK: =============加载数据===============
  188. func loadData() {
  189. let url = RequestURL.mySettlementCard
  190. let params = NSMutableDictionary()
  191. loadDataInfo(url: url, params: params, tag: 1002)
  192. }
  193. func loadDataNew(){
  194. let url = RequestURL.cashApplicationSet
  195. let params = NSMutableDictionary()
  196. params.setValue(CommonValue.getUserId(), forKey: "userId")
  197. isAlertError = true
  198. let http = CommonValue.getHttp()
  199. MBProgressHUD.showAdded(to: self.view, animated: true)
  200. http.get(url, parameters: params, progress: nil, success: { (_, json1) -> Void in
  201. let json = json1 as! NSDictionary
  202. print(json)
  203. let succeed = json.object(forKey: "succeed") as! String
  204. if succeed == "000"||succeed == "0000" {
  205. self.dataInfo = Double(truncating: json["sucInfo"] as! NSNumber)
  206. } else {
  207. if self.isAlertError {
  208. SVProgressHUD.showError(withStatus: json.object(forKey: "sucInfo") as? String)
  209. }
  210. }
  211. MBProgressHUD.hide(for: self.view, animated: true)
  212. }, failure: { (_, err) -> Void in
  213. MBProgressHUD.hide(for: self.view, animated: true)
  214. CommonUntils.alertError(error: err as NSError)
  215. })
  216. }
  217. func submitData() {
  218. let money = txtMoney.text!
  219. var url = RequestURL.cashApplicationWithMachineTypeId
  220. let params = NSMutableDictionary()
  221. if machineTypeId == "" {
  222. url = RequestURL.cashApplicationWithMachineTypeIdAll
  223. let data = (try? JSONSerialization.data(withJSONObject: brandEarnArr!, options: .prettyPrinted))!
  224. let strJson = NSString(data: data, encoding: String.Encoding.utf8.rawValue)
  225. params.setValue(strJson, forKey: "machineTypeAndAtm")
  226. }
  227. params.setValue(machineTypeId, forKey: "machineTypeId")
  228. params.setValue(money, forKey: "amountMoney")
  229. params.setValue(isFaPiao, forKey: "type")
  230. params.setValue("", forKey: "invoicePhoto")
  231. params.setValue("", forKey: "expressName")
  232. params.setValue("", forKey: "expressNumber")
  233. params.setValue("", forKey: "invoiceType")
  234. params.setValue("", forKey: "reteType")
  235. params.setValue("1", forKey: "phoneType")
  236. submitData(url: url, params: params, tag: 1001)
  237. }
  238. override func returnData(tag: Int) {
  239. if tag == 1001 {
  240. appDelegate.reloadUserInfo()
  241. let vc = TiXianAlertViewController()
  242. vc.machineTypeId = machineTypeId
  243. toViewController(viewController: vc)
  244. } else if tag == 1002 {
  245. let dic: NSDictionary = self.dicData["cardInfo"] as! NSDictionary
  246. lblName.text = dic.getString(key: "bank_account_name")
  247. lblCardNo.text = dic.getString(key: "card_number")
  248. lblBankName.text = dic.getString(key: "affiliated_bank")
  249. lblBankChildName.text = dic.getString(key: "affiliated_branch_bank")
  250. if getIntValue(key: "type", dic: dic) == 1 {
  251. fType = 2
  252. isFaPiao = 1
  253. self.lblRemark2.text = "实开发票金额"
  254. lblType.text = "对公账户"
  255. self.lblContent1.text = "增值税专用发票(6%)"
  256. btnFBType.isEnabled = true
  257. } else {
  258. isFaPiao = 0
  259. lblType.text = "个人账户"
  260. fType = 3
  261. self.lblRemark2.text = "实际到账"
  262. btnFBType.isEnabled = false
  263. self.lblContent1.text = "不开发票"
  264. }
  265. }else {
  266. }
  267. }
  268. override func returnError(tag: Int, type: String) {
  269. }
  270. override func viewWillAppear(_ animated: Bool) {
  271. super.viewWillAppear(animated)
  272. appDelegate.setNavigationBarHidden(isHidden: false)
  273. if machineTypeId.length() == 0 {
  274. earnBtn.setTitle("选择品牌", for: .normal)
  275. txtMoney.isUserInteractionEnabled = false
  276. txtMoney.placeholder = "可提现金额\(withdraw ?? "0")元"
  277. } else {
  278. txtMoney.isUserInteractionEnabled = true
  279. earnBtn.setTitle("全部", for: .normal)
  280. txtMoney.placeholder = "可提现金额\(withdraw ?? "0")元"
  281. }
  282. // lblName.text = dicData.getString(key: "bank_account_name")
  283. // lblCardNo.text = dicData.getString(key: "card_number")
  284. // lblBankName.text = dicData.getString(key: "affiliated_bank")
  285. // lblBankChildName.text = dicData.getString(key: "affiliated_branch_bank")
  286. // if(getIntValue(key: "type", dic: self.dicData["cardInfo"] as! NSDictionary) == 1)
  287. // {
  288. // fType = 2;
  289. // isFaPiao = 1;
  290. // self.lblRemark2.text = "实开发票金额"
  291. // lblType.text = "对公账户"
  292. // self.lblContent1.text = "增值税专用发票(6%)"
  293. // btnFBType.isEnabled = true;
  294. // }
  295. // else
  296. // {
  297. // isFaPiao = 0;
  298. // lblType.text = "个人账户"
  299. // fType = 3;
  300. // self.lblRemark2.text = "实际到账"
  301. // btnFBType.isEnabled = false;
  302. // self.lblContent1.text = "不开发票"
  303. // }
  304. }
  305. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  306. super.init(nibName: "TiXianViewController", bundle: nil)
  307. }
  308. required init?(coder aDecoder: NSCoder) {
  309. fatalError("init(coder:) has not been implemented")
  310. }
  311. }