123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- //
- // IHCurtainView.swift
- // Inhealth
- //
- // Created by weclouds on 2020/7/25.
- // Copyright © 2020 weclouds. All rights reserved.
- //
- import UIKit
- import PKHUD
- protocol CurtainViewDelegate : NSObjectProtocol{
- //设置窗帘
- func setCurtain(dataLists : [[String : String]])
- }
- class IHCurtainView: UIView {
-
- //var dataSource = [["Full-on mode" : "On"],["Full-off mode" : "Off"],["Attend class mode" : "On"],["Finish class mode" : "Off"], ["Noon break mode" : "Off"],["Self-study mode" : "On"],["Blackboard mode" : "On"],["Projection mode" : "Off"]]
-
-
- var tableView : UITableView?
- weak var delegate : CurtainViewDelegate?
- private var dataSources = [[String : String]]()
- var curtainModelData : CurtainModel?{
- didSet{
-
- let data1 = ["全开模式" : curtainModelData?.open_status == "0" ? "关" : "开"]
- let data2 = ["全关模式" : curtainModelData?.close_status == "0" ? "关" : "开"]
- let data3 = ["上课模式" : curtainModelData?.att_class_status == "0" ? "关" : "开"]
- let data4 = ["下课模式" : curtainModelData?.fin_class_status == "0" ? "关" : "开"]
- let data5 = ["午休模式" : curtainModelData?.break_status == "0" ? "关" : "开"]
- let data6 = ["自习模式" : curtainModelData?.self_stu_status == "0" ? "关" : "开"]
- let data7 = ["板书模式" : curtainModelData?.blackboard_status == "0" ? "关" : "开"]
- let data8 = ["投影模式" : curtainModelData?.shadow_status == "0" ? "关" : "开"]
-
- dataSources.append(data1)
- dataSources.append(data2)
- dataSources.append(data3)
- dataSources.append(data4)
- dataSources.append(data5)
- dataSources.append(data6)
- dataSources.append(data7)
- dataSources.append(data8)
-
- self.tableView?.reloadData()
- }
- }
- override init(frame: CGRect) {
- super.init(frame: frame)
-
- self.createUI()
-
- NotificationCenter.default.addObserver(self, selector: #selector(acceptCurtainChoseData), name: NSNotification.Name(KNotificationCurtain), object: nil)
- }
- @objc func acceptCurtainChoseData(noti : Notification){
- let dic = noti.userInfo
- let indexPath = dic?["indexPath"] as! IndexPath
- let choseValue = dic?["choseValue"] as! String
-
- var data = self.dataSources[indexPath.row]
- let key = data.keys.first!
- data.updateValue(choseValue, forKey: key)
-
- //更新数组
- self.dataSources[indexPath.row] = data
- self.tableView?.reloadRows(at: [indexPath], with: .automatic)
-
- }
-
- deinit {
- NotificationCenter.default.removeObserver(self)
- }
-
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- private func createUI() {
-
- if KNavBarHeight == 64 {
- self.tableView = UITableView.init(frame: CGRect.init(x: 0, y: 0, width: KSCREENWIDTH, height: KSCREENHEIGHT - KNavBarHeight - 70), style: .plain)
- }else {
- self.tableView = UITableView.init(frame: CGRect.init(x: 0, y: 0, width: KSCREENWIDTH, height: KSCREENHEIGHT - KNavBarHeight - 34 - 70), style: .plain)
- }
-
- tableView?.dataSource = self
- tableView?.delegate = self
- tableView?.separatorStyle = .none
- tableView?.rowHeight = 120.0
- //self.tableView = tableView
- self.addSubview(tableView!)
-
- let between : CGFloat = 30.0
- let saveBtn = UIButton.init(frame: CGRect.init(x: between, y: tableView!.size.height + 20.0, width: KSCREENWIDTH - between * 2, height: 40))
- saveBtn.setTitle("保存", for: .normal)
- saveBtn.backgroundColor = UIColor.init(hexString: "#573F95")
- saveBtn.addTarget(self, action: #selector(saveValueBtn), for: .touchUpInside)
- saveBtn.layer.cornerRadius = 5
- saveBtn.layer.masksToBounds = true
- self.addSubview(saveBtn)
-
- }
-
- }
- extension IHCurtainView {
- @objc func saveValueBtn(sender : UIButton){
- // HUD.flash(.label("加载中..."), delay: 8)
- HUD.flash(.progress, delay: 8.0)
- self.delegate?.setCurtain(dataLists: dataSources)
- }
- }
- extension IHCurtainView : UITableViewDelegate,UITableViewDataSource{
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return self.dataSources.count
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = IHCurtainCell.curtainCellWithTableViewAndIndexPath(tableView: tableView, indexPath: indexPath)
- cell.indexPath = indexPath
- cell.dataSource = self.dataSources[indexPath.row]
- return cell
- }
-
-
- }
|