IHEquipmentSearchView.swift 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. //
  2. // IHEquipmentSearchView.swift
  3. // Inhealth
  4. //
  5. // Created by weclouds on 2020/1/13.
  6. // Copyright © 2020 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. import ESPullToRefresh
  10. protocol IHEquipmentSearchViewDelegate : NSObjectProtocol{
  11. //查找设备
  12. func searchDevice(_ keyWords : String?)
  13. //选择网关
  14. func equipmentListSelected(_ gateway: GatewayData?)
  15. //选择设备(学校/酒店)
  16. func equipmentListSelected(_ devData: DevData?)
  17. //左滑 - 设备(设置)
  18. func equipmentSetting(_ devData: DevData, segmentIndex: Int)
  19. //左滑 - 网关(设置)
  20. func gatewaySetting(_ gateway: GatewayData, segmentIndex setmentIndex: Int)
  21. //左滑 - 网关(升级)
  22. func gatewayUpdate(_ gateway : GatewayData,segmentIndex: Int)
  23. //左滑 - 设备(历史)
  24. func equipmentHistory(_ devData: DevData, segmentIndex: Int)
  25. //左滑 - 设备(删除)
  26. func equipmentListDeleteDevice(_ devType: String, devId: String,segmentIndex: Int)
  27. //左滑 - 网关(删除)
  28. func gatewayDelegate(_ gateway: GatewayData, segmentIndex: Int)
  29. func tableviewHeaderEsReloadData(keywords : String?)//上拉刷新
  30. func tableviewBottonEsgetMoreData(keywords : String?)//下拉刷新
  31. }
  32. class IHEquipmentSearchView: UIView {
  33. //weak var delegate : IHEquipmentlistViewDelegate?
  34. weak var delegate : IHEquipmentSearchViewDelegate?
  35. weak var target : IHEquipmentSeachVCtr?{
  36. didSet{
  37. //点击cell时,可以隐藏searchbar
  38. target?.definesPresentationContext = true
  39. }
  40. }
  41. private var searchText : String? //搜索输入的内容
  42. private var totalDeviceList : [AnyObject]? //所有的设备
  43. //查找返回的设备
  44. var searchSchoolAndHotelList : [DevData]?
  45. //查找返回的网关
  46. var searchGatewayList : [GatewayData]?
  47. //刷新列表
  48. var reloadAll : Bool?{
  49. didSet{
  50. var list = [AnyObject]()
  51. if searchSchoolAndHotelList?.count ?? 0 > 0{
  52. for item in searchSchoolAndHotelList! {
  53. list.append(item as AnyObject)
  54. }
  55. }
  56. if searchGatewayList?.count ?? 0 > 0{
  57. for item in searchGatewayList! {
  58. list.append(item as AnyObject)
  59. }
  60. }
  61. totalDeviceList = list
  62. self.tableView.reloadData()
  63. }
  64. }
  65. var devDataList:[DevData]?{
  66. didSet{
  67. self.tableView.reloadData()
  68. }
  69. }
  70. var gatewayList:[GatewayData]?{
  71. didSet{
  72. self.tableView.reloadData()
  73. }
  74. }
  75. var currentIndex :Int? = 0
  76. var fillterResult :[DevData]?{
  77. didSet{
  78. self.tableView.reloadData()
  79. }
  80. }
  81. var fillterGatewayResult:[GatewayData]?{
  82. didSet{
  83. self.tableView.reloadData()
  84. }
  85. }
  86. // MARK: - Cancel Button 取消按钮
  87. public var showCancelButtonWhileEditing: Bool = false
  88. private var isRemove = false //是否移除了上下拉刷新
  89. var searchController : UISearchController?
  90. //编辑的cell
  91. var editingIndexPath : IndexPath?
  92. lazy var tableView: UITableView = {
  93. let tableView = UITableView(frame: .zero, style: .plain)
  94. tableView.delegate = self
  95. tableView.dataSource = self
  96. tableView.allowsSelection = true
  97. tableView.separatorStyle = .none
  98. tableView.register(UINib(nibName: "IHEquipmentListCell", bundle: nil), forCellReuseIdentifier: "cell")
  99. return tableView
  100. }()
  101. override init(frame: CGRect) {
  102. super.init(frame: frame)
  103. // self.backgroundColor = .red
  104. addSubview(tableView)
  105. settingSerachController()
  106. //加载上下拉刷新
  107. tableViewRefresh()
  108. }
  109. private func tableViewRefresh(){
  110. let header = KKWRefreshHeaderAnimator(frame: CGRect.zero)
  111. let footer = ESRefreshFooterAnimator(frame: CGRect.zero)
  112. //下拉刷新
  113. tableView.es.addPullToRefresh(animator: header) {[unowned self] in
  114. log.debug("下ll拉加载更多")
  115. self.delegate?.tableviewHeaderEsReloadData(keywords :self.searchText)
  116. }
  117. //上拉加载更多
  118. tableView.es.addInfiniteScrolling(animator: footer) {[unowned self] in
  119. log.debug("上拉加载更多")
  120. //上拉刷新
  121. self.delegate?.tableviewBottonEsgetMoreData(keywords : self.searchText)
  122. }
  123. }
  124. required init?(coder: NSCoder) {
  125. fatalError("init(coder:) has not been implemented")
  126. }
  127. func endReflesh(){
  128. tableView.es.stopPullToRefresh()
  129. tableView.es.stopLoadingMore()
  130. }
  131. override func layoutSubviews() {
  132. super.layoutSubviews()
  133. searchController?.view.frame = self.bounds
  134. tableView.frame = self.bounds
  135. // tableView.backgroundColor = .blue
  136. //加了上下拉刷新,就要加这个
  137. tableView.y = 44
  138. tableView.height = tableView.height - 44
  139. if self.editingIndexPath != nil {
  140. configSwipeButtons()
  141. }
  142. }
  143. func settingSerachController() {
  144. //传nil 搜索代码在当前界面
  145. searchController = UISearchController(searchResultsController: nil)
  146. searchController?.searchResultsUpdater = self
  147. searchController?.searchBar.frame = CGRect(x: 0, y: 0, width: 0, height: 44)
  148. searchController?.dimsBackgroundDuringPresentation = false
  149. searchController?.hidesNavigationBarDuringPresentation = true
  150. searchController?.obscuresBackgroundDuringPresentation = false
  151. searchController?.searchBar.sizeToFit()
  152. searchController?.searchBar.delegate = self
  153. searchController?.delegate = self
  154. //点击cell时,可以隐藏searchbar(这里此时的target是没有值的)
  155. // target?.definesPresentationContext = true
  156. tableView.tableHeaderView = searchController?.searchBar
  157. setSearchBar()
  158. }
  159. ///设置searchbar
  160. func setSearchBar() {
  161. //获取searchbar
  162. let searchBar = searchController?.searchBar
  163. searchBar?.barStyle = .default
  164. //获取searchBar 的search
  165. let searchField = searchBar?.value(forKey: "searchField") as? UITextField
  166. if searchField == nil {
  167. return
  168. }
  169. //文本框字体颜色
  170. searchField?.font = UIFont(name: PingFangSC_Regular, size: 14)
  171. searchField?.textColor = UIColor(hexString: "#333333")
  172. ///文本框文字颜色
  173. let holderText = "请输入设备ID或设备名称"
  174. let placeholder = NSMutableAttributedString(string: holderText)
  175. placeholder.addAttributes([NSAttributedString.Key.foregroundColor : UIColor(hexString: "#C6CDD5") as Any], range: NSRange(location: 0, length: holderText.count))
  176. placeholder.addAttributes([NSAttributedString.Key.font : UIFont(name: Alibaba_PuHuiTi_Regular, size: 14) as Any], range: NSRange(location: 0, length: holderText.count))
  177. searchField?.attributedPlaceholder = placeholder
  178. //设置文本框背景
  179. searchField?.backgroundColor = UIColor(hexString: "#F6F8F7")
  180. //隐藏搜索框的上下两条黑线
  181. searchBar?.backgroundImage = UIImage()
  182. //搜索框背景颜色
  183. searchBar?.barTintColor = UIColor(hexString: "#F6F8F7")
  184. searchBar?.tintColor = UIColor(hexString: "#657085")
  185. }
  186. ///设置取消按钮
  187. ///过滤
  188. func filterContent(for searchText:String) {
  189. if currentIndex == 0 {
  190. if self.devDataList != nil && self.devDataList?.count != 0{
  191. filterDevice(searchText)
  192. }
  193. if self.gatewayList != nil && self.gatewayList?.count != 0{
  194. filterGateway(searchText)
  195. }
  196. }else if currentIndex == 5{
  197. filterGateway(searchText)
  198. }else{
  199. filterDevice(searchText)
  200. }
  201. }
  202. func filterDevice(_ searchText:String) {
  203. let _devicelist = self.devDataList
  204. let devId = searchText
  205. var fillterDevicesNS : [DevData]
  206. if devId == "" || _devicelist == nil || _devicelist?.count == 0 { //没有输入则为传入的内容
  207. fillterDevicesNS = _devicelist!
  208. }else{
  209. fillterDevicesNS = (_devicelist?.filter({ (newDevice) -> Bool in
  210. let name = newDevice.name!.lowercased()
  211. let deviceId = newDevice.deviceId!
  212. let search = searchText.lowercased()
  213. //return name.contains(search) == true
  214. return deviceId.contains(search) == true || name.contains(search) == true
  215. }))!
  216. }
  217. fillterResult = fillterDevicesNS
  218. }
  219. func filterGateway(_ searchText:String) {
  220. let _devicelist = self.gatewayList
  221. let devId = searchText
  222. var fillterDevicesNS : [GatewayData]
  223. if devId == "" || _devicelist == nil || _devicelist?.count == 0 { //没有输入则为传入的内容
  224. fillterDevicesNS = _devicelist!
  225. }else{
  226. fillterDevicesNS = (_devicelist?.filter({ (newDevice) -> Bool in
  227. let name = newDevice.network_name!.lowercased()
  228. let deviceId = newDevice.gatewayId!.lowercased()
  229. let search = searchText.lowercased()
  230. return deviceId.contains(search) == true || name.contains(search) == true
  231. }))!
  232. }
  233. fillterGatewayResult = fillterDevicesNS
  234. }
  235. }
  236. extension IHEquipmentSearchView:UITableViewDelegate,UITableViewDataSource{
  237. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  238. return self.totalDeviceList?.count ?? 0
  239. // if currentIndex == 0 {
  240. // if searchController?.isActive == true {
  241. // let devCount = self.fillterResult?.count ?? 0
  242. // let gatewayListCount = self.fillterGatewayResult?.count ?? 0
  243. // let totalCount = devCount + gatewayListCount
  244. // return totalCount
  245. // }else{
  246. // let devCount = self.devDataList?.count ?? 0
  247. // let gatewayListCount = self.gatewayList?.count ?? 0
  248. // let totalCount = devCount + gatewayListCount
  249. // return totalCount
  250. // }
  251. // }else if currentIndex == 5{
  252. // if searchController?.isActive == true {
  253. // return self.fillterGatewayResult?.count ?? 0
  254. // }else{
  255. // return gatewayList?.count ?? 0
  256. // }
  257. // }else {
  258. // if searchController?.isActive == true {
  259. // return self.fillterResult?.count ?? 0
  260. // }else{
  261. // return devDataList?.count ?? 0
  262. // }
  263. // }
  264. }
  265. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  266. let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! IHEquipmentListCell
  267. cell.selectionStyle = .none
  268. if searchSchoolAndHotelList?.count ?? 0 > 0 {
  269. cell.devData = totalDeviceList?[indexPath.row] as? DevData
  270. }
  271. if searchGatewayList?.count ?? 0 > 0{
  272. cell.gateway = totalDeviceList?[indexPath.row] as? GatewayData
  273. }
  274. return cell
  275. // if currentIndex == 0 {
  276. // if searchController?.isActive == true {
  277. // if let filterNs = fillterResult {
  278. // if indexPath.row < filterNs.count {
  279. // let devData = filterNs[indexPath.row]
  280. // cell.devData = devData
  281. // }else{
  282. // let devData = self.fillterGatewayResult![indexPath.row - filterNs.count]
  283. // cell.gateway = devData
  284. // }
  285. // }
  286. // }else{
  287. // if let deviceList = self.devDataList {
  288. // if indexPath.row < deviceList.count {
  289. // let devData = self.devDataList![indexPath.row]
  290. // cell.devData = devData
  291. // }else{
  292. // let devData = self.gatewayList![indexPath.row - deviceList.count]
  293. // cell.gateway = devData
  294. // }
  295. // }
  296. // }
  297. //
  298. // }else if currentIndex == 5{
  299. // let devData = searchController?.isActive == true ? self.fillterGatewayResult![indexPath.row] : self.gatewayList![indexPath.row]
  300. // cell.gateway = devData
  301. // }else{
  302. // let devData = searchController?.isActive == true ? self.fillterResult![indexPath.row] : self.devDataList![indexPath.row]
  303. // cell.devData = devData
  304. // }
  305. //
  306. //
  307. // return cell
  308. }
  309. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  310. return 135
  311. }
  312. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  313. if searchSchoolAndHotelList?.count ?? 0 > 0 && searchSchoolAndHotelList!.count > indexPath.row{
  314. //设备 - (学校,酒店的)
  315. let devData = self.totalDeviceList?[indexPath.row] as? DevData
  316. self.delegate?.equipmentListSelected(devData)
  317. return
  318. }
  319. if searchGatewayList?.count ?? 0 > 0{
  320. //网关
  321. let devData = totalDeviceList?[indexPath.row] as? GatewayData
  322. delegate?.equipmentListSelected(devData)
  323. }
  324. // if currentIndex == 0 {
  325. // if searchController?.isActive == true {
  326. // if let filterNs = fillterResult {
  327. // if indexPath.row < filterNs.count {
  328. // let devData = filterNs[indexPath.row]
  329. // if let delegate = self.delegate {
  330. // //delegate.equipmentListSelected(devData)
  331. // }
  332. // }else{
  333. // let devData = self.fillterGatewayResult![indexPath.row - filterNs.count]
  334. // if let delegate = self.delegate {
  335. // //delegate.equipmentListSelected(devData)
  336. // }
  337. // }
  338. // }
  339. // }else{
  340. // if let deviceList = self.devDataList {
  341. // if indexPath.row < deviceList.count {
  342. // let devData = self.devDataList![indexPath.row]
  343. // if let delegate = self.delegate {
  344. // //delegate.equipmentListSelected(devData)
  345. // }
  346. // }else{
  347. // let devData = self.gatewayList![indexPath.row - deviceList.count]
  348. // if let delegate = self.delegate {
  349. // //delegate.equipmentListSelected(devData)
  350. // }
  351. // }
  352. // }
  353. // }
  354. //
  355. // }else if currentIndex == 5{
  356. // let devData = searchController?.isActive == true ? self.fillterGatewayResult![indexPath.row] : self.gatewayList![indexPath.row]
  357. // if let delegate = self.delegate {
  358. // //delegate.equipmentListSelected(devData)
  359. // }
  360. // }else{
  361. // let devData = searchController?.isActive == true ? self.fillterResult![indexPath.row] : self.devDataList![indexPath.row]
  362. // if let delegate = self.delegate {
  363. // //delegate.equipmentListSelected(devData)
  364. // }
  365. // }
  366. //
  367. //
  368. //
  369. // if searchController?.isActive == true {
  370. // self.searchController?.isActive = false
  371. // }
  372. }
  373. ///==========
  374. //iOS 11 将进入此方法 actions.performsFirstActionWithFullSwipe = NO 可以控制是否自动删除。
  375. func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
  376. let deleteAction = UIContextualAction(style: .normal, title: "") { (action, sourceView, completionHandler) in
  377. completionHandler(true)
  378. log.debug("删除")
  379. //处理事件(设备,网关)
  380. //删除设备
  381. if self.searchSchoolAndHotelList?.count ?? 0 > 0 && self.searchSchoolAndHotelList!.count > indexPath.row{
  382. let devData = self.totalDeviceList![indexPath.row] as? DevData
  383. self.delegate?.equipmentListDeleteDevice(devData!.type!, devId: devData!.id!, segmentIndex: self.currentIndex ?? 0)
  384. return
  385. }
  386. //删除网关
  387. if self.searchGatewayList?.count ?? 0 > 0{
  388. let gateway = self.totalDeviceList![indexPath.row] as? GatewayData
  389. self.delegate?.gatewayDelegate(gateway!, segmentIndex: self.currentIndex ?? 0)
  390. }
  391. // if let delegate = self.delegate{
  392. // let devData = self.devDataList![indexPath.row]
  393. // delegate.equipmentListDeleteDevice(devData.devType!, devId: devData.id!, segmentIndex: self.currentIndex ?? 0)
  394. // }
  395. }
  396. deleteAction.backgroundColor = UIColor(hexString: "#EBEFF2")
  397. let historyAction = UIContextualAction(style: .normal, title: "") { (action, sourceView, completionHandler) in
  398. completionHandler(true)
  399. //处理事件(设备历史,网关升级)
  400. //设备-历史
  401. if self.searchSchoolAndHotelList?.count ?? 0 > 0 && self.searchSchoolAndHotelList!.count > indexPath.row{
  402. let devData = self.totalDeviceList![indexPath.row] as? DevData
  403. self.delegate?.equipmentHistory(devData!, segmentIndex: 0)
  404. return
  405. }
  406. //网关-升级
  407. if self.searchGatewayList?.count ?? 0 > 0{
  408. let gateway = self.totalDeviceList![indexPath.row] as? GatewayData
  409. self.delegate?.gatewayUpdate(gateway!, segmentIndex: 0)
  410. }
  411. // if self.currentIndex == 0{
  412. // if let devDataList = self.devDataList {
  413. // if indexPath.row < devDataList.count {
  414. // if let delegate = self.delegate{
  415. // let data = self.devDataList![indexPath.row]
  416. // delegate.equipmentHistory(data, segmentIndex: self.currentIndex ?? 0)
  417. // }
  418. // }else{
  419. // if let delegate = self.delegate {
  420. // delegate.gatewayUpdate(segmentIndex: self.currentIndex ?? 5)
  421. // }
  422. // }
  423. // }
  424. // }else if self.currentIndex == 5{
  425. // if let delegate = self.delegate {
  426. // delegate.gatewayUpdate(segmentIndex: self.currentIndex ?? 5)
  427. // }
  428. // }else{
  429. // if let delegate = self.delegate{
  430. // let data = self.devDataList![indexPath.row]
  431. // delegate.equipmentHistory(data, segmentIndex: self.currentIndex ?? 0)
  432. // }
  433. // }
  434. }
  435. historyAction.backgroundColor = UIColor(hexString: "#0A82CF")
  436. let settingAction = UIContextualAction(style: .normal, title: "") { (action, sourceView, completionHandler) in
  437. completionHandler(true)
  438. //处理事件
  439. log.debug("设置")
  440. //设备
  441. if self.searchSchoolAndHotelList?.count ?? 0 > 0 && self.searchSchoolAndHotelList!.count > indexPath.row{
  442. let devData = self.totalDeviceList![indexPath.row] as? DevData
  443. self.delegate?.equipmentSetting(devData!, segmentIndex: 0)
  444. return
  445. }
  446. //网关
  447. if self.searchGatewayList?.count ?? 0 > 0{
  448. let gateway = self.totalDeviceList![indexPath.row] as? GatewayData
  449. self.delegate?.gatewaySetting(gateway!, segmentIndex: 0)
  450. }
  451. // if let delegate = self.delegate{
  452. // let data = self.devDataList![indexPath.row]
  453. // delegate.equipmentSetting(data, segmentIndex: self.currentIndex ?? 0)
  454. // }
  455. }
  456. // #05CFAB
  457. settingAction.backgroundColor = UIColor(hexString: "#573F95")
  458. let actions = UISwipeActionsConfiguration(actions: [settingAction,historyAction,deleteAction])
  459. actions.performsFirstActionWithFullSwipe = false
  460. return actions
  461. }
  462. func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
  463. }
  464. func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
  465. return true
  466. }
  467. func tableView(_ tableView: UITableView, willBeginEditingRowAt indexPath: IndexPath) {
  468. editingIndexPath = indexPath
  469. log.debug("willBeginEditingRowAt")
  470. setNeedsLayout() // 触发layoutSubviews()
  471. }
  472. //取消选中
  473. func tableView(_ tableView: UITableView, didEndEditingRowAt indexPath: IndexPath?) {
  474. editingIndexPath = nil
  475. log.debug("didEndEditingRowAt")
  476. }
  477. func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
  478. log.debug("canMoveRowAt")
  479. return true
  480. }
  481. func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
  482. log.debug("sourceIndexPath - \(sourceIndexPath) --destinationIndexPath \(destinationIndexPath)")
  483. }
  484. func configSwipeButtons() {
  485. // log.debug("重新绘制 ")
  486. //iOS 11 层级 UITableView -> UISwipActionPull
  487. var swipeButtons : [UIView]?
  488. if #available(iOS 11, *) {
  489. swipeButtons = self.tableView.getSwipeButtonView()
  490. }else{
  491. // iOS 8-10: 画UITableView->UITableViewCell->UITableVIewCellDeleteConfirmationView
  492. let tabCell = self.tableView.cellForRow(at: self.editingIndexPath!)
  493. swipeButtons = tabCell?.getSwipeButtonView()
  494. }
  495. // log.debug("子控件 -- \(swipeButtons)")
  496. if swipeButtons?.count == 0 || swipeButtons == nil{
  497. return
  498. }
  499. for i in 0..<(swipeButtons?.count)!{
  500. let button = swipeButtons![i] as! UIButton
  501. if i == 0{
  502. configSwipeButton(button, backgroundImage: UIImage(named: "ic_delete_bg")!)
  503. }else if i == 1{
  504. //第二按钮(历史,更新固件)
  505. let data = self.totalDeviceList![editingIndexPath!.row] as? DevData
  506. if data != nil{
  507. //设备的
  508. configSwipeButton(button, backgroundImage: UIImage(named: "ic_hitory_bg")!)
  509. }else{
  510. //网关的
  511. configSwipeButton(button, backgroundImage: UIImage(named: "ic_update")!)
  512. }
  513. }else{
  514. //第三个(设置)
  515. configSwipeButton(button, backgroundImage: UIImage(named: "ic_setting_bg")!)
  516. }
  517. // let button = swipeButtons![i] as! UIButton
  518. // if i == 0 {
  519. // configSwipeButton(button, backgroundImage: UIImage(named: "ic_delete_bg")!)
  520. // }else if i == 1{
  521. //
  522. // if currentIndex == 0 {
  523. // if self.searchController?.isActive == true {
  524. // if let devDataList = self.fillterResult {
  525. // if self.editingIndexPath!.row < devDataList.count {
  526. // configSwipeButton(button, backgroundImage: UIImage(named: "ic_hitory_bg")!)
  527. // }else{
  528. // configSwipeButton(button, backgroundImage: UIImage(named: "ic_update")!)
  529. // }
  530. // }
  531. // }else{
  532. // if let devDataList = self.devDataList {
  533. // if self.editingIndexPath!.row < devDataList.count {
  534. // configSwipeButton(button, backgroundImage: UIImage(named: "ic_hitory_bg")!)
  535. // }else{
  536. // configSwipeButton(button, backgroundImage: UIImage(named: "ic_update")!)
  537. // }
  538. // }
  539. // }
  540. //
  541. // }else if currentIndex == 5{
  542. // configSwipeButton(button, backgroundImage: UIImage(named: "ic_update")!)
  543. // }else {
  544. // configSwipeButton(button, backgroundImage: UIImage(named: "ic_hitory_bg")!)
  545. // }
  546. // }else{
  547. // configSwipeButton(button, backgroundImage: UIImage(named: "ic_setting_bg")!)
  548. // }
  549. }
  550. }
  551. func configSwipeButton(_ button: UIButton,backgroundImage:UIImage) {
  552. button.layer.cornerRadius = 5
  553. button.layer.masksToBounds = true
  554. button.setBackgroundImage(backgroundImage, for: .normal)
  555. button.setBackgroundImage(backgroundImage, for: .selected)
  556. button.titleLabel?.font = UIFont(name: PingFangSC_Medium, size: 11)
  557. let frame = button.frame
  558. button.frame = CGRect(x: frame.origin.x + 5 , y: frame.origin.y + 10, width: frame.size.width - 10, height: frame.size.height - 20)
  559. }
  560. }
  561. extension IHEquipmentSearchView : UISearchResultsUpdating,UISearchBarDelegate,UISearchControllerDelegate{
  562. func updateSearchResults(for searchController: UISearchController) {
  563. if let searchText = searchController.searchBar.text {
  564. //filterContent(for: searchText)
  565. if searchText != ""{
  566. self.searchText = searchText
  567. delegate?.searchDevice(searchText)
  568. if isRemove == false{
  569. tableViewRefresh()
  570. }
  571. isRemove = true
  572. }
  573. }
  574. }
  575. func didPresentSearchController(_ searchController: UISearchController) {
  576. log.debug("self.tableView.frame - \(self.tableView.frame)")
  577. showCancelButtonWhileEditing = true
  578. }
  579. func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
  580. //删除上下拉刷新01
  581. isRemove = false
  582. tableView.es.removeRefreshHeader()
  583. tableView.es.removeRefreshFooter()
  584. }
  585. func willDismissSearchController(_ searchController: UISearchController) {
  586. log.debug("self.tableView.frame - \(self.tableView.frame)")
  587. showCancelButtonWhileEditing = false
  588. }
  589. }