//
//  HomeViewController+AppLication.swift
//  MobilePortal
//
//  Created by caiyang on 2020/3/31.
//  Copyright © 2020 yin chen. All rights reserved.
//

import UIKit

extension HomeViewController {
    /// 设置服务范围数组
    func setScopeList(scopeHttpArray:NSMutableArray){
        if scopeHttpArray.count == 0 {
            return
        }
        let appModelArray = NSMutableArray()
        let titleModel = MineTitleTableViewCellModel()
        titleModel.className = "MineTitleTableViewCell"
        titleModel.titleValue = "常用功能"
        appModelArray.add(titleModel)
        for index in 0..<scopeHttpArray.count {
            
            let scopeHttpModel:ApplicationHttpScopListModel = scopeHttpArray[index] as! ApplicationHttpScopListModel
            let detailedModel = MineDetailedTableViewCellModel()
            detailedModel.className = "MineDetailedTableViewCell"
            detailedModel.cellNum = self.cellNum
            detailedModel.lineViewShowType = true
            detailedModel.titleValue = scopeHttpModel.scope
            self.addMyApplicationsHttpCellData(detailedModelArray: detailedModel.detaileArray, applicationsHttpArray: scopeHttpModel.application, scopeHttpModel: scopeHttpModel)
            appModelArray.add(detailedModel)
        }
        self.dataSource.add(appModelArray)
    }
    //添加分类
    func addMyApplicationsHttpCellData(detailedModelArray:NSMutableArray,applicationsHttpArray:NSMutableArray,scopeHttpModel:ApplicationHttpScopListModel)  {
        //添加详细分类
        for index in 0..<applicationsHttpArray.count{
            let httpDetailModel:ApplicationHttpListModel = applicationsHttpArray[index] as! ApplicationHttpListModel
            let detailModel = MineCollectionViewCellModel()
            detailModel.className = "MineCollectionViewCell"
            detailModel.titleValue = httpDetailModel.name
            detailModel.imageName = httpDetailModel.imageUrl
            detailModel.biaojiNum = httpDetailModel.value2
            detailModel.openUrl = httpDetailModel.iosopenurl
            detailModel.platforms = httpDetailModel.platforms
            detailModel.isInstallation = self.isInstallation(urlString: httpDetailModel.iosopenurl!)
            detailModel.block = { [weak self](value:Any) in
                //                self?.gotoWeb(httpDetailModel: httpDetailModel, type: type!)
//                self?.classAction(selecHttpModel:httpDetailModel)
                self?.refreshTokenHttpAction(selecHttpModel: httpDetailModel)
            }
            detailedModelArray .add(detailModel)
        }
        addCellModel(array: detailedModelArray , scopeHttpModel: scopeHttpModel)
    }
    //添加更多按钮
    func addCellModel(array:NSMutableArray ,scopeHttpModel:ApplicationHttpScopListModel){
        let detailModel = MineCollectionViewCellModel()
        detailModel.className = "MineCollectionViewCell"
        detailModel.titleValue = "更多"
        detailModel.imageName = "more_image"
        detailModel.comments = "123"
        detailModel.applicationType = .HomeApplicationType
        detailModel.block = { [weak self](value:Any) in
            self?.gotoMineMore(title: scopeHttpModel.scope!, str: scopeHttpModel.scopes!)
        }
        array .add(detailModel)
    }
    //跳转更多页面
    func gotoMineMore(title:String,str:String){
        let vc:MineMoreViewController=MineMoreViewController()
        vc.title = "常用功能"
        vc.scope = str
        vc.scopes = title
        vc.applicationType = .HomeApplicationType
        vc.systemType = .HomeSystemType
        vc.hidesBottomBarWhenPushed = true
        self.pushViewController(viewController: vc, animated: true)
    }
}
