//
//  ApplyCardAccountViewController.swift
//  xingchuangke
//
//  Created by Virgil on 2019/4/26.
//  Copyright © 2019 Virgil. All rights reserved.
//

import UIKit

class ApplyCardAccountViewController: BaseViewController, UITableViewDataSource, UITableViewDelegate {

    @IBOutlet weak var btnQuery: UIButton!
    @IBOutlet weak var btnEnd: UIButton!
    @IBOutlet weak var btnStart: UIButton!
    @IBOutlet weak var lblMoney: UILabel!
    @IBOutlet weak var view2: UIView!
    @IBOutlet weak var tableView: UITableView!
    @IBOutlet weak var viewTop: UIView!
    override func viewDidLoad() {
        super.viewDidLoad()
        let viewNav = (CommonViewUntils.getViewForXIB(xibName: "NavView") as! NavView)
        viewNav.initView(title: "我的账户") {[weak self] (index, _) in
            if index == 0 {
                self!.handleBack()
            }
        }
        self.view.addSubview(viewNav)
        viewNav.marginTop(top: 0)
        viewTop.setSizeWidth(width: ScreenWidth)
        viewTop.setSizeHeight(height: viewNav.bottom() + 90)

        view2.marginTop(top: 0, view: viewTop)
        tableView.marginTop(top: 0, view: view2)
        tableView.setSizeHeight(height: ScreenHeight - common_bottom_height - view2.bottom())

        btnStart.setSizeWidth(width: (ScreenWidth - 36 - 47) / 2)
        btnEnd.setSizeWidth(width: (ScreenWidth - 36 - 47) / 2)
        btnStart.marginLeft(left: 10)
        btnEnd.marginLeft(left: 8, view: btnStart)
        btnQuery.marginLeft(left: 8, view: btnEnd)

        btnStart.setCornerRadius(size: 2)
        btnEnd.setCornerRadius(size: 2)

        tableView.register(UINib(nibName: "ApplyCardAccountTableViewCell", bundle: nil), forCellReuseIdentifier: "ApplyCardAccountTableViewCell")
        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()
        })
    }

    let arrTitle = ["建设银行", "中国银行", "农业银行", "工商银行", "招商银行", "农商银行"]
    let arrContent = ["12", "5", "23", "8", "6", "15"]
    // MARK: =============加载数据===============
    func loadData() {

        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()
        }
    }
    override func returnError(tag: Int, type: String) {

    }

    // MARK: TABLEVLEW 实现
    // MARK: TABLEVLEW 实现
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.arrTitle.count
    }

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 55
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "ApplyCardAccountTableViewCell", for: indexPath as IndexPath) as! ApplyCardAccountTableViewCell
        //cell.lblTitle.text = getString(indexPath.row, key: "Name")
        cell.lblName.text  = arrTitle[indexPath.row]
        cell.lblCount.text  = arrContent[indexPath.row]
        return cell
    }

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        //        let view = UIViewController()
        //        view.oneGoId = self.arrData[indexPath.row]["ItemId"] as! Int
        //        self.navigationController?.pushViewController(view, animated: true)
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        appDelegate.setNavigationBarHidden(isHidden: true)
    }
    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        super.init(nibName: "ApplyCardAccountViewController", bundle: nil)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}