//
//  HomeMoreViewController+http.swift
//  MobilePortal
//
//  Created by xiejiangbo on 2019/9/21.
//  Copyright © 2019 yin chen. All rights reserved.
//

import UIKit

extension HomeMoreViewController{
    
    func getMoreApplicationsHttpCmd(){
        showHintView()
        let cmd:HttpCommand = MoreApplicationsHttpCmd.init(version: PHttpVersion_v1)
        let block:httpBlock = {[weak self] (result:RequestResult!,useInfo:Any!)->() in
            if result != nil {
                self?.httpMoreApplicationsHttpResultResponse(result: result)
            }else{
                print("空的")
            }
        }
        let dic:NSMutableDictionary = NSMutableDictionary()
        let attrDic:NSMutableDictionary = NSMutableDictionary()
        attrDic[kHttpMoreApplicationsHttpCmd_empid] = judgmentStrNil(str: AccountInfo.sharedInstance().UserId)
        dic[kHttpMoreApplicationsHttpCmd_attr] = attrDic
        dic[kHttpMoreApplicationsHttpCmd_pageNum] = ""
        dic[kHttpMoreApplicationsHttpCmd_pageSize] = "999"
        dic[kHttpMoreApplicationsHttpCmd_sort] = "desc"
        let filtersDic:NSMutableDictionary = NSMutableDictionary()
        filtersDic[kHttpMoreApplicationsHttpCmd_value] = "6"
        let filtersArray = NSMutableArray()
        filtersArray.add(filtersDic)
        dic[kHttpMoreApplicationsHttpCmd_filters] = filtersArray
        cmd.requestInfo = dic as [NSObject:AnyObject]
        let completeDelegate = SMBaseHttpComplete.init(block: block , withUserInfo: nil)
        cmd.completeDelegate=completeDelegate
        print("url==%@",cmd.getUrl())
        cmd.execute()
    }
    func httpMoreApplicationsHttpResultResponse(result:RequestResult){
        let r:MoreApplicationsHttpResult = result as! MoreApplicationsHttpResult
        if r.isOk() {
            let array:NSMutableArray = r.getMoreApplicationsHttpResult()
            let httpModel:MoreApplicationsHttpModel = array[0] as! MoreApplicationsHttpModel
            self.initDataModel(httpModel: httpModel)
        }else{
            SMToastView.showMessage("请查看当前网络状态！")
        }
        hidenHintView()
    }
    func initDataModel(httpModel:MoreApplicationsHttpModel){
        for index in 0..<httpModel.listArray.count {
            let listModel:MoreApplicationsHttpListModel = httpModel.listArray[index] as! MoreApplicationsHttpListModel
            oneArr.add(self.getHomeMoreCollectionViewCellModel(listModel: listModel, operationType: .DeleteType))
        }
        self.dataSource.add(oneArr)
        self.delegate.dataSource = self.dataSource
        collectionView.reloadData()
    }
    func getHomeMoreCollectionViewCellModel(listModel:MoreApplicationsHttpListModel,operationType:OperationType)->HomeMoreCollectionViewCellModel{
        let model = HomeMoreCollectionViewCellModel()
        model.className = "HomeMoreCollectionViewCell"
        model.titleValue = listModel.title
        model.imageName = listModel.image
        model.comments = listModel.comments
        //model.operationType = operationType
        model.block = {[weak self](value:Any) in
            self?.actionGotoWeb(webViewUrl: value as! String, isHomePushType: .YesIsHomePushType, isShowTitleType: .YesShowTitleType, appid: "", isEncryptionType: .YesEncryptionType)
        }
        //model.editStatusType = self.editStatusType
        return model
    }
}
