// // SBTHistoryDataCell.swift // SolarBT // // Created by weclouds on 2019/3/4. // Copyright © 2019 weclouds. All rights reserved. // import UIKit let SBTHistoryDataChartOrFormSelected = "SBTHistoryDataChartOrFormSelected" class SBTHistoryDataCell: UITableViewCell { var weekData : [OneDayData]? { didSet{ if let arr = self.weekData { for i in 0..Void)? var changeViewCallBack:((Bool)->Void)? var shareFormViewCallback: (()->Void)? var shareCallback:((SBTChartsView)->Void)? var horizontalScreenCallback : (()->Void)? lazy var toolBox: UIView = { let toolBox = UIView(frame: CGRect(x: 0, y: 0, width: KSCREENWIDTH, height: 50)) toolBox.backgroundColor = UIColor(hexString: "F6F6F6") return toolBox }() lazy var formBtn: UIButton = { let formBtn = UIButton(type: .custom) formBtn.setTitle("Form".da_localizedStr(), for: .normal) formBtn.titleLabel?.font = UIFont(name: PingFangSC_Medium, size: 11) formBtn.setTitleColor(UIColor(hexString: "FD8B23"), for: .normal ) formBtn.setBackgroundImage(UIImage(named: "form_normal"), for: .normal) formBtn.setTitleColor(UIColor(hexString: "FFFFFF"), for: .selected) formBtn.setBackgroundImage(UIImage(named: "form_selected"), for: .selected) formBtn.addTarget(self, action:#selector(choseFormType) , for: .touchUpInside) return formBtn }() lazy var barChartBtn: UIButton = { let barChartBtn = UIButton(type: .custom) barChartBtn.titleLabel?.font = UIFont(name: PingFangSC_Medium, size: 11) barChartBtn.setTitle("Histogram".da_localizedStr(), for: .normal) barChartBtn.setTitleColor(UIColor(hexString: "FD8B23"), for: .normal ) barChartBtn.setBackgroundImage(UIImage(named: "form_normal"), for: .normal) barChartBtn.setTitleColor(UIColor(hexString: "FFFFFF"), for: .selected) barChartBtn.setBackgroundImage(UIImage(named: "form_selected"), for: .selected) barChartBtn.addTarget(self, action:#selector(choseFormType) , for: .touchUpInside) return barChartBtn }() lazy var scaleBtn: UIButton = { let scaleBtn = UIButton(type: .custom) scaleBtn.setBackgroundImage(UIImage(named: "scale"), for: .normal) scaleBtn.layer.masksToBounds = true scaleBtn.layer.cornerRadius = 2 scaleBtn.addTarget(self, action: #selector(scaleAction), for: .touchUpInside) return scaleBtn }() lazy var shareBtn: UIButton = { let shareBtn = UIButton(type: .custom) shareBtn.setBackgroundImage(UIImage(named: "share"), for: .normal) shareBtn.layer.masksToBounds = true shareBtn.layer.cornerRadius = 2 shareBtn.addTarget(self, action: #selector(shareAction), for: .touchUpInside) return shareBtn }() lazy var clearDataBtn: UIButton = { let clearDataBtn = UIButton(type: .custom) clearDataBtn.setBackgroundImage(UIImage(named: "22"), for: .normal) clearDataBtn.layer.masksToBounds = true clearDataBtn.layer.cornerRadius = 2 clearDataBtn.addTarget(self, action: #selector(clearHistoryData), for: .touchUpInside) return clearDataBtn }() lazy var formView: SheetView = { let formView = SheetView() formView.delegate = self formView.dataSource = self formView.titleRowHeight = 63 formView.titleColWidth = 143 formView.backgroundColor = UIColor.white return formView }() lazy var chartsView: SBTChartsView = { let chartsView = SBTChartsView() return chartsView }() func fillCellData(_ weekData : [OneDayData]){ self.dataArr?.removeAll() chartsView.fillChartsData(weekData) for i in 0.., with event: UIEvent?) { } func createUI() { //toolBox 添加到scrollview上 self.addSubview(self.toolBox) //添加按钮到toolBox上 toolBox.addSubview(self.formBtn) toolBox.addSubview(self.barChartBtn) toolBox.addSubview(self.clearDataBtn) toolBox.addSubview(scaleBtn) toolBox.addSubview(shareBtn) formBtn.isSelected = true ///选择表格按钮 scaleBtn.isHidden = true /// 放大按钮 formView.isHidden = false /// 表格view chartsView.isHidden = true //布局 formBtn.snp.makeConstraints { (make) in make.left.equalToSuperview().offset(25) make.top.equalToSuperview().offset(10) make.width.equalTo(100) make.height.equalTo(30) } barChartBtn.snp.makeConstraints { (make) in make.left.equalTo(formBtn.snp.right).offset(8) make.top.equalTo(formBtn.snp.top) make.width.equalTo(100) make.height.equalTo(30) } shareBtn.snp.makeConstraints { (make) in make.left.equalTo(barChartBtn.snp.right).offset(8) make.top.equalToSuperview().offset(10) make.width.height.equalTo(30) } clearDataBtn.snp.makeConstraints { (make) in make.left.equalTo(shareBtn.snp.right).offset(8) make.top.equalToSuperview().offset(10) make.width.height.equalTo(30) } scaleBtn.snp.makeConstraints { (make) in make.left.equalTo(clearDataBtn.snp.right).offset(8) make.top.equalToSuperview().offset(10) make.width.height.equalTo(30) } //添加表格视图 self.addSubview(formView) self.addSubview(chartsView) formView.snp.makeConstraints { (make) in make.left.right.equalToSuperview() make.top.equalTo(toolBox.snp.bottom) make.height.equalTo(510) } chartsView.snp.makeConstraints { (make) in make.left.right.equalToSuperview() make.top.equalTo(toolBox.snp.bottom) make.height.equalTo(356) } } @objc func choseFormType(_ sender:UIButton) { log.debug("点击了呀 --- -") formBtn.isSelected = false barChartBtn.isSelected = false sender.isSelected = true //处理事件 if formBtn.isSelected { log.debug("表格") scaleBtn.isHidden = true //shareBtn.isHidden = true formView.isHidden = false chartsView.isHidden = true changeViewCallBack!(false) //记录当前选择 UserDefaults.standard.set("0", forKey: SBTHistoryDataChartOrFormSelected) UserDefaults.standard.synchronize() log.debug(" ++\(chartsView) ---- \(formView)") } if barChartBtn.isSelected { log.debug("柱状图") scaleBtn.isHidden = false // shareBtn.isHidden = false formView.isHidden = true chartsView.isHidden = false //记录当前选择 UserDefaults.standard.set("1", forKey: SBTHistoryDataChartOrFormSelected) UserDefaults.standard.synchronize() } } //清除历史数据 @objc func clearHistoryData() { log.debug("i清除历史数据") self.clearHistoryDataCallBack!() } //分享事件 @objc func shareAction() { log.debug("分享") if self.formBtn.isSelected { self.shareFormViewCallback!() } if self.barChartBtn.isSelected == true { self.shareCallback!(chartsView) } } //横屏事件 @objc func scaleAction() { log.debug("横屏") self.horizontalScreenCallback!() } } extension SBTHistoryDataCell: SheetViewDelegate,SheetViewDataSource{ func sheetView(_ sheetView: SheetView!, heightForRowAt indexPath: IndexPath!) -> CGFloat { return 44.5 } func sheetView(_ sheetView: SheetView!, widthForColAt indexPath: IndexPath!) -> CGFloat { return 55 } func sheetView(_ sheetView: SheetView!, didSelectItemAtIndexRow indexRow: IndexPath!, indexCol: IndexPath!) { log.debug("点击了 row\(indexRow.row),col\(indexCol.row)") } func sheetView(_ sheetView: SheetView!, numberOfRowsInSection section: Int) -> Int { return 10 } func sheetView(_ sheetView: SheetView!, numberOfColsInSection section: Int) -> Int { return 8 } func sheetView(_ sheetView: SheetView!, cellForContentItemAtIndexRow indexRow: IndexPath!, indexCol: IndexPath!) -> String! { return self.dataArr![indexCol.row][indexRow.row] } func sheetView(_ sheetView: SheetView!, cellForLeftColAt indexPath: IndexPath!) -> String! { let rowArrs = ["Minimum_battery_voltage_of_the_day_(V)".da_localizedStr(), "Maximum_battery_voltage_of_the_day_(V)".da_localizedStr(), "Maximum_charge_current_of_the_day_(A)".da_localizedStr(), "Maximum_charge_power_of_the_day_(W)".da_localizedStr(), "Charge_amp_hours_of_the_day_(Ah)".da_localizedStr(), "Maximum_discharge_current_of_the_day_(A)".da_localizedStr(), "Maximum_discharge_power_of_the_day_(W)".da_localizedStr(), "Discharge_amp_hours_of_the_day_(Ah)".da_localizedStr(), "Power_generation_of_the_day_(kWh)".da_localizedStr(), "Discharge_amount_of_the_day_(kWh)".da_localizedStr()] return rowArrs[indexPath.row] } func sheetView(_ sheetView: SheetView!, cellForTopRowAt indexPath: IndexPath!) -> String! { return dayArr![indexPath.row] } func sheetView(_ sheetView: SheetView!, cellWithColorAtIndexRow indexRow: IndexPath!) -> Bool { return indexRow.row % 2 == 0 ? true : false } }