TradeViewController.swift 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. //
  2. // TradeViewController.swift
  3. // xingchuangke
  4. //
  5. // Created by Virgil on 2019/4/13.
  6. // Copyright © 2019 Virgil. All rights reserved.
  7. //
  8. import UIKit
  9. class TradeViewController: BaseViewController, UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate {
  10. @IBOutlet weak var btnSort: UIButton!
  11. @IBOutlet weak var tableView: UITableView!
  12. @IBOutlet weak var imgBackgroud: UIImageView!
  13. @IBOutlet weak var txtCode: UITextField!
  14. @IBOutlet weak var viewMenu: UIView!
  15. @IBOutlet weak var viewRemark: UIView!
  16. @IBOutlet weak var viewMoney: UIView!
  17. @IBOutlet weak var allNumLabel: UILabel!
  18. @IBOutlet weak var allMoneyLabel: UILabel!
  19. var rightMenu: CommonRightMenu!
  20. var rightMenuhk: CommonRightMenuHK!
  21. var rightMenuky: CommonRightMenuKY!
  22. var rightMenuks: CommonRightMenuKS!
  23. var rightMenuhhsf: CommonRightMenuHSF!
  24. var queryEntity: QueryEntity!
  25. var machineTypeId: String!
  26. var machineType: String?
  27. var titleStr: String?
  28. override func viewDidLoad() {
  29. super.viewDidLoad()
  30. let index: NSInteger = brandIdList.lastIndex(of: machineTypeId) ?? 0
  31. machineType = brandList[index]
  32. queryEntity = QueryEntity()
  33. let viewNav = (CommonViewUntils.getViewForXIB(xibName: "NavView") as! NavView)
  34. viewNav.initView(title: titleStr ?? "") {[weak self] (index, _) in
  35. if index == 0 {
  36. self!.handleBack()
  37. }
  38. }
  39. self.view.addSubview(viewNav)
  40. viewNav.marginTop(top: 0)
  41. self.view.addSubview(viewNav)
  42. viewNav.marginTop(top: 0)
  43. viewMenu.marginTop(top: viewNav.bottom())
  44. txtCode.setCornerRadius(size: 4)
  45. txtCode.setContentMarginLeft(leftWidth: 15)
  46. txtCode.setContentMarginRight(rightWidth: 30)
  47. imgBackgroud.setSizeHeight(height: viewMenu.bottom())
  48. viewRemark.marginTop(top: 0, view: imgBackgroud)
  49. viewMoney.frame.size.width = SCREEN_WIDTH
  50. viewMoney.marginTop(top: 0, view: viewRemark)
  51. tableView.marginTop(top: 1, view: viewMoney)
  52. tableView.setSizeHeight(height: ScreenHeight - imgBackgroud.height() - 49 - 35)
  53. tableView.register(UINib(nibName: "TradeTableViewCell", bundle: nil), forCellReuseIdentifier: "TradeTableViewCell")
  54. tableView.delegate = self
  55. tableView.dataSource = self
  56. tableView.separatorStyle = .none
  57. tableView.showsVerticalScrollIndicator = false
  58. tableView.estimatedRowHeight = 100
  59. txtCode.delegate = self
  60. txtCode.returnKeyType = .search
  61. tableView.mj_header = MJRefreshNormalHeader(refreshingBlock: {[weak self] in
  62. self!.currentPage = 1
  63. self!.loadData()
  64. })
  65. tableView.mj_header?.lastUpdatedTimeKey = "ShowTableViewCell"
  66. tableView.mj_footer = MJRefreshBackNormalFooter(refreshingBlock: {[weak self] in
  67. self!.currentPage += 1
  68. self!.loadData()
  69. })
  70. tableView.mj_header?.beginRefreshing()
  71. }
  72. // MARK: =============加载数据===============
  73. func loadData() {
  74. let url = RequestURL.transactionListPage
  75. let params = NSMutableDictionary()
  76. params.setValue(machineTypeId, forKey: "machineTypeId")
  77. params.setValue(queryEntity.startTime == "选择开始日期" ? "" : queryEntity.startTime, forKey: "timeStart")
  78. params.setValue(queryEntity.endTime == "选择截止日期" ? "" : queryEntity.endTime, forKey: "timeEnd")
  79. params.setValue(queryEntity.cardType, forKey: "cardType")
  80. params.setValue(queryEntity.busType, forKey: "busType")
  81. params.setValue(queryEntity.payType, forKey: "payType")
  82. params.setValue(queryEntity.depositTrade, forKey: "depositTrade")
  83. params.setValue(queryEntity.settleWay, forKey: "settleWay")
  84. params.setValue(queryEntity.deviceType, forKey: "deviceType")
  85. if btnSort.isSelected {
  86. params.setValue("asc", forKey: "sortType")
  87. } else {
  88. params.setValue("desc", forKey: "sortType")
  89. }
  90. params.setValue(txtCode.text!, forKey: "likeStr")
  91. loadDataList(url: url, params: params, tableView: tableView, tag: 1001)
  92. }
  93. func loadProType() {
  94. if arrType.count > 0 {
  95. returnData(tag: 1002)
  96. return
  97. }
  98. let url = RequestURL.machineTypeList
  99. let params = NSMutableDictionary()
  100. params.setValue(CommonValue.getUserId(), forKey: "userId")
  101. loadDataList(url: url, params: params, tag: 1002, array: arrType)
  102. }
  103. override func returnData(tag: Int) {
  104. if tag == 1001 {
  105. self.allNumLabel.text = self.dicData["XTransactionDataCount"] as? String
  106. self.allMoneyLabel.text = self.dicData["XTransactionDataTotal"] as? String
  107. tableView.reloadData()
  108. } else if tag == 1002 {
  109. if rightMenu == nil || rightMenuhk == nil || rightMenuky == nil || rightMenuks == nil || rightMenuhhsf == nil{
  110. if machineTypeId == "2" {
  111. rightMenu = (CommonViewUntils.getViewForXIB(xibName: "CommonRightMenu") as! CommonRightMenu)
  112. rightMenu.initView(arrType: arrType) {[weak self] (queryEntityTemp) in
  113. self!.queryEntity.typeID = queryEntityTemp.typeID
  114. self!.queryEntity.startTime = queryEntityTemp.startTime
  115. self!.queryEntity.endTime = queryEntityTemp.endTime
  116. self!.queryEntity.cardType = queryEntityTemp.cardType
  117. self!.queryEntity.busType = queryEntityTemp.busType
  118. self!.queryEntity.payType = queryEntityTemp.payType
  119. self!.queryEntity.depositTrade = queryEntityTemp.depositTrade
  120. self!.queryEntity.settleWay = queryEntityTemp.settleWay
  121. self!.tableView.mj_header?.beginRefreshing()
  122. }
  123. rightMenu.showMenu(paretnView: self.view)
  124. }else if machineTypeId == "4" {
  125. rightMenuky = (CommonViewUntils.getViewForXIB(xibName: "CommonRightMenuKY") as! CommonRightMenuKY)
  126. rightMenuky.initView(arrType: arrType) {[weak self] (queryEntityTemp) in
  127. self!.queryEntity.typeID = queryEntityTemp.typeID
  128. self!.queryEntity.startTime = queryEntityTemp.startTime
  129. self!.queryEntity.endTime = queryEntityTemp.endTime
  130. self!.queryEntity.cardType = queryEntityTemp.cardType
  131. self!.queryEntity.busType = queryEntityTemp.busType
  132. self!.queryEntity.payType = queryEntityTemp.payType
  133. self!.queryEntity.depositTrade = queryEntityTemp.depositTrade
  134. self!.queryEntity.settleWay = queryEntityTemp.settleWay
  135. self!.tableView.mj_header?.beginRefreshing()
  136. }
  137. rightMenuky.showMenu(paretnView: self.view)
  138. }else if machineTypeId == "4e7c6d802cf149e9b8e1fc0efca4e965" {
  139. rightMenuks = (CommonViewUntils.getViewForXIB(xibName: "CommonRightMenuKS") as! CommonRightMenuKS)
  140. rightMenuks.initView(arrType: arrType) {[weak self] (queryEntityTemp) in
  141. self!.queryEntity.typeID = queryEntityTemp.typeID
  142. self!.queryEntity.startTime = queryEntityTemp.startTime
  143. self!.queryEntity.endTime = queryEntityTemp.endTime
  144. self!.queryEntity.cardType = queryEntityTemp.cardType
  145. self!.queryEntity.busType = queryEntityTemp.busType
  146. self!.queryEntity.depositTrade = queryEntityTemp.depositTrade
  147. self!.queryEntity.settleWay = queryEntityTemp.settleWay
  148. self!.queryEntity.deviceType = queryEntityTemp.deviceType
  149. self!.tableView.mj_header?.beginRefreshing()
  150. }
  151. rightMenuks.showMenu(paretnView: self.view)
  152. }else if machineTypeId == "777" || machineTypeId == "888" || machineTypeId == "999" || machineTypeId == "9999" {
  153. rightMenuhhsf = (CommonViewUntils.getViewForXIB(xibName: "CommonRightMenuHSF") as! CommonRightMenuHSF)
  154. rightMenuhhsf.initView(arrType: arrType) {[weak self] (queryEntityTemp) in
  155. self!.queryEntity.typeID = queryEntityTemp.typeID
  156. self!.queryEntity.startTime = queryEntityTemp.startTime
  157. self!.queryEntity.endTime = queryEntityTemp.endTime
  158. self!.queryEntity.cardType = queryEntityTemp.cardType
  159. self!.queryEntity.depositTrade = queryEntityTemp.depositTrade
  160. self!.tableView.mj_header?.beginRefreshing()
  161. }
  162. rightMenuhhsf.showMenu(paretnView: self.view)
  163. }else {
  164. rightMenuhk = (CommonViewUntils.getViewForXIB(xibName: "CommonRightMenuHK") as! CommonRightMenuHK)
  165. rightMenuhk.initView(arrType: arrType) {[weak self] (queryEntityTemp) in
  166. self!.queryEntity.typeID = queryEntityTemp.typeID
  167. self!.queryEntity.startTime = queryEntityTemp.startTime
  168. self!.queryEntity.endTime = queryEntityTemp.endTime
  169. self!.queryEntity.cardType = queryEntityTemp.cardType
  170. self!.queryEntity.busType = queryEntityTemp.busType
  171. self!.queryEntity.payType = queryEntityTemp.payType
  172. self!.queryEntity.depositTrade = queryEntityTemp.depositTrade
  173. self!.queryEntity.settleWay = queryEntityTemp.settleWay
  174. self!.tableView.mj_header?.beginRefreshing()
  175. }
  176. rightMenuhk.showMenu(paretnView: self.view)
  177. }
  178. }
  179. }
  180. }
  181. override func returnError(tag: Int, type: String) {
  182. }
  183. var arrType = NSMutableArray()
  184. @IBAction func btnMenuClick(_ sender: AnyObject) {
  185. switch (sender as! UIButton).tag {
  186. case 1001: // 排序
  187. btnSort.isSelected = !btnSort.isSelected
  188. self.currentPage = 1
  189. loadData()
  190. break
  191. case 1002: // 筛选
  192. loadProType()
  193. break
  194. case 1003: //
  195. break
  196. case 1004: //
  197. break
  198. case 1005: //
  199. break
  200. case 1006: //
  201. break
  202. default:
  203. break
  204. }
  205. }
  206. @IBAction func btnQuery(_ sender: Any) {
  207. self.currentPage = 1
  208. loadData()
  209. }
  210. func textFieldShouldReturn(_ textField: UITextField) -> Bool {
  211. self.currentPage = 1
  212. loadData()
  213. return true
  214. }
  215. // MARK: TABLEVLEW 实现
  216. // MARK: TABLEVLEW 实现
  217. func numberOfSections(in tableView: UITableView) -> Int {
  218. return 1
  219. }
  220. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  221. return self.arrData.count
  222. }
  223. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  224. return 111
  225. }
  226. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  227. let cell = tableView.dequeueReusableCell(withIdentifier: "TradeTableViewCell", for: indexPath as IndexPath) as! TradeTableViewCell
  228. cell.lblName.text = getString(current: indexPath.row, key: "shopName")
  229. cell.lblMachineTypename.text = machineType
  230. cell.lblMoney.text = "¥\(getString(current: indexPath.row, key: "tradeAmount") )"
  231. cell.lblCard.text = getString(current: indexPath.row, key: "cardNo")
  232. let payType = getString(current: indexPath.row, key: "payType")
  233. // if(payType == "00")
  234. // {
  235. // cell.lblTransactionType.text = "T0"
  236. // }
  237. // else if(payType == "01")
  238. // {
  239. // cell.lblTransactionType.text = "T1"
  240. // }
  241. if payTypeDic[payType] as? String == nil {
  242. cell.lblTransactionType.text = payType
  243. }else{
  244. cell.lblTransactionType.text = payTypeDic[payType] as? String
  245. }
  246. let cardType1 = getString(current: indexPath.row, key: "cardType")
  247. var cardType = ""
  248. if machineTypeId == "4e7c6d802cf149e9b8e1fc0efca4e965" {
  249. cardType = cardTypeTradeDic1[cardType1] as? String ?? ""
  250. }else{
  251. cardType = cardTypeTradeDic[cardType1] as? String ?? ""
  252. }
  253. let depositTrade1 = getString(current: indexPath.row, key: "depositTrade")
  254. let depositTrade = depositTradeDic[depositTrade1] as? String
  255. if getString(current: indexPath.row, key: "cardType") != "" {
  256. let index = Int(getString(current: indexPath.row, key: "cardType")) ?? -1
  257. if index >= 0 {
  258. cell.lblRemark.text = "卡类型:\(cardType ) 交易类型:\(depositTrade ?? "")"
  259. } else {
  260. cell.lblRemark.text = "卡类型:\(getString(current: indexPath.row, key: "cardType")) 交易类型:\(getString(current: indexPath.row, key: "depositTrade"))"
  261. }
  262. } else {
  263. if Int(getString(current: indexPath.row, key: "depositTrade")) != 0 {
  264. cell.lblRemark.text = "交易类型:\(depositTrade ?? "")"
  265. } else {
  266. cell.lblRemark.text = "交易类型:\(getString(current: indexPath.row, key: "depositTrade"))"
  267. }
  268. }
  269. cell.lblDate.text = getString(current: indexPath.row, key: "tradeDate")
  270. return cell
  271. }
  272. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  273. // let view = UIViewController()
  274. // view.oneGoId = self.arrData[indexPath.row]["ItemId"] as! Int
  275. // self.navigationController?.pushViewController(view, animated: true)
  276. }
  277. override func viewWillAppear(_ animated: Bool) {
  278. super.viewWillAppear(animated)
  279. appDelegate.setNavigationBarHidden(isHidden: true)
  280. }
  281. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  282. super.init(nibName: "TradeViewController", bundle: nil)
  283. }
  284. required init?(coder aDecoder: NSCoder) {
  285. fatalError("init(coder:) has not been implemented")
  286. }
  287. var payTypeDic: NSDictionary = ["POSPAY": "刷卡", "QR_WECHAT": "微信", "QR_ALIPAY": "支付宝", "QR_UNIONPAY": "银联二维码", "QR_QQPAY": "QQ钱包", "00": "消费", "01": "收款", "02": "云闪付", "03": "智能消费", "04": "微信", "05": "支付宝", "云闪付借记卡": "云闪付借记卡", "云闪付贷记卡": "云闪付贷记卡", "刷卡交易借记卡": "刷卡交易借记卡", "刷卡交易贷记卡标准类": "刷卡交易贷记卡标准类", "刷卡交易贷记卡优惠类": "刷卡交易贷记卡优惠类", "刷卡交易贷记卡优享类": "刷卡交易贷记卡优享类", "刷卡交易贷记卡特殊计费类": "刷卡交易贷记卡特殊计费类", "刷卡交易贷记卡减免类": "刷卡交易贷记卡减免类", "微信": "微信", "支付宝": "支付宝", "刷卡": "刷卡", "挥卡": "挥卡", "闪付": "闪付", "海收付": "刷卡"]
  288. var depositTradeDic: NSDictionary = ["03": "消费", "19": "押金", "20": "智能消费", "21": "抵扣消费", "1": "押金", "consume": "消费", "0": "消费", "01": "刷卡", "02": "挥卡", "03": "芯片插卡", "04": "扫码", "05": "押金"]
  289. var cardTypeTradeDic: NSDictionary = ["1": "借记卡", "2": "贷记卡", "3": "准贷记卡", "4": "预付费卡", "5": "银联双免", "01": "借记卡", "02": "信用卡"]
  290. var cardTypeTradeDic1: NSDictionary = ["1": "借记卡", "2": "贷记卡", "3": "准贷记卡", "4": "预付费卡", "5": "银联双免", "01": "借记卡", "02": "贷记卡"]
  291. }