OpenDetailViewController.swift 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. //
  2. // OpenDetailViewController.swift
  3. // xingchuangke
  4. //
  5. // Created by Virgil on 2019/3/28.
  6. // Copyright © 2019 Virgil. All rights reserved.
  7. //
  8. import UIKit
  9. class OpenDetailViewController: BaseViewController, UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate {
  10. @IBOutlet weak var txtNoPassContent: UITextView!
  11. @IBOutlet weak var lblNoAlert: UILabel!
  12. var localCurrnetIndex = -1
  13. @IBOutlet weak var viewFooter: UIView!
  14. @IBOutlet weak var btnNextPage: UIButton!
  15. var shopOpen: ShopOpenEntity!
  16. var arrTitle = [["公司简称", "申请人信息", "店铺信息", "所属行业", "结算信息", "费率"], ["店铺照片", "商户合影照"]]
  17. var arrRemark = [["公司名称+所属行业", "请上传照片", "请填写详细地址", "请选择", "请上传照片", ""], ["选填,请上传照片", "选填,请上传照片"]]
  18. var arrRemarkDefault = [["公司名称+所属行业", "请上传照片", "请填写详细地址", "请选择", "请上传照片", ""], ["选填,请上传照片", "选填,请上传照片"]]
  19. @IBOutlet weak var tableView: UITableView!
  20. var isSaveLocal = false
  21. ///0:正常 1:审核被拒
  22. var type = 0
  23. var isMod = true
  24. override func viewDidLoad() {
  25. super.viewDidLoad()
  26. initNavLeftBackButton()
  27. title = "开通详情"
  28. tableView.register(UINib(nibName: "OpenDetailTableViewCell", bundle: nil), forCellReuseIdentifier: "OpenDetailTableViewCell")
  29. tableView.delegate = self
  30. tableView.dataSource = self
  31. tableView.separatorStyle = .none
  32. tableView.showsVerticalScrollIndicator = false
  33. tableView.estimatedRowHeight = 100
  34. tableView.keyboardDismissMode = .onDrag
  35. viewFooter.setSizeWidth(width: ScreenWidth)
  36. viewFooter.removeFromSuperview()
  37. tableView.tableFooterView = viewFooter
  38. if shopOpen.rate == "" {
  39. getFeiLv(isDefault: true)
  40. } else {
  41. arrRemark[0][5] = "\(shopOpen.rate)%"
  42. }
  43. }
  44. override func handleBack() {
  45. if shopOpen.companyName != "" && isSaveLocal {
  46. CommonUntils.AlertView(controller: self, title: "提示", message: "资料尚未提交,是否先保存到本地?", buttons: ["保存"], style: .alert, actionHandler: {[weak self] (_, _) in
  47. self!.saveInfoToLocal()
  48. }) {
  49. super.handleBack()
  50. }
  51. } else {
  52. super.handleBack()
  53. }
  54. }
  55. func initData() {
  56. arrRemark[0][0] = shopOpen.companyName
  57. reloadAlertInfo()
  58. }
  59. func saveInfoToLocal() {
  60. let arrLocal = NSMutableArray()
  61. let local = CommonValue.getDefaultUserInfoForObject(key: "common_local_businfo")
  62. if local != nil && (local as? NSArray) != nil && (local as! NSArray).count > 0 {
  63. arrLocal.addObjects(from: ((local as! NSArray) as! [Any]))
  64. }
  65. let dic = shopOpen.mj_keyValues()!
  66. dic.setValue(CommonDate.getStringForDate(date: Date(), dateFormat: "yyyy-MM-dd HH:mm:ss"), forKey: "createtime")
  67. if localCurrnetIndex != -1 && arrLocal.count > localCurrnetIndex {
  68. arrLocal.removeObject(at: localCurrnetIndex)
  69. }
  70. arrLocal.add(dic)
  71. CommonValue.setDefaultUserInfoForObject(value: arrLocal, key: "common_local_businfo")
  72. if localCurrnetIndex == -1 {
  73. if !CommonUntils.reBackView(controller: self, aclass: ShopManagerViewController.classForCoder()) {
  74. self.navigationController?.popToRootViewController(animated: true)
  75. }
  76. } else {
  77. super.handleBack()
  78. }
  79. }
  80. // MARK: TABLEVLEW 实现
  81. func numberOfSections(in tableView: UITableView) -> Int {
  82. return arrTitle.count
  83. }
  84. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  85. return arrTitle[section].count
  86. }
  87. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  88. return 55
  89. }
  90. func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  91. let view = CommonViewUntils.getViewForXIB(xibName: "OpenDetailTableViewHeaderView") as! OpenDetailTableViewHeaderView
  92. view.initView(section: section)
  93. return view
  94. }
  95. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  96. return 50
  97. }
  98. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  99. let cell = tableView.dequeueReusableCell(withIdentifier: "OpenDetailTableViewCell", for: indexPath as IndexPath) as! OpenDetailTableViewCell
  100. //cell.lblTitle.text = getString(indexPath.row, key: "Name")
  101. cell.lblTitle.text = arrTitle[indexPath.section][indexPath.row]
  102. cell.lblDesc.text = arrRemark[indexPath.section][indexPath.row]
  103. if arrTitle[indexPath.section][indexPath.row] == "公司简称" {
  104. cell.txtContent.isHidden = false
  105. cell.txtContent.delegate = self
  106. cell.txtContent.text = shopOpen.companyName
  107. cell.txtContent.placeholder = arrRemark[indexPath.section][indexPath.row]
  108. cell.lblDesc.isHidden = true
  109. cell.btnRight.setImage(UIImage(named: "ion_opening_merchants_02"), for: .normal)
  110. cell.btnRight.addTarget(self, action: #selector(btnRemarkClick), for: .touchUpInside)
  111. } else {
  112. cell.txtContent.isHidden = true
  113. cell.lblDesc.isHidden = false
  114. cell.btnRight.removeTarget(self, action: #selector(btnRemarkClick), for: .touchUpInside)
  115. cell.btnRight.setImage(UIImage(named: "ion_arrow_right_gray"), for: .normal)
  116. }
  117. return cell
  118. }
  119. func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
  120. // if(string != "")
  121. // {
  122. // shopOpen.companyName = "\(textField.text!)\(string)"
  123. // }
  124. // else
  125. // {
  126. // if(textField.text!.length() > 0)
  127. // {
  128. // shopOpen.companyName = textField.text!.substringTo(index: textField.text!.length() - 1)
  129. // }
  130. // }
  131. return true
  132. }
  133. func textFieldDidEndEditing(_ textField: UITextField) {
  134. shopOpen.companyName = textField.text!
  135. print(shopOpen.companyName)
  136. }
  137. @IBAction func btnSubmitClick(_ sender: Any) {
  138. if shopOpen.companyName.length() < 1 {
  139. SVProgressHUD.showError(withStatus: "请输入公司简称")
  140. return
  141. }
  142. if arrRemark[0][1] != "已填写" {
  143. SVProgressHUD.showError(withStatus: "请填写申请人信息")
  144. return
  145. }
  146. if arrRemark[0][2] != "已填写" {
  147. SVProgressHUD.showError(withStatus: "请填写店铺地址")
  148. return
  149. }
  150. if arrRemark[0][3] != "已填写" {
  151. SVProgressHUD.showError(withStatus: "请填写所属行业")
  152. return
  153. }
  154. if arrRemark[0][4] != "已填写" {
  155. SVProgressHUD.showError(withStatus: "请填写结算信息")
  156. return
  157. }
  158. if shopOpen.rate == "" {
  159. SVProgressHUD.showError(withStatus: "请选择费率")
  160. return
  161. }
  162. submitData()
  163. }
  164. // MARK: =============加载数据===============
  165. func submitData() {
  166. let params = NSMutableDictionary()
  167. var url = RequestURL.openingMerchants
  168. if shopOpen.id != "" {
  169. url = RequestURL.editMerchants
  170. params.setValue(shopOpen.id, forKey: "merchantsId")
  171. }
  172. params.setValue(CommonValue.getUserId(), forKey: "userId")
  173. params.setValue(shopOpen.posId, forKey: "machineTypeId")
  174. params.setValue(shopOpen.posSN, forKey: "machineSnCode")
  175. params.setValue(shopOpen.shopType, forKey: "busType")
  176. params.setValue(shopOpen.phone, forKey: "busPhone")
  177. params.setValue(shopOpen.companyName, forKey: "companyName")
  178. params.setValue(shopOpen.name, forKey: "applicantName")
  179. params.setValue(shopOpen.card, forKey: "applicantCard")
  180. params.setValue(shopOpen.cardFront, forKey: "applicantCardFront")
  181. params.setValue(shopOpen.cardReverse, forKey: "applicantCardReverse")
  182. params.setValue(shopOpen.cardHoldFront, forKey: "applicantCardHoldFront")
  183. params.setValue(shopOpen.otherImage, forKey: "applicantCardHoldReverse")
  184. params.setValue(shopOpen.addressDetail, forKey: "shopAddress")
  185. params.setValue(shopOpen.addressId1, forKey: "shopProvinceId")
  186. params.setValue(shopOpen.addressId2, forKey: "shopCityId")
  187. params.setValue(shopOpen.addressId3, forKey: "shopAreaId")
  188. params.setValue(shopOpen.addressName1, forKey: "provinceCN")
  189. params.setValue(shopOpen.addressName2, forKey: "cityCN")
  190. params.setValue(shopOpen.addressName3, forKey: "areaCN")
  191. params.setValue(shopOpen.typeId2, forKey: "categoryTwoId")
  192. params.setValue(shopOpen.typeId1, forKey: "categoryOneId")
  193. params.setValue(shopOpen.bankCardNo, forKey: "bankCardNumber")
  194. params.setValue(shopOpen.bankAddressId1, forKey: "bankProvinceId")
  195. params.setValue(shopOpen.bankAddressId2, forKey: "bankCityId")
  196. params.setValue(shopOpen.bankAddressId3, forKey: "bankAreaId")
  197. params.setValue(shopOpen.bankAddressName1, forKey: "bankProvinceCN")
  198. params.setValue(shopOpen.bankAddressName2, forKey: "bankCityCN")
  199. params.setValue(shopOpen.bankAddressName3, forKey: "bankAreaCN")
  200. //params.setValue(shopOpen.bankAddressName3, forKey: "bankAreaCN")
  201. params.setValue(shopOpen.bankAffiliatedBranchBank, forKey: "bankAffiliatedBranchBank")
  202. params.setValue(shopOpen.bankOpenName, forKey: "bankOpenName")
  203. params.setValue(shopOpen.bankCardImage, forKey: "bankCardImg")
  204. params.setValue(shopOpen.typeName1, forKey: "categoryONECN")
  205. params.setValue(shopOpen.typeName2, forKey: "categoryTWOCN")
  206. params.setValue(shopOpen.licenseImage, forKey: "licenseImage")
  207. params.setValue(shopOpen.licenseNum, forKey: "licenseNum")
  208. params.setValue(shopOpen.bankAccountType, forKey: "bankAccountType")
  209. params.setValue(shopOpen.openingPermitImage, forKey: "openingPermitImage")
  210. params.setValue(shopOpen.reservePhone, forKey: "reservePhone")
  211. params.setValue(shopOpen.bankName, forKey: "bankAffiliatedBankCN")
  212. params.setValue(shopOpen.bankAffiliatedBank, forKey: "bankAffiliatedBank")
  213. params.setValue(shopOpen.applicantCardFrontLocal, forKey: "applicantCardFrontLocal")
  214. params.setValue(shopOpen.applicantCardReverseLocal, forKey: "applicantCardReverseLocal")
  215. params.setValue(shopOpen.applicantCardHoldFrontLocal, forKey: "applicantCardHoldFrontLocal")
  216. params.setValue(shopOpen.bankCardImgLocal, forKey: "bankCardImgLocal")
  217. params.setValue(shopOpen.bankAffiliatedBranchBankCN, forKey: "bankAffiliatedBranchBankCN")
  218. params.setValue(shopOpen.dpImages, forKey: "shopPhoto")
  219. params.setValue(shopOpen.shhyzImages, forKey: "shopUserPhoto")
  220. params.setValue(shopOpen.productTypeId, forKey: "productTypeId")
  221. params.setValue(shopOpen.rate, forKey: "rate")
  222. params.setValue(shopOpen.debitCardCostRate, forKey: "debitCardCostRate")
  223. params.setValue(shopOpen.debitCardCapping, forKey: "debitCardCapping")
  224. params.setValue(shopOpen.unionpayRate, forKey: "unionpayRate")
  225. params.setValue(shopOpen.loanCardCapping, forKey: "loanCardCapping")
  226. submitData(url: url, params: params, tag: 1001)
  227. }
  228. ///费率
  229. let dicFL = NSMutableDictionary()
  230. func getFeiLv(isDefault: Bool) {
  231. if dicFL.count > 0 {
  232. returnData(tag: 1003)
  233. return
  234. }
  235. let params = NSMutableDictionary()
  236. let url = RequestURL.rateConfig
  237. params.setValue(shopOpen.posId, forKey: "machine_type_id")
  238. params.setValue(shopOpen.shopType, forKey: "merchant_type")
  239. params.setValue(shopOpen.productTypeId, forKey: "product_type_id")
  240. if isDefault {
  241. loadDataInfo(url: url, params: params, tag: 1002, reDic: dicFL)
  242. } else {
  243. loadDataInfo(url: url, params: params, tag: 1003, reDic: dicFL)
  244. }
  245. }
  246. override func returnData(tag: Int) {
  247. if tag == 1001 {
  248. let arrLocal = NSMutableArray()
  249. let local = CommonValue.getDefaultUserInfoForObject(key: "common_local_businfo")
  250. if local != nil && (local as? NSArray) != nil && (local as! NSArray).count > 0 {
  251. arrLocal.addObjects(from: ((local as! NSArray) as! [Any]))
  252. }
  253. if localCurrnetIndex != -1 && arrLocal.count > localCurrnetIndex {
  254. arrLocal.removeObject(at: localCurrnetIndex)
  255. }
  256. CommonValue.setDefaultUserInfoForObject(value: arrLocal, key: "common_local_businfo")
  257. if shopOpen.id == "" {
  258. SVProgressHUD.showSuccess(withStatus: "信息提交成功,请等待审核!")
  259. self.cusHandleBack()
  260. } else {
  261. self.cusHandleBack()
  262. }
  263. } else if(tag == 1002) //初始化加载默认费率
  264. {
  265. shopOpen.rate = String.init(format: "%.2f", dicFL.getDouble(key: "loan_card_rate_default"))
  266. shopOpen.debitCardCostRate = String.init(format: "%.2f", dicFL.getDouble(key: "debit_card_cost_rate"))
  267. shopOpen.debitCardCapping = String.init(format: "%.2f", dicFL.getDouble(key: "debit_card_capping"))
  268. shopOpen.unionpayRate = String.init(format: "%.2f", dicFL.getDouble(key: "unionpay_rate"))
  269. shopOpen.loanCardCapping = String.init(format: "%.2f", dicFL.getDouble(key: "loan_card_capping"))
  270. arrRemark[0][5] = "\(String.init(format: "%.2f", dicFL.getDouble(key: "loan_card_rate_default")))%"
  271. self.tableView.reloadData()
  272. } else if(tag == 1003) //加载费率选择框
  273. {
  274. shopOpen.rate = String.init(format: "%.2f", dicFL.getDouble(key: "loan_card_rate_default"))
  275. shopOpen.debitCardCostRate = String.init(format: "%.2f", dicFL.getDouble(key: "debit_card_cost_rate"))
  276. shopOpen.debitCardCapping = String.init(format: "%.2f", dicFL.getDouble(key: "debit_card_capping"))
  277. shopOpen.unionpayRate = String.init(format: "%.2f", dicFL.getDouble(key: "unionpay_rate"))
  278. shopOpen.loanCardCapping = String.init(format: "%.2f", dicFL.getDouble(key: "loan_card_capping"))
  279. var rateMin = dicFL.getDouble(key: "loan_card_rate_min") * 100
  280. let rateMax = dicFL.getDouble(key: "loan_card_rate_max") * 100
  281. arrRateContent.removeAll()
  282. var arrTitle = [String]()
  283. while Int(rateMin) <= Int(rateMax) {
  284. arrTitle.append("\(String.init(format: "%.2f", rateMin / 100))%")
  285. arrRateContent.append(String.init(format: "%.2f", rateMin / 100))
  286. rateMin += 1
  287. }
  288. CommonUntils.AlertView(controller: self, title: nil, message: "请选择费率", buttons: arrTitle, style: .actionSheet) {[weak self] (index, _) in
  289. self!.arrRemark[0][5] = "\(self!.arrRateContent[index])%"
  290. self!.shopOpen.rate = self!.arrRateContent[index]
  291. self!.tableView.reloadData()
  292. }
  293. }
  294. }
  295. var arrRateContent = [String]()
  296. override func returnError(tag: Int, type: String) {
  297. }
  298. func cusHandleBack() {
  299. if !CommonUntils.reBackView(controller: self, aclass: ShopManagerViewController.classForCoder()) {
  300. self.navigationController?.popToRootViewController(animated: true)
  301. }
  302. }
  303. @objc func btnRemarkClick(btn: UIButton) {
  304. let vc = CommonWebViewViewController()
  305. vc.strTitle = "公司名称规则"
  306. vc.sourceType = 1
  307. vc.url = "\(RequestURL.sysConfigWeb)?type=company_name"
  308. toViewController(viewController: vc)
  309. }
  310. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  311. //[["公司简称","申请人信息","店铺地址","所属行业","结算信息"],["店铺照片","商户合影照"]]
  312. if arrTitle[indexPath.section][indexPath.row] == "公司简称" {
  313. } else if arrTitle[indexPath.section][indexPath.row] == "申请人信息" {
  314. let vc = ApplyerViewController()
  315. vc.shopOpen = self.shopOpen
  316. toViewController(viewController: vc)
  317. } else if arrTitle[indexPath.section][indexPath.row] == "店铺信息" {
  318. let vc = ShopAddressViewController()
  319. vc.shopOpen = self.shopOpen
  320. toViewController(viewController: vc)
  321. } else if arrTitle[indexPath.section][indexPath.row] == "所属行业" {
  322. let vc = ShopIndustryViewController()
  323. vc.shopOpen = self.shopOpen
  324. toViewController(viewController: vc)
  325. } else if arrTitle[indexPath.section][indexPath.row] == "结算信息" {
  326. let vc = BalanceAccountViewController()
  327. vc.shopOpen = self.shopOpen
  328. toViewController(viewController: vc)
  329. } else if arrTitle[indexPath.section][indexPath.row] == "店铺照片" {
  330. let vc = AddImagesViewController()
  331. vc.shopOpen = shopOpen
  332. vc.type = 0
  333. vc.initView()
  334. toViewController(viewController: vc)
  335. } else if arrTitle[indexPath.section][indexPath.row] == "费率" {
  336. getFeiLv(isDefault: false)
  337. } else if arrTitle[indexPath.section][indexPath.row] == "商户合影照" {
  338. let vc = AddImagesViewController()
  339. vc.shopOpen = shopOpen
  340. vc.type = 1
  341. vc.initView()
  342. toViewController(viewController: vc)
  343. }
  344. }
  345. func reloadAlertInfo() {
  346. //arrRemark = [["公司名称+所属行业","请上传照片","请填写详细地址","请选择","请上传照片"],["选填,请上传照片","选填,请上传照片"]];
  347. if shopOpen.cardFront != "" {
  348. arrRemark[0][1] = "已填写"
  349. } else {
  350. arrRemark[0][1] = arrRemarkDefault[0][1]
  351. }
  352. if shopOpen.addressId1 != "" {
  353. arrRemark[0][2] = "已填写"
  354. } else {
  355. arrRemark[0][2] = arrRemarkDefault[0][2]
  356. }
  357. if shopOpen.typeId1 != "" {
  358. arrRemark[0][3] = "已填写"
  359. } else {
  360. arrRemark[0][3] = arrRemarkDefault[0][3]
  361. }
  362. if shopOpen.bankCardImage != "" {
  363. arrRemark[0][4] = "已填写"
  364. } else {
  365. arrRemark[0][4] = arrRemarkDefault[0][4]
  366. }
  367. if shopOpen.dpImages != "" {
  368. arrRemark[1][0] = "已上传\(shopOpen.dpImages.split(s: ",").count)张"
  369. } else {
  370. arrRemark[1][0] = arrRemarkDefault[1][0]
  371. }
  372. if shopOpen.shhyzImages != "" {
  373. arrRemark[1][1] = "已上传\(shopOpen.shhyzImages.split(s: ",").count)张"
  374. } else {
  375. arrRemark[1][1] = arrRemarkDefault[1][1]
  376. }
  377. tableView.reloadData()
  378. }
  379. override func viewWillAppear(_ animated: Bool) {
  380. super.viewWillAppear(animated)
  381. initData()
  382. if isMod {
  383. viewFooter.isHidden = false
  384. } else {
  385. viewFooter.isHidden = true
  386. }
  387. if type == 1 {
  388. lblNoAlert.isHidden = false
  389. txtNoPassContent.isHidden = false
  390. txtNoPassContent.text = shopOpen.reason
  391. }
  392. }
  393. override func viewDidAppear(_ animated: Bool) {
  394. super.viewDidAppear(animated)
  395. closeRightBack()
  396. }
  397. override func viewWillDisappear(_ animated: Bool) {
  398. super.viewWillDisappear(animated)
  399. }
  400. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  401. super.init(nibName: "OpenDetailViewController", bundle: nil)
  402. }
  403. required init?(coder aDecoder: NSCoder) {
  404. fatalError("init(coder:) has not been implemented")
  405. }
  406. }
  407. extension UserDefaults {
  408. func saveCustomObj(customObject object: NSCoding, key: String) {
  409. let encodedObject = NSKeyedArchiver.archivedData(withRootObject: object)
  410. self.setValue(encodedObject, forKey: key)
  411. self.synchronize()
  412. }
  413. }