// // ApplyCardPercentViewController.swift // xingchuangke // // Created by Virgil on 2019/4/25. // Copyright © 2019 Virgil. All rights reserved. // import UIKit class CarInsuranceViewController: BaseViewController, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout { @IBOutlet weak var viewTopHeight: NSLayoutConstraint! @IBOutlet weak var collectionView: UICollectionView! @IBOutlet weak var viewTop: UIView! override func viewDidLoad() { super.viewDidLoad() self.title = "进度查询" initNavLeftBackButton() viewTopHeight.constant = ScreenWidth / 375 * 95 //添加header 无header去掉 需要创建 UICollectionReusableView collectionView.register(UINib(nibName: "CarInsuranceCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "CarInsuranceCollectionViewCell") collectionView.delegate = self collectionView.dataSource = self collectionView.showsVerticalScrollIndicator = false // collectionView.mj_header = MJRefreshNormalHeader(refreshingBlock: { // self.currentPage = 1; // self.loadData() // // }) // collectionView.mj_header.lastUpdatedTimeKey = "NewsListViewController" // collectionView.mj_footer = MJRefreshBackNormalFooter(refreshingBlock: { // 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 ..< 20 // { // arrData.add(i) // } // collectionView.mj_header.endRefreshing() // collectionView.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 { collectionView.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) } collectionView.reloadData() } } override func returnError(tag: Int, type: String) { if tag == 1003 { collectionView.mj_header?.beginRefreshing() } } //返回分区个数 func numberOfSections(in collectionView: UICollectionView) -> Int { return 1 } //返回每个分区的item个数 func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return self.arrTitle.count } //定义每个UICollectionView 的大小 func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { return CGSize(width: (ScreenWidth-10)/3, height: (ScreenWidth - 10) / 3 / 180 * 200) } let arrImages = ["ion_vehicle_03", "ion_vehicle_04", "ion_vehicle_05", "ion_vehicle_06", "ion_vehicle_07", "ion_vehicle_08", "ion_vehicle_09"] let arrTitle = ["待投保", "我的保单", "团队保险", "车险保险", "优惠查询", "投保指引", "常见问题"] //初始化cell func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CarInsuranceCollectionViewCell", for: indexPath) as! CarInsuranceCollectionViewCell cell.img.image = UIImage(named: arrImages[indexPath.row]) cell.lblName.text = arrTitle[indexPath.row] return cell } //定义每个UICollectionView 的间距 func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets { return UIEdgeInsets(top: 10, left: 0, bottom: 0, right: 0) } //定义每个UICollectionView 纵向的间距 func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat { return 0 } func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat { return 5 } //选中 func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) } override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { super.init(nibName: "CarInsuranceViewController", bundle: nil) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } }