// // PolicyViewController.swift // xingchuangke // // Created by 李晓飞 on 2020/9/1. // Copyright © 2020 Virgil. All rights reserved. // import UIKit class PolicyViewController: BaseViewController, UITableViewDelegate, UITableViewDataSource { var index: NSInteger? var machineType: String? var selectedActivityId: String = "" let tableView: UITableView = { let tab = UITableView.init(frame: CGRect.zero, style: .plain) tab.tableFooterView = UIView.init() return tab }() override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) appDelegate.setNavigationBarHidden(isHidden: false) // self.title = "活动中心" // self.title = brandList[index!] } override func viewDidLoad() { super.viewDidLoad() self.view.backgroundColor = UIColor.white initNavLeftBackButton() tableView.frame = self.view.bounds tableView.delegate = self tableView.dataSource = self tableView.separatorStyle = .none tableView.register(UINib(nibName: "ActiveListCell", bundle: nil), forCellReuseIdentifier: "ActiveListCell") self.view.addSubview(tableView) loadData() } // MARK: request func loadData() { let url = RequestURL.activityAuth let params = NSMutableDictionary() params.setValue(CommonValue.getUserId(), forKey: "userId") params.setValue("0012", forKey: "code") params.setValue(machineType, forKey: "machineTypeId") loadDataListPost(url: url, params: params, tag: 1001) } func loadDataForEdit() { let url = RequestURL.activityEdit let params = NSMutableDictionary() params.setValue(modelJson(), forKey: "model") params.setValue("0004", forKey: "code") loadDataInfoPost(url: url, params: params, tag: 1002) } func modelJson() -> String { let tempDic = NSMutableDictionary() tempDic.setValue(selectedActivityId, forKey: "activityId") tempDic.setValue(CommonValue.getUserId(), forKey: "userId") let data = (try? JSONSerialization.data(withJSONObject: tempDic, options: .prettyPrinted))! let strJson = NSString(data: data, encoding: String.Encoding.utf8.rawValue) return strJson! as String } override func returnData(tag: Int) { if tag == 1002 { let vc = ActiveDetailViewController() vc.activityId = selectedActivityId vc.userId = CommonValue.getUserId() self.navigationController?.pushViewController(vc, animated: true) return } tableView.reloadData() } override func returnError(tag: Int, type: String) { } // MARK: delegate func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return arrData.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "ActiveListCell", for: indexPath as IndexPath) as! ActiveListCell cell.selectionStyle = .none let activDic = arrData[indexPath.row] as! NSDictionary let productPolicyDic = activDic["productPolicy"] as! NSDictionary let depositStatus = productPolicyDic["activationConditions"] as! String if depositStatus == "0" { cell.depositStatusLbl.text = "押金" cell.earnTitleLbl.text = "押金金额" } else { cell.depositStatusLbl.text = "非押金" cell.earnTitleLbl.text = "交易达标金额" } let status = getString(current: indexPath.row, key: "type") if status == "1.0" { cell.statusLbl.text = "可给直属下级进行配置" cell.bgView.backgroundColor = UIColor.init(red: 56/255.0, green: 112/255.0, blue: 242/255.0, alpha: 1.0) } else { cell.statusLbl.text = "不可更改" cell.bgView.backgroundColor = UIColor.init(red: 0.0, green: 178/255.0, blue: 191/255.0, alpha: 1.0) } cell.rewardTitleLbl.text = "激活奖励" cell.brandLbl.text = getString(current: indexPath.row, key: "activityName") let startTime = getString(current: indexPath.row, key: "startTime") let endTime = getString(current: indexPath.row, key: "endTime") let startDataArr = startTime.components(separatedBy: " ") let endDataArr = endTime.components(separatedBy: " ") cell.timeLbl.text = "活动时间:\(startDataArr[0]) 至 \(endDataArr[0])" cell.earnLbl.text = productPolicyDic["depositAmount"] as? String cell.rewardLbl.text = productPolicyDic["activationAmountReward"] as? String return cell } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let status = getString(current: indexPath.row, key: "type") if status != "1.0" { return } let activDic = arrData[indexPath.row] as! NSDictionary selectedActivityId = activDic["activityId"] as! String loadDataForEdit() } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { // Get the new view controller using segue.destination. // Pass the selected object to the new view controller. } */ }