SBTParamSet_ChargerCell.swift 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  1. //
  2. // SBTParamSet_ChargerCell.swift
  3. // SolarBT
  4. //
  5. // Created by weclouds on 2019/3/14.
  6. // Copyright © 2019 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. class SBTextfield: UITextField {
  10. }
  11. //扩展NSRange,添加转换成Range的方法
  12. extension NSRange {
  13. func toRange(string: String) -> Range<String.Index> {
  14. let startIndex = string.index(string.startIndex, offsetBy: self.location)
  15. let endIndex = string.index(startIndex, offsetBy: self.length)
  16. return startIndex..<endIndex
  17. }
  18. }
  19. class SBTParamSetSwitch_Item: UICollectionViewCell {
  20. var sb_selected : Bool? = false {
  21. didSet{
  22. }
  23. }
  24. var differenceUI : Int? = 0{
  25. didSet{
  26. if let didfference = self.differenceUI {
  27. if didfference == 1{
  28. self.contentView.backgroundColor = UIColor(hexString: "#F1F1F1")
  29. // self.contentView.backgroundColor = UIColor.gray
  30. self.isUserInteractionEnabled = false
  31. }else{
  32. self.contentView.backgroundColor = UIColor(hexString: "#FFFFFF")
  33. //self.backgroundColor = UIColor.green
  34. self.isUserInteractionEnabled = true
  35. }
  36. }
  37. }
  38. }
  39. var switchCallback :((Bool)->Void)?
  40. var isOn :Bool?{
  41. didSet{
  42. if let isOn = self.isOn {
  43. if isOn == true {
  44. onButton.isSelected = true
  45. offButton.isSelected = false
  46. }else{
  47. onButton.isSelected = false
  48. offButton.isSelected = true
  49. }
  50. }
  51. }
  52. }
  53. var title : String?{
  54. didSet{
  55. titleLabel.text = title
  56. }
  57. }
  58. var canEdit : Bool? = false{
  59. didSet{
  60. if let canEdit = self.canEdit {
  61. onButton.isUserInteractionEnabled = canEdit
  62. offButton.isUserInteractionEnabled = canEdit
  63. }
  64. }
  65. }
  66. lazy var titleLabel: UILabel = {
  67. let titleLabel = UILabel()
  68. titleLabel.textColor = UIColor(hexString: "222222")
  69. titleLabel.numberOfLines = 0
  70. titleLabel.font = UIFont(name: PingFangSC_Regular, size: 11)
  71. return titleLabel
  72. }()
  73. lazy var onButton : UIButton = {
  74. let btn = UIButton()
  75. btn.titleLabel?.font = UIFont(name: PingFangSC_Semibold, size: 16)
  76. btn.setTitleColor(UIColor(hexString: "#B8B8B8"), for: .normal)
  77. btn.setTitleColor(UIColor(hexString: "#222222"), for: .selected)
  78. btn.addTarget(self, action: #selector(buttonClick), for: .touchUpInside)
  79. btn.setTitle("ON", for: .normal)
  80. return btn
  81. }()
  82. lazy var offButton : UIButton = {
  83. let btn = UIButton()
  84. btn.titleLabel?.font = UIFont(name: PingFangSC_Semibold, size: 16)
  85. btn.setTitleColor(UIColor(hexString: "#B8B8B8"), for: .normal)
  86. btn.setTitleColor(UIColor(hexString: "#222222"), for: .selected)
  87. btn.addTarget(self, action: #selector(buttonClick), for: .touchUpInside)
  88. btn.setTitle("OFF", for: .normal)
  89. return btn
  90. }()
  91. override init(frame: CGRect) {
  92. super.init(frame: frame)
  93. createUI()
  94. self.layer.borderColor = UIColor(hexString: "#D2D2D2")?.cgColor
  95. self.layer.borderWidth = 1
  96. self.layer.cornerRadius = 5
  97. self.layer.masksToBounds = true
  98. }
  99. required init?(coder aDecoder: NSCoder) {
  100. fatalError("init(coder:) has not been implemented")
  101. }
  102. @objc func buttonClick(_ button: UIButton) {
  103. onButton.isSelected = false
  104. offButton.isSelected = false
  105. button.isSelected = true
  106. if self.canEdit == true {
  107. if onButton.isSelected == true{
  108. self.switchCallback!(true)
  109. }
  110. if offButton.isSelected == true{
  111. self.switchCallback!(false)
  112. }
  113. }
  114. }
  115. func createUI() {
  116. addSubview(titleLabel)
  117. addSubview(onButton)
  118. addSubview(offButton)
  119. titleLabel.snp.makeConstraints { (make) in
  120. make.top.equalToSuperview().offset(20)
  121. make.left.equalToSuperview().offset(15)
  122. make.right.equalToSuperview().offset(-15)
  123. }
  124. let line = UIView()
  125. line.backgroundColor = UIColor(hexString: "#CECECE")
  126. addSubview(line)
  127. line.snp.makeConstraints { (make) in
  128. make.centerX.equalToSuperview()
  129. make.bottom.equalToSuperview().offset(-18)
  130. make.width.equalTo(1)
  131. make.height.equalTo(19)
  132. }
  133. onButton.snp.makeConstraints { (make) in
  134. make.top.equalTo(titleLabel.snp.bottom).offset(8)
  135. make.bottom.equalToSuperview().offset(-8)
  136. make.left.equalToSuperview()
  137. make.right.equalTo(line.snp.left)
  138. }
  139. offButton.snp.makeConstraints { (make) in
  140. make.top.equalTo(titleLabel.snp.bottom).offset(8)
  141. make.bottom.equalToSuperview().offset(-8)
  142. make.right.equalToSuperview()
  143. make.left.equalTo(line.snp.right)
  144. }
  145. }
  146. }
  147. class SBTParamSet_balance_Item: UICollectionViewCell {
  148. var sb_selected : Bool? = false {
  149. didSet{
  150. // if let isselected = self.sb_selected {
  151. // if isselected == true{
  152. // //#29B009
  153. // self.layer.borderColor = UIColor(hexString: "#29B009")?.cgColor
  154. // }else{
  155. // self.layer.borderColor = UIColor(hexString: "#D2D2D2")?.cgColor
  156. // }
  157. // }
  158. }
  159. }
  160. var differenceUI : Int? = 0{
  161. didSet{
  162. if let didfference = self.differenceUI {
  163. if didfference == 1{
  164. self.contentView.backgroundColor = UIColor(hexString: "#F1F1F1")
  165. self.isUserInteractionEnabled = false
  166. }else{
  167. self.contentView.backgroundColor = UIColor(hexString: "#FFFFFF")
  168. self.isUserInteractionEnabled = true
  169. }
  170. }
  171. }
  172. }
  173. var canEdit : Bool = false {
  174. didSet{
  175. if self.canEdit == true {
  176. self.subTitleLabel.textColor = UIColor(hexString: "BBBBBB")
  177. // self.subTitleTextfield.isHidden = false
  178. // self.subTitleTextfield.placeholder = subTitle
  179. // self.subTitleLabel.isHidden = true
  180. }else{
  181. self.subTitleLabel.textColor = UIColor(hexString: "222222")
  182. // self.subTitleTextfield.isHidden = true
  183. // self.subTitleLabel.isHidden = false
  184. // self.isTapGuesture = false
  185. }
  186. }
  187. }
  188. var balanceTypeCallback:((Int)->Void)?
  189. var balanceType : Int? = -1{
  190. didSet{
  191. if self.balanceType != -1 {
  192. self.balanceTypeCallback!(self.balanceType!)
  193. }
  194. }
  195. }
  196. var title : String?{
  197. didSet{
  198. titleLabel.text = title
  199. }
  200. }
  201. var subTitle : String?{
  202. didSet{
  203. self.subTitleLabel.text = subTitle
  204. }
  205. }
  206. lazy var titleLabel: UILabel = {
  207. let titleLabel = UILabel()
  208. titleLabel.textColor = UIColor(hexString: "222222")
  209. titleLabel.numberOfLines = 0
  210. titleLabel.font = UIFont(name: PingFangSC_Regular, size: 11)
  211. return titleLabel
  212. }()
  213. lazy var subTitleLabel: UILabel = {
  214. let subTitleLabel = UILabel()
  215. subTitleLabel.textColor = UIColor(hexString: "222222")
  216. subTitleLabel.font = UIFont(name: PingFangSC_Semibold, size: 16)
  217. subTitleLabel.isHidden = false
  218. return subTitleLabel
  219. }()
  220. override init(frame: CGRect) {
  221. super.init(frame: frame)
  222. createUI()
  223. self.layer.borderColor = UIColor(hexString: "#D2D2D2")?.cgColor
  224. self.layer.borderWidth = 1
  225. self.layer.cornerRadius = 5
  226. self.layer.masksToBounds = true
  227. }
  228. required init?(coder aDecoder: NSCoder) {
  229. fatalError("init(coder:) has not been implemented")
  230. }
  231. func createUI() {
  232. addSubview(titleLabel)
  233. addSubview(subTitleLabel)
  234. titleLabel.snp.makeConstraints { (make) in
  235. make.top.equalToSuperview().offset(20)
  236. make.left.equalToSuperview().offset(15)
  237. make.right.equalToSuperview().offset(-15)
  238. }
  239. subTitleLabel.snp.makeConstraints { (make) in
  240. make.left.equalTo(titleLabel.snp.left)
  241. make.right.equalTo(titleLabel.snp.right)
  242. make.top.equalTo(titleLabel.snp.bottom).offset(8)
  243. }
  244. self.subTitleLabel.isUserInteractionEnabled = true
  245. let tap = UITapGestureRecognizer(target: self, action: #selector(tapAction))
  246. self.subTitleLabel.addGestureRecognizer(tap)
  247. }
  248. func sb_becameFirstResonder() {
  249. tapAction()
  250. }
  251. @objc func tapAction() {
  252. log.debug("手动均衡")
  253. let balances = ["Prohibited".da_localizedStr(),"Enable".da_localizedStr()]
  254. let balancePick = THScrollChooseView(question: balances, withDefaultDesc:"Prohibited".da_localizedStr())
  255. balancePick!.show()
  256. balancePick?.confirmBlock = {[weak self](selectedIndex) in
  257. log.debug(balances[selectedIndex])
  258. self?.subTitleLabel.text = balances[selectedIndex]
  259. self?.subTitleLabel.textColor = UIColor(hexString: "222222")
  260. self?.balanceType = selectedIndex
  261. }
  262. }
  263. }
  264. class SBTParamSet_Item: UICollectionViewCell , UITextFieldDelegate{
  265. var beginEditingCallback:(()->Void)?
  266. var ChangeCharactersCallback:((String?)->Void)?
  267. var sb_selected : Bool? = false {
  268. didSet{
  269. // if let isselected = self.sb_selected {
  270. // let view = subTitleTextfield.next as! SBTParamSet_Item
  271. // if isselected == true{
  272. //
  273. // //#29B009
  274. // view.layer.borderColor = UIColor(hexString: "#29B009")?.cgColor
  275. // }else{
  276. // view.layer.borderColor = UIColor(hexString: "#D2D2D2")?.cgColor
  277. // }
  278. // }
  279. }
  280. }
  281. //
  282. @objc func didselectedTexfield() {
  283. log.debug("测试 UITextField 的点击 ------\(subTitleTextfield.isEditing)")
  284. }
  285. var differenceUI : Int? = 0{
  286. didSet{
  287. if let didfference = self.differenceUI {
  288. if didfference == 1{
  289. self.contentView.backgroundColor = UIColor(hexString: "#F1F1F1")
  290. // self.contentView.backgroundColor = UIColor.gray
  291. self.isUserInteractionEnabled = false
  292. if self.canEdit == true {
  293. self.subTitleTextfield.isEnabled = false
  294. // self.subTitleTextfield.resignFirstResponder()
  295. }else{
  296. self.subTitleTextfield.isEnabled = true
  297. }
  298. }else{
  299. self.contentView.backgroundColor = UIColor(hexString: "#FFFFFF")
  300. self.isUserInteractionEnabled = true
  301. }
  302. }
  303. }
  304. }
  305. var resultCallback:((String,UITextField)->Void)?
  306. var isTapGuesture: Bool = false{
  307. didSet{
  308. }
  309. }
  310. var itemKeyboardType: UIKeyboardType? = .default{
  311. didSet {
  312. self.subTitleTextfield.keyboardType = self.itemKeyboardType!
  313. }
  314. }
  315. var keyboartypeISFloat: Bool? = false{
  316. didSet{
  317. if let keyboartypeISFloat = self.keyboartypeISFloat {
  318. if keyboartypeISFloat == true{
  319. // self.subTitleTextfield.keyboardType = .decimalPad
  320. }else{
  321. // self.subTitleTextfield.keyboardType = .numberPad
  322. }
  323. }
  324. }
  325. }
  326. var canEdit : Bool = false {
  327. didSet{
  328. if self.canEdit == true {
  329. self.subTitleTextfield.isHidden = false
  330. self.subTitleTextfield.placeholder = subTitle
  331. self.subTitleLabel.isHidden = true
  332. }else{
  333. self.subTitleTextfield.isHidden = true
  334. self.subTitleLabel.isHidden = false
  335. // self.isTapGuesture = false
  336. }
  337. }
  338. }
  339. var title : String?{
  340. didSet{
  341. titleLabel.text = title
  342. }
  343. }
  344. var subTitle : String?{
  345. didSet{
  346. self.subTitleLabel.text = subTitle
  347. }
  348. }
  349. lazy var titleLabel: UILabel = {
  350. let titleLabel = UILabel()
  351. titleLabel.textColor = UIColor(hexString: "222222")
  352. titleLabel.numberOfLines = 0
  353. titleLabel.font = UIFont(name: PingFangSC_Regular, size: 11)
  354. return titleLabel
  355. }()
  356. lazy var subTitleLabel: UILabel = {
  357. let subTitleLabel = UILabel()
  358. subTitleLabel.textColor = UIColor(hexString: "222222")
  359. subTitleLabel.font = UIFont(name: PingFangSC_Semibold, size: 16)
  360. subTitleLabel.isHidden = false
  361. return subTitleLabel
  362. }()
  363. lazy var subTitleTextfield: UITextField = {
  364. let subTitle = UITextField()
  365. subTitle.textColor = UIColor(hexString: "222222")
  366. // subTitle.backgroundColor = UIColor.blue
  367. subTitle.isHidden = true
  368. subTitle.addDoneOnKeyboardWithTarget(self, action: #selector(self.doneAction(_:)), shouldShowPlaceholder: true)
  369. subTitle.keyboardToolbar.doneBarButton.setTitleTextAttributes([NSAttributedString.Key.foregroundColor : UIColor(hexString: "222222") as Any], for: .normal)
  370. subTitle.font = UIFont(name: PingFangSC_Semibold, size: 16)
  371. return subTitle
  372. }()
  373. @objc func doneAction(_ sender : UITextField!) {
  374. self.endEditing(true)
  375. }
  376. override init(frame: CGRect) {
  377. super.init(frame: frame)
  378. createUI()
  379. self.layer.borderColor = UIColor(hexString: "#D2D2D2")?.cgColor
  380. self.layer.borderWidth = 1
  381. self.layer.cornerRadius = 5
  382. self.layer.masksToBounds = true
  383. self.subTitleTextfield.delegate = self
  384. }
  385. required init?(coder aDecoder: NSCoder) {
  386. fatalError("init(coder:) has not been implemented")
  387. }
  388. //输入完成
  389. func textFieldDidEndEditing(_ textField: UITextField) {
  390. if textField.text != ""{
  391. let textFloat = Float(textField.text!)
  392. if (textFloat == nil){
  393. makeToast("please_enter_number".da_localizedStr())
  394. textField.text = ""
  395. }else{
  396. self.resultCallback!(textField.text!,textField)
  397. // if let ChangeCharactersCallback = self.ChangeCharactersCallback {
  398. // ChangeCharactersCallback(textField.text)
  399. // }
  400. }
  401. }
  402. }
  403. func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
  404. // if beginEditingCallback != nil{
  405. // self.beginEditingCallback!()
  406. // }
  407. // self.sb_selected = true
  408. return true
  409. }
  410. func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
  411. // let currentText = textField.text ?? ""
  412. // let newText = currentText.replacingCharacters(in:
  413. // range.toRange(string: currentText), with: string)
  414. if self.keyboartypeISFloat == true {
  415. let toString = (textField.text! as NSString).replacingCharacters(in: range, with: string)
  416. let expression = "^[0-9]*((\\\\.|,)[0-9]{0,1})?$"// 正则表达式 保留一位小数
  417. let regex = try! NSRegularExpression(pattern: expression, options: NSRegularExpression.Options.allowCommentsAndWhitespace)
  418. let numberOfMatches = regex.numberOfMatches(in: toString, options:NSRegularExpression.MatchingOptions.reportProgress, range: NSMakeRange(0, (toString as NSString).length))
  419. return numberOfMatches != 0
  420. }
  421. return true
  422. }
  423. func createUI() {
  424. addSubview(titleLabel)
  425. addSubview(subTitleLabel)
  426. addSubview(subTitleTextfield)
  427. titleLabel.snp.makeConstraints { (make) in
  428. make.top.equalToSuperview().offset(20)
  429. make.left.equalToSuperview().offset(15)
  430. make.right.equalToSuperview().offset(-15)
  431. }
  432. subTitleLabel.snp.makeConstraints { (make) in
  433. make.left.equalTo(titleLabel.snp.left)
  434. make.top.equalTo(titleLabel.snp.bottom).offset(8)
  435. }
  436. subTitleTextfield.snp.makeConstraints { (make) in
  437. make.left.equalTo(titleLabel.snp.left)
  438. make.top.equalTo(titleLabel.snp.bottom).offset(8)
  439. make.right.equalToSuperview().offset(-15)
  440. make.bottom.equalToSuperview().offset(-8)
  441. }
  442. }
  443. }
  444. class SBTParamSet_ChargerCell: UITableViewCell,UICollectionViewDelegate,UICollectionViewDataSource {
  445. var isOld: Bool?
  446. //放大倍数
  447. var Multiple : Float? // 默认为1倍
  448. var difeffrentUIArr : [Int]? = [Int]()
  449. var defaultData : [Double]? = [Double]()
  450. var CellBatteryType :BatteryType? = .USER{
  451. didSet{
  452. if self.isOld == true {
  453. if let batteryType = self.CellBatteryType {
  454. switch batteryType {
  455. case .USER:
  456. self.difeffrentUIArr = [1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1]
  457. //self.defaultData = [16.0,15.5,14.4,13.8,13.2,120,-3]
  458. case .SLD:
  459. self.difeffrentUIArr = [1,1,1,1, 1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1]
  460. case .FLD:
  461. self.difeffrentUIArr = [1,1,1,1, 1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1]
  462. case .GEL:
  463. self.difeffrentUIArr = [1,1,1,1, 1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1]
  464. case .LI:
  465. self.difeffrentUIArr = [1,1,1,1, 1,1,0,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1]
  466. }
  467. }
  468. }else{
  469. if let batteryType = self.CellBatteryType {
  470. switch batteryType {
  471. case .USER:
  472. self.difeffrentUIArr = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
  473. //self.defaultData = [16.0,15.5,14.4,13.8,13.2,120,-3]
  474. case .SLD:
  475. self.difeffrentUIArr = [0,0,0,0, 1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0,0]
  476. case .FLD:
  477. self.difeffrentUIArr = [0,0,0,0, 1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0,0]
  478. case .GEL:
  479. self.difeffrentUIArr = [0,0,0,0, 1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0,0]
  480. case .LI:
  481. self.difeffrentUIArr = [0,0,0,0, 1,1,0,1,1,1,1,1,1,1,1,0,1,0,1,1,0,0]
  482. }
  483. }
  484. }
  485. }
  486. }
  487. var dataSources:[String]? = [String](){
  488. didSet{
  489. self.collectionView?.reloadData()
  490. }
  491. }
  492. var a :String?{
  493. didSet{
  494. log.debug("====================传过来\(a!)")
  495. }
  496. }
  497. func getData(_ dataSource:[String]?) {
  498. }
  499. var itemdidSelectedCallBack:((IndexPath)->Void)?
  500. var collectionView:UICollectionView?
  501. var canEdit: Bool? = false{
  502. didSet{
  503. }
  504. }
  505. var itemTitles = [String]()
  506. // override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
  507. // super.init(style: style, reuseIdentifier: reuseIdentifier)
  508. // // dataSources = [String]()
  509. // createUI()
  510. // }
  511. //
  512. // required init?(coder aDecoder: NSCoder) {
  513. // fatalError("init(coder:) has not been implemented")
  514. // }
  515. override func awakeFromNib() {
  516. super.awakeFromNib()
  517. NotificationCenter.default.addObserver(self, selector: #selector(notifionCationSetBatteryType), name: NSNotification.Name(rawValue: kNotifionCationSetBatteryType), object: nil)
  518. let def = UserDefaults.standard
  519. let istemp = def.value(forKey: TEMPISCENTIGRADE) as? String
  520. var Upper_limit_of_charge_temperature = "Upper_limit_of_charge_temperature".da_localizedStr() + "(℃)"
  521. var Lower_limit_of_charge_temperature = "Lower_limit_of_charge_temperature".da_localizedStr() + "(℃)"
  522. var Upper_limit_of_discharge_temperature = "Upper_limit_of_discharge_temperature".da_localizedStr() + "(℃)"
  523. var Lower_limit_of_discharge_temperature = "Lower_limit_of_discharge_temperature".da_localizedStr() + "(℃)"
  524. if istemp == "0"{
  525. Upper_limit_of_charge_temperature = "Upper_limit_of_charge_temperature".da_localizedStr() + "(℉)"
  526. Lower_limit_of_charge_temperature = "Lower_limit_of_charge_temperature".da_localizedStr() + "(℉)"
  527. Upper_limit_of_discharge_temperature = "Upper_limit_of_discharge_temperature".da_localizedStr() + "(℉)"
  528. Lower_limit_of_discharge_temperature = "Lower_limit_of_discharge_temperature".da_localizedStr() + "(℉)"
  529. }else if istemp == "1"{
  530. Upper_limit_of_charge_temperature = "Upper_limit_of_charge_temperature".da_localizedStr() + "(℃)"
  531. Lower_limit_of_charge_temperature = "Lower_limit_of_charge_temperature".da_localizedStr() + "(℃)"
  532. Upper_limit_of_discharge_temperature = "Upper_limit_of_discharge_temperature".da_localizedStr() + "(℃)"
  533. Lower_limit_of_discharge_temperature = "Lower_limit_of_discharge_temperature".da_localizedStr() + "(℃)"
  534. }
  535. itemTitles = ["Maximum_charge_current(A)".da_localizedStr(),
  536. "Charge_on/off".da_localizedStr(),
  537. Upper_limit_of_charge_temperature,
  538. Lower_limit_of_charge_temperature,
  539. "Overvoltage".da_localizedStr(),
  540. "Limited_charge_voltage".da_localizedStr(),
  541. "Boost_charge_voltage".da_localizedStr(),
  542. "Floating_charge_voltage".da_localizedStr(),
  543. "Boost_charge_return_voltage".da_localizedStr(),
  544. "Boost_charge_time".da_localizedStr(),
  545. "Temperature_compensation_coefficient".da_localizedStr(),
  546. "Equalizing_charge_voltage".da_localizedStr(),
  547. "Equalizing_charge_time".da_localizedStr(),
  548. "Equalizing_charge_interval".da_localizedStr(),
  549. "Manual_equalizing".da_localizedStr(),
  550. "Over_discharge_return_voltage".da_localizedStr(),
  551. "Undervoltage_warning_voltage".da_localizedStr(),
  552. "Over_discharge_voltage".da_localizedStr(),
  553. "Discharge_cutoff_voltage".da_localizedStr(),
  554. "Over_discharge_delay_time".da_localizedStr(),
  555. Upper_limit_of_discharge_temperature,
  556. Lower_limit_of_discharge_temperature]
  557. createUI()
  558. }
  559. override func setSelected(_ selected: Bool, animated: Bool) {
  560. super.setSelected(selected, animated: animated)
  561. // Configure the view for the selected state
  562. }
  563. // 01 10ve01d0005a7cc
  564. //设置区别颜色
  565. @objc func notifionCationSetBatteryType() {
  566. let batteryType = AppShare.batteryType
  567. log.debug("电池类型啊啊啊啊啊啊啊啊啊 -- \(batteryType! )")
  568. self.CellBatteryType = batteryType
  569. self.collectionView?.reloadData()
  570. }
  571. func createUI() {
  572. let layout = UICollectionViewFlowLayout()
  573. let itemWidth = (KSCREENWIDTH - 25 * 3 ) / 2
  574. layout.itemSize = CGSize(width:itemWidth , height: 89)
  575. layout.minimumLineSpacing = 12.5 //列间距
  576. layout.minimumInteritemSpacing = 10 //行间距
  577. layout.scrollDirection = .vertical
  578. collectionView = UICollectionView(frame: CGRect(x: 25, y: 15, width: KSCREENWIDTH - 50, height: 110 * 10 + 15 ), collectionViewLayout: layout)
  579. collectionView?.backgroundColor = UIColor.white
  580. collectionView?.showsVerticalScrollIndicator = false
  581. collectionView?.showsHorizontalScrollIndicator = false
  582. collectionView?.isScrollEnabled = false
  583. collectionView?.dataSource = self
  584. collectionView?.delegate = self
  585. collectionView?.bounces = false
  586. for i in 0..<22 {
  587. if i != 1 {
  588. let identifier = "cell" + "\(i)"
  589. collectionView?.register(SBTParamSet_Item.self, forCellWithReuseIdentifier: identifier)
  590. }
  591. }
  592. collectionView?.register(SBTParamSetSwitch_Item.self, forCellWithReuseIdentifier: "cell1")
  593. addSubview(collectionView!)
  594. }
  595. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  596. return self.dataSources!.count
  597. }
  598. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  599. //
  600. // log.debug(difeffrentUIArr)
  601. if indexPath.row == 1 {
  602. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell1", for: indexPath) as! SBTParamSetSwitch_Item
  603. cell.title = itemTitles[indexPath.row]
  604. cell.differenceUI = self.difeffrentUIArr![indexPath.row]
  605. // log.debug("UI显示不一样-----\(self.difeffrentUIArr![indexPath.row])")
  606. let cmd = dataSources![indexPath.row]
  607. if cmd == "开" || cmd == "On"{
  608. cell.isOn = true
  609. }else if cmd == "关" || cmd == "Off"{
  610. cell.isOn = false
  611. }
  612. cell.canEdit = canEdit
  613. cell.backgroundColor = UIColor.white
  614. return cell
  615. }
  616. else{
  617. let identifier = "cell" + "\(indexPath.row)"
  618. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath) as! SBTParamSet_Item
  619. cell.title = itemTitles[indexPath.row]
  620. cell.differenceUI = self.difeffrentUIArr![indexPath.row]
  621. cell.subTitle = dataSources![indexPath.row]
  622. cell.backgroundColor = UIColor.white
  623. return cell
  624. }
  625. }
  626. func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  627. itemdidSelectedCallBack!(indexPath)
  628. }
  629. }