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

import UIKit

extension AutonmousMoreViewController {
    /// 获取自主服务
    func getAutonomousHttpPostCmd(){
        let cmd:HttpCommand = AutonomousHttpPostCmd.init(version: PHttpVersion_v1)
        let block:httpBlock = {[weak self] (result:RequestResult!,useInfo:Any!)->() in
            if result != nil {
                self?.httpAutonomousHttpPostResultResponse(result: result)
            }else{
                print("空的")
            }
        }
        let dic:NSMutableDictionary = NSMutableDictionary()
        let attrDic:[String:Any] = ["userid":AccountInfo.sharedInstance().UserId!,"value":"5"]
//        dic[kHttpCustomerServiewHttpCmd_filters] = filtersArray
        dic[kHttpCustomerServiewHttpCmd_attr] = attrDic
        cmd.requestInfo = dic as [NSObject:AnyObject]
        let completeDelegate = SMBaseHttpComplete.init(block: block , withUserInfo: nil)
        cmd.completeDelegate=completeDelegate
        print("url==%@",cmd.getUrl())
        cmd.execute()
    }
    func httpAutonomousHttpPostResultResponse(result:RequestResult){
        let r:AutonomousHttpPostResult = result as! AutonomousHttpPostResult
        if r.isOk() {
            let array = r.getAutonomousHttpPostResult() as NSMutableArray
            self.collectionViewData(array: array)
        }else{
            SMToastView.showMessage("请查看当前网络状态！")
        }
        group.leave()
    }
    /// 数据处理
    func collectionViewData(array:NSMutableArray){
        self.dataSource = NSMutableArray()
        for index in 0..<array.count {
            let httpModel:ApplicationHttpListModel = array[index] as! ApplicationHttpListModel
            self.dataSource .add(self.getUpcomingCollectionViewCellModel(httpModel:httpModel))
        }
//        addMore()
    }
    func getUpcomingCollectionViewCellModel(httpModel:ApplicationHttpListModel)->UpcomingCollectionViewCellModel{
        let detailModel = UpcomingCollectionViewCellModel()
        detailModel.className = "UpcomingCollectionViewCell"
        detailModel.titleValue = httpModel.name
        detailModel.imageName = httpModel.imageUrl
        detailModel.biaojiNum = httpModel.value2
        detailModel.openUrl = httpModel.openurl
        detailModel.comments = httpModel.comments
        detailModel.biaojiNum = httpModel.value4
        detailModel.block = { [weak self](value:Any) in
            self?.selectAutonomous(model: httpModel)
//            self?.classAction(selecHttpModel: httpModel)
        }
        return detailModel
    }
}
