//
//  AutonmousMoreViewController+initView.swift
//  MobilePortal
//
//  Created by caiyang on 2020/4/28.
//  Copyright © 2020 yin chen. All rights reserved.
//

import UIKit

extension AutonmousMoreViewController {
    func initDragCollectionView(){
        cellNum = 4
        //initData()
        delegate.dataSource = self.dataSource
        delegate.cellNum = self.cellNum
        delegate.block = {(value:Any) in
        }
        
        delegate.dataSource = self.dataSource
        collectionView.delegate = self.delegate
        collectionView.dataSource = self.delegate
        self.collectionView.reloadData()
    }
    func getCollectionViewH(itemArray:NSMutableArray)->CGFloat {
        if itemArray.count >= Int(self.cellNum){
            let index = lroundf(Float(ceil(Double(itemArray.count)/self.cellNum)))
            return (SCREEN_WHIDTH()/4)*CGFloat(index)*0.9
        }
        return (SCREEN_WHIDTH()/4)*0.9
    }
    func selectAutonomous(model:ApplicationHttpListModel) {
        self.selecClassModel = model
        if model.belong != "IT_ROBOT" {
            self.gotoAutonomousCompanyVC(model: model)
        } else {
//            let url = model.comments! + "userId=" + judgmentStrNil(str: AccountInfo.sharedInstance().UserId) + "&userCompany=" + judgmentStrNil(str: AccountInfo.sharedInstance().infoCompanyName) + "&userName=" + judgmentStrNil(str: AccountInfo.sharedInstance().userName)
//            self.actionGotoWebGotoWeb(webViewUrl: url, isHomePushType: .NOIsHomePushType, previousPageShowTitleType: .YesShowTitleType)
//            self.classAction(selecHttpModel: model)
            self.refreshTokenHttpAction(selecHttpModel: model)
            
        }
    }
    func gotoAutonomousCompanyVC(model:ApplicationHttpListModel){
        let vc = AutonomousCompanyVC()
        vc.model = model
        vc.block = {[weak self] (value:Any) in
            self?.mineGotoWebVC(model: value as! AutonomousCompanyModel)
        }
        vc.hidesBottomBarWhenPushed = true
        self.pushViewController(viewController: vc, animated: true)
    }
    @objc func mineGotoWebVC(model:AutonomousCompanyModel){
        //        http://mobileportal.shaphar.com:8020/SYERP/todolist/robotGoodsSearch/view/common.html?title=%E5%95%86%E5%93%81%E6%9F%A5%E8%AF%A2&userId=159748&sysDbSource=erp_ogg_fujian#/datalist/goodsInfoList
        //        http://mobileportal.shaphar.com:8020/SYERP/todolist/robotGoodsSearch/view/common.html?title=商品查询
        var url = self.selecClassModel.hurl!
        if (url.contains("?")){
            url = url + "&userId="+judgmentStrNil(str: AccountInfo.sharedInstance().UserId)+"&sysDbSource="+judgmentStrNil(str: model.db_source)+"#/datalist/goodsInfoList"
        } else {
            url = url + "?userId="+judgmentStrNil(str: AccountInfo.sharedInstance().UserId)+"&sysDbSource="+judgmentStrNil(str: model.db_source)
        }
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
            self.gotoWeb(url: url)
        }
    }
    func gotoWeb(url:String) {
        let vc:WebSwiftViewController = WebSwiftViewController()
        vc.newType = .OrdinaryNewsType
        vc.isHomePushType = .YesIsHomePushType
        vc.isShowTitleType = .NoShowTitleType
        vc.webViewUrl = url
        self.pushViewController(viewController: vc, animated: true)
    }
}
