CommonRightMenuHSF.swift 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. //
  2. // CommonRightMenuHSF.swift
  3. // xingchuangke
  4. //
  5. // Created by 刘惠萍 on 2023/1/31.
  6. //
  7. import UIKit
  8. class CommonRightMenuHSF: UIView {
  9. @IBOutlet weak var scrollView: UIScrollView!
  10. @IBOutlet weak var busAllBtn: UIButton!
  11. @IBOutlet weak var busBZBtn: UIButton!
  12. @IBOutlet weak var busYHBtn: UIButton!
  13. @IBOutlet weak var busWXBtn: UIButton!
  14. @IBOutlet weak var busZFBBtn: UIButton!
  15. @IBOutlet weak var busYLBtn: UIButton!
  16. @IBOutlet weak var busLLBtn: UIButton!
  17. @IBOutlet weak var busYJBtn: UIButton!
  18. @IBOutlet weak var cardAllBtn: UIButton!
  19. @IBOutlet weak var cardJJBtn: UIButton!
  20. @IBOutlet weak var cardXYBtn: UIButton!
  21. @IBOutlet weak var btnConfrim: UIButton!
  22. @IBOutlet weak var btnReset: UIButton!
  23. @IBOutlet weak var btnEnd: UIButton!
  24. @IBOutlet weak var btnStart: UIButton!
  25. var queryEntity: QueryEntityHSF!
  26. var oBackFunc: CommonBackQueryHSF!
  27. var btnTypes = [UIButton]()
  28. var arrTempType = NSMutableArray()
  29. func initView(arrType: NSMutableArray, backFunc:@escaping CommonBackQueryHSF) {
  30. oBackFunc = backFunc
  31. self.setSizeWidth(width: ScreenWidth)
  32. btnEnd.setCornerRadius(size: 3)
  33. btnStart.setCornerRadius(size: 3)
  34. scrollView.contentSize.height = btnConfrim.bottom() + 40
  35. busAllBtn.isSelected = true
  36. cardAllBtn.isSelected = true
  37. busAllBtn.setTitleColor(.red, for: .selected)
  38. cardAllBtn.setTitleColor(.red, for: .selected)
  39. arrTempType.removeAllObjects()
  40. arrTempType.addObjects(from: arrType as! [Any])
  41. // scrollViewType.removeAll();
  42. var left: CGFloat = 14
  43. btnTypes.removeAll()
  44. for i in 0 ..< arrType.count {
  45. let btn = UIButton(frame: CGRect(x: left, y: 0, width: 100, height: 36))
  46. btn.backgroundColor = CommonUntils.getUIColorFromRGB(rgbValue: 0xf5f5f5, alpha: 1.0)
  47. btn.setTitle((arrType[i] as! NSDictionary).getString(key: "name"), for: .normal)
  48. btn.setTitleColor(CommonUntils.getUIColorFromRGB(rgbValue: 0x333333, alpha: 1.0), for: .normal)
  49. btn.setTitleColor(UIColor.white, for: .selected)
  50. btn.sizeToFitWidth()
  51. btn.titleLabel?.font = UIFont.systemFont(ofSize: 12)
  52. btn.tag = i
  53. btn.addTarget(self, action: #selector(btnTypeClick), for: .touchUpInside)
  54. btn.setSizeWidth(width: btn.width() + 40)
  55. // scrollViewType.addSubview(btn)
  56. left = btn.right() + 15
  57. btnTypes.append(btn)
  58. btn.setCornerRadius(size: 3)
  59. }
  60. // scrollViewType.contentSize.width = left;
  61. queryEntity = QueryEntityHSF()
  62. queryEntity.startTime = "选择开始日期"
  63. queryEntity.endTime = "选择截止日期"
  64. }
  65. @objc func btnTypeClick(btn: UIButton) {
  66. for btnTemp in btnTypes {
  67. if btnTemp.tag == btn.tag {
  68. queryEntity.typeID = (arrTempType[btn.tag] as! NSDictionary).getString(key: "id")
  69. btnTemp.backgroundColor = CommonUntils.getUIColorFromRGB(rgbValue: 0x2A92F7, alpha: 1.0)
  70. btnTemp.isSelected = true
  71. } else {
  72. btnTemp.backgroundColor = CommonUntils.getUIColorFromRGB(rgbValue: 0xf5f5f5, alpha: 1.0)
  73. btnTemp.isSelected = false
  74. }
  75. }
  76. }
  77. @IBAction func btnMenuClick(_ sender: AnyObject) {
  78. switch (sender as! UIButton).tag {
  79. case 1001: // 开始时间
  80. let viewDatePicer = (CommonViewUntils.getViewForXIB(anyClass: Virgil_SelectDateForPickerView.self) as! Virgil_SelectDateForPickerView)
  81. var defaultDate: Date!
  82. if queryEntity.startTime == "选择开始日期" || queryEntity.startTime.length() != 10 {
  83. defaultDate = CommonDate.addMonth(date: Date(), month: 0)
  84. } else {
  85. defaultDate = CommonDate.getDateForString(dateStr: queryEntity.startTime, dateFormat: "yyyy-MM-dd")
  86. }
  87. viewDatePicer.datePicker.maximumDate = Date()
  88. viewDatePicer.showDatePickerView(defaultDate: defaultDate) {[weak self] (str) in
  89. self!.queryEntity.startTime = str
  90. self!.refreshView()
  91. }
  92. break
  93. case 1002: // 结束时间
  94. let viewDatePicer = (CommonViewUntils.getViewForXIB(anyClass: Virgil_SelectDateForPickerView.self) as! Virgil_SelectDateForPickerView)
  95. var defaultDate: Date!
  96. if queryEntity.endTime == "选择截止日期" || queryEntity.endTime.length() != 10 {
  97. defaultDate = Date()
  98. } else {
  99. defaultDate = CommonDate.getDateForString(dateStr: queryEntity.endTime, dateFormat: "yyyy-MM-dd")
  100. }
  101. viewDatePicer.datePicker.maximumDate = Date()
  102. viewDatePicer.showDatePickerView(defaultDate: defaultDate) {[weak self] (str) in
  103. self!.queryEntity.endTime = str
  104. self!.refreshView()
  105. }
  106. refreshView()
  107. break
  108. case 1021: // 全部
  109. queryEntity.depositTrade = ""
  110. refreshView()
  111. break
  112. case 1022: // 标准消费
  113. queryEntity.depositTrade = "00"
  114. refreshView()
  115. break
  116. case 1023: // 优惠消费
  117. queryEntity.depositTrade = "01"
  118. refreshView()
  119. break
  120. case 1024: // wx
  121. queryEntity.depositTrade = "02"
  122. refreshView()
  123. break
  124. case 1025: // zfb
  125. queryEntity.depositTrade = "03"
  126. refreshView()
  127. break
  128. case 1026: // 银联二维码
  129. queryEntity.depositTrade = "04"
  130. refreshView()
  131. break
  132. case 1027: // 流量费
  133. queryEntity.depositTrade = "05"
  134. refreshView()
  135. break
  136. case 1028: // 押金消费
  137. queryEntity.depositTrade = "06"
  138. refreshView()
  139. break
  140. case 1041: // 全部
  141. queryEntity.cardType = ""
  142. refreshView()
  143. break
  144. case 1042: // 借记卡
  145. queryEntity.cardType = "0"
  146. refreshView()
  147. break
  148. case 1043: // 信用卡
  149. queryEntity.cardType = "1"
  150. refreshView()
  151. break
  152. case 1007: // 重置
  153. queryEntity.startTime = "选择开始日期"
  154. queryEntity.endTime = "选择截止日期"
  155. queryEntity.cardType = ""
  156. queryEntity.depositTrade = ""
  157. refreshView()
  158. break
  159. case 1008: // 确定
  160. hidMenu()
  161. if oBackFunc != nil {
  162. oBackFunc(queryEntity)
  163. }
  164. break
  165. case 1009: // 隐藏
  166. hidMenu()
  167. break
  168. default:
  169. break
  170. }
  171. }
  172. func refreshView() {
  173. for btnTemp in btnTypes {
  174. if queryEntity.typeID != (arrTempType[btnTemp.tag] as! NSDictionary).getString(key: "id") {
  175. btnTemp.isSelected = false
  176. btnTemp.backgroundColor = CommonUntils.getUIColorFromRGB(rgbValue: 0xf5f5f5, alpha: 1.0)
  177. }
  178. }
  179. if queryEntity.depositTrade == "" {
  180. busAllBtn.isSelected = true
  181. busBZBtn.isSelected = false
  182. busYHBtn.isSelected = false
  183. busWXBtn.isSelected = false
  184. busZFBBtn.isSelected = false
  185. busYLBtn.isSelected = false
  186. busLLBtn.isSelected = false
  187. busYJBtn.isSelected = false
  188. busAllBtn.setTitleColor(.red, for: .selected)
  189. busBZBtn.setTitleColor(.black, for: .normal)
  190. busYHBtn.setTitleColor(.black, for: .normal)
  191. busWXBtn.setTitleColor(.black, for: .normal)
  192. busZFBBtn.setTitleColor(.black, for: .normal)
  193. busYLBtn.setTitleColor(.black, for: .normal)
  194. busLLBtn.setTitleColor(.black, for: .normal)
  195. busYJBtn.setTitleColor(.black, for: .normal)
  196. } else if queryEntity.depositTrade == "00" {
  197. busAllBtn.isSelected = false
  198. busBZBtn.isSelected = true
  199. busYHBtn.isSelected = false
  200. busWXBtn.isSelected = false
  201. busZFBBtn.isSelected = false
  202. busYLBtn.isSelected = false
  203. busLLBtn.isSelected = false
  204. busYJBtn.isSelected = false
  205. busAllBtn.setTitleColor(.black, for: .normal)
  206. busBZBtn.setTitleColor(.red, for: .selected)
  207. busYHBtn.setTitleColor(.black, for: .normal)
  208. busWXBtn.setTitleColor(.black, for: .normal)
  209. busZFBBtn.setTitleColor(.black, for: .normal)
  210. busYLBtn.setTitleColor(.black, for: .normal)
  211. busLLBtn.setTitleColor(.black, for: .normal)
  212. busYJBtn.setTitleColor(.black, for: .normal)
  213. }else if queryEntity.depositTrade == "01" {
  214. busAllBtn.isSelected = false
  215. busBZBtn.isSelected = false
  216. busYHBtn.isSelected = true
  217. busWXBtn.isSelected = false
  218. busZFBBtn.isSelected = false
  219. busYLBtn.isSelected = false
  220. busLLBtn.isSelected = false
  221. busYJBtn.isSelected = false
  222. busAllBtn.setTitleColor(.black, for: .normal)
  223. busBZBtn.setTitleColor(.black, for: .normal)
  224. busYHBtn.setTitleColor(.red, for: .selected)
  225. busWXBtn.setTitleColor(.black, for: .normal)
  226. busZFBBtn.setTitleColor(.black, for: .normal)
  227. busYLBtn.setTitleColor(.black, for: .normal)
  228. busLLBtn.setTitleColor(.black, for: .normal)
  229. busYJBtn.setTitleColor(.black, for: .normal)
  230. }else if queryEntity.depositTrade == "02" {
  231. busAllBtn.isSelected = false
  232. busBZBtn.isSelected = false
  233. busYHBtn.isSelected = false
  234. busWXBtn.isSelected = true
  235. busZFBBtn.isSelected = false
  236. busYLBtn.isSelected = false
  237. busLLBtn.isSelected = false
  238. busYJBtn.isSelected = false
  239. busAllBtn.setTitleColor(.black, for: .normal)
  240. busBZBtn.setTitleColor(.black, for: .normal)
  241. busYHBtn.setTitleColor(.black, for: .normal)
  242. busWXBtn.setTitleColor(.red, for: .selected)
  243. busZFBBtn.setTitleColor(.black, for: .normal)
  244. busYLBtn.setTitleColor(.black, for: .normal)
  245. busLLBtn.setTitleColor(.black, for: .normal)
  246. busYJBtn.setTitleColor(.black, for: .normal)
  247. }else if queryEntity.depositTrade == "03" {
  248. busAllBtn.isSelected = false
  249. busBZBtn.isSelected = false
  250. busYHBtn.isSelected = false
  251. busWXBtn.isSelected = false
  252. busZFBBtn.isSelected = true
  253. busYLBtn.isSelected = false
  254. busLLBtn.isSelected = false
  255. busYJBtn.isSelected = false
  256. busAllBtn.setTitleColor(.black, for: .normal)
  257. busBZBtn.setTitleColor(.black, for: .normal)
  258. busYHBtn.setTitleColor(.black, for: .normal)
  259. busWXBtn.setTitleColor(.black, for: .normal)
  260. busZFBBtn.setTitleColor(.red, for: .selected)
  261. busYLBtn.setTitleColor(.black, for: .normal)
  262. busLLBtn.setTitleColor(.black, for: .normal)
  263. busYJBtn.setTitleColor(.black, for: .normal)
  264. }else if queryEntity.depositTrade == "04" {
  265. busAllBtn.isSelected = false
  266. busBZBtn.isSelected = false
  267. busYHBtn.isSelected = false
  268. busWXBtn.isSelected = false
  269. busZFBBtn.isSelected = false
  270. busYLBtn.isSelected = true
  271. busLLBtn.isSelected = false
  272. busYJBtn.isSelected = false
  273. busAllBtn.setTitleColor(.black, for: .normal)
  274. busBZBtn.setTitleColor(.black, for: .normal)
  275. busYHBtn.setTitleColor(.black, for: .normal)
  276. busWXBtn.setTitleColor(.black, for: .normal)
  277. busZFBBtn.setTitleColor(.black, for: .normal)
  278. busYLBtn.setTitleColor(.red, for: .selected)
  279. busLLBtn.setTitleColor(.black, for: .normal)
  280. busYJBtn.setTitleColor(.black, for: .normal)
  281. }else if queryEntity.depositTrade == "05" {
  282. busAllBtn.isSelected = false
  283. busBZBtn.isSelected = false
  284. busYHBtn.isSelected = false
  285. busWXBtn.isSelected = false
  286. busZFBBtn.isSelected = false
  287. busYLBtn.isSelected = false
  288. busLLBtn.isSelected = true
  289. busYJBtn.isSelected = false
  290. busAllBtn.setTitleColor(.black, for: .normal)
  291. busBZBtn.setTitleColor(.black, for: .normal)
  292. busYHBtn.setTitleColor(.black, for: .normal)
  293. busWXBtn.setTitleColor(.black, for: .normal)
  294. busZFBBtn.setTitleColor(.black, for: .normal)
  295. busYLBtn.setTitleColor(.black, for: .normal)
  296. busLLBtn.setTitleColor(.red, for: .selected)
  297. busYJBtn.setTitleColor(.black, for: .normal)
  298. } else {
  299. busAllBtn.isSelected = false
  300. busBZBtn.isSelected = false
  301. busYHBtn.isSelected = false
  302. busWXBtn.isSelected = false
  303. busZFBBtn.isSelected = false
  304. busYLBtn.isSelected = false
  305. busLLBtn.isSelected = false
  306. busYJBtn.isSelected = true
  307. busAllBtn.setTitleColor(.black, for: .normal)
  308. busBZBtn.setTitleColor(.black, for: .normal)
  309. busYHBtn.setTitleColor(.black, for: .normal)
  310. busWXBtn.setTitleColor(.black, for: .normal)
  311. busZFBBtn.setTitleColor(.black, for: .normal)
  312. busYLBtn.setTitleColor(.black, for: .normal)
  313. busLLBtn.setTitleColor(.black, for: .normal)
  314. busYJBtn.setTitleColor(.red, for: .selected)
  315. }
  316. if queryEntity.cardType == "" {
  317. cardAllBtn.isSelected = true
  318. cardJJBtn.isSelected = false
  319. cardXYBtn.isSelected = false
  320. cardAllBtn.setTitleColor(.red, for: .selected)
  321. cardJJBtn.setTitleColor(.black, for: .normal)
  322. cardXYBtn.setTitleColor(.black, for: .normal)
  323. } else if queryEntity.cardType == "0" {
  324. cardAllBtn.isSelected = false
  325. cardJJBtn.isSelected = true
  326. cardXYBtn.isSelected = false
  327. cardAllBtn.setTitleColor(.black, for: .normal)
  328. cardJJBtn.setTitleColor(.red, for: .selected)
  329. cardXYBtn.setTitleColor(.black, for: .normal)
  330. }else if queryEntity.cardType == "1" {
  331. cardAllBtn.isSelected = false
  332. cardJJBtn.isSelected = false
  333. cardXYBtn.isSelected = true
  334. cardAllBtn.setTitleColor(.black, for: .normal)
  335. cardJJBtn.setTitleColor(.black, for: .normal)
  336. cardXYBtn.setTitleColor(.red, for: .selected)
  337. }
  338. btnStart.setTitle(queryEntity.startTime, for: .normal)
  339. btnEnd.setTitle(queryEntity.endTime, for: .normal)
  340. }
  341. func showMenu(paretnView: UIView) {
  342. scrollView.marginLeft(left: ScreenWidth)
  343. paretnView.addSubview(self)
  344. self.setFillForSuperView()
  345. UIView.animate(withDuration: 0.5, animations: {
  346. self.scrollView.marginLeft(left: ScreenWidth - self.scrollView.width())
  347. }) { (_) in
  348. }
  349. }
  350. func hidMenu() {
  351. UIView.animate(withDuration: 0.5, animations: {
  352. self.scrollView.marginLeft(left: ScreenWidth)
  353. }) { (_) in
  354. self.removeFromSuperview()
  355. }
  356. }
  357. }
  358. class QueryEntityHSF: NSObject {
  359. ///品牌ID
  360. var typeID = ""
  361. var startTime = ""
  362. var endTime = ""
  363. ///交易卡类型:借记卡
  364. var cardType = ""
  365. ///交易类型
  366. var depositTrade = ""
  367. }
  368. typealias CommonBackQueryHSF=(_ entity: QueryEntityHSF) -> Void