// // ApplyCardStrategyViewController.swift // xingchuangke // // Created by Virgil on 2019/4/25. // Copyright © 2019 Virgil. All rights reserved. // import UIKit class ApplyCardStrategyViewController: BaseViewController, UITableViewDataSource, UITableViewDelegate { @IBOutlet weak var viewTopHeight: NSLayoutConstraint! @IBOutlet weak var tableView: UITableView! @IBOutlet weak var viewTop: UIView! override func viewDidLoad() { super.viewDidLoad() self.title = "办卡攻略" initNavLeftBackButton() viewTopHeight.constant = ScreenWidth / 1242 * 710 tableView.register(UINib(nibName: "ApplyCardStrategyTableViewCell", bundle: nil), forCellReuseIdentifier: "ApplyCardStrategyTableViewCell") tableView.delegate = self tableView.dataSource = self tableView.separatorStyle = .none tableView.showsVerticalScrollIndicator = false tableView.estimatedRowHeight = 100 tableView.mj_header = MJRefreshNormalHeader(refreshingBlock: {[weak self] in self!.currentPage = 1 self!.loadData() }) tableView.mj_header?.lastUpdatedTimeKey = "ShowTableViewCell" tableView.mj_footer = MJRefreshBackNormalFooter(refreshingBlock: {[weak self] in self!.currentPage += 1 self!.loadData() }) loadHeaderData() } // MARK: =============加载数据=============== let arrHeader = NSMutableArray() func loadHeaderData() { let url = RequestURL.findAdvertisingWheel let params = NSMutableDictionary() params.setValue(0, forKey: "position") loadDataList(url: url, params: params, tag: 1003, array: arrHeader) } func loadData() { for i in 0 ..< 12 { arrData.add(i) } tableView.mj_header?.endRefreshing() tableView.mj_footer?.endRefreshing() returnData(tag: 1001) // let url = RequestURL.bookList; // let params = NSMutableDictionary() // params.setValue("", forKey: "subjectId") // params.setValue("", forKey: "showTimeSort") // params.setValue("", forKey: "priceSort") // loadDataList(url: url, params: params, tableView: self.tableView,tag:1001) } override func returnData(tag: Int) { if tag == 1001 { tableView.reloadData() } else if tag == 1003 { if arrHeader.count > 0 { var imgUrl = [String]() for i in 0 ..< arrHeader.count { imgUrl.append(getStringForArray(key: "img_path", arr: arrHeader, current: i)) } let viewHeader = Virgil_PagedView(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: viewTopHeight.constant), imageURLStrings: imgUrl, placeholderImage: UIImage(named: "img_banner_01")!, timeInterval: 6) {[weak self] (item) -> Void in if CommonValue.getUserId() == "" { appDelegate.navController.pushViewController(LoginViewController(), animated: true) return } let type = (self!.arrHeader[item] as! NSDictionary).getInt(key: "type") ///0:内部web 1:外部web 111:邀请好友 222开通商户 if type == 0 || type == 1 { let web = CommonWebViewViewController() web.strTitle = "详情" web.url = (self!.arrHeader[item] as! NSDictionary).getString(key: "web_url") appDelegate.navController.pushViewController(web, animated: true) } else if type == 111 { let vc = InviteViewController() appDelegate.navController.pushViewController(vc, animated: true) } else if type == 222 { let vc = SelectPayBrandViewController() appDelegate.navController.pushViewController(vc, animated: true) } } viewHeader.backgroundColor = UIColor.clear viewHeader.titles = ["1111", "2222", "3333", "4444"] viewTop.removeAll() viewTop.addSubview(viewHeader) } tableView.mj_header?.beginRefreshing() } } override func returnError(tag: Int, type: String) { if tag == 1003 { tableView.mj_header?.beginRefreshing() } } // MARK: TABLEVLEW 实现 func numberOfSections(in tableView: UITableView) -> Int { return 1 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return self.arrData.count } func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { return 9 } func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { let view = UIView(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: 9)) view.backgroundColor = CommonUntils.getUIColorFromRGB(rgbValue: 0xf5f6f9, alpha: 1.0) return view } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "ApplyCardStrategyTableViewCell", for: indexPath as IndexPath) as! ApplyCardStrategyTableViewCell //cell.lblTitle.text = getString(indexPath.row, key: "Name") cell.lblTitle.text = "办卡不能太急,技巧很重要" cell.lblDesc.text = "办卡不能太急,技巧很重要,今天给大家分享一下办卡技巧,办卡不能太急,技巧很重要" cell.img.loadImage(imgUrl: "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1556193280248&di=c15fd3d86cdfa3dc14bb6ea0281a5da8&imgtype=0&src=http%3A%2F%2Fimg.mp.itc.cn%2Fupload%2F20170223%2Fe8c14927d0cd44b180253142ec5e52d3_th.jpeg", defaultImage: "") cell.img.setCornerRadius(size: 8) return cell } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let vc = CommonWebViewViewController() vc.strTitle = "详情" vc.url = "" toViewController(viewController: vc) } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) } override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { super.init(nibName: "ApplyCardStrategyViewController", bundle: nil) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } }