//
//  MineMoreViewController+oldHttp.swift
//  MobilePortal
//
//  Created by caiyang on 2020/4/21.
//  Copyright © 2020 yin chen. All rights reserved.
//

import UIKit

extension MineMoreViewController {
    // MARK:获取我的自定义
    func getMyApplicationsHttpCmdTwo(){
        let cmd:HttpCommand = MyApplicationsHttpCmd.init(version: PHttpVersion_v1)
        let block:httpBlock = {[weak self] (result:RequestResult!,useInfo:Any!)->() in
            if result != nil {
                self?.httpMyApplicationsHttpResultResponseTwo(result: result)
            }else{
                print("空的")
            }
        }
        let dic:NSMutableDictionary = NSMutableDictionary()
        
        dic[kHttpMyApplicationsHttpCmd_empid] = judgmentStrNil(str: AccountInfo.sharedInstance().UserId)
        if self.applicationType == .MyApplicationType {
            dic[kHttpMyApplicationsHttpCmd_type] = "10"
        }else if self.applicationType == .OftenApplicationType{
            dic[kHttpMyApplicationsHttpCmd_type] = "11"
        } else if self.applicationType == .HomeApplicationType {
            dic[kHttpMyApplicationsHttpCmd_system] = "1"
        }
//        dic[kHttpMyApplicationsHttpCmd_system] = ""
        cmd.requestInfo = dic as [NSObject:AnyObject]
        let completeDelegate = SMBaseHttpComplete.init(block: block , withUserInfo: nil)
        cmd.completeDelegate=completeDelegate
        print("url==%@",cmd.getUrl())
        cmd.execute()
    }
    func httpMyApplicationsHttpResultResponseTwo(result:RequestResult){
        let r:MyApplicationsHttpResult = result as! MyApplicationsHttpResult
        if r.isOk() {
            let array:NSMutableArray = r.getMyApplicationsHttpResult()
            let httpModel:MyApplicationsHttpModel = array[0] as! MyApplicationsHttpModel
            self.mineCellModelArray = httpModel.listArray
            setmineCellModelArrayOld()
        }else{
            SMToastView.showMessage("请查看当前网络状态！")
        }
        group.leave()
    }
    func setmineCellModelArrayOld(){
//        for index in 0..<httpArray.count {
//            let scopeHttpModel:ApplicationHttpScopListModel = httpArray[index] as! ApplicationHttpScopListModel
//            self.mineCellModelArray = scopeHttpModel.application
//        }
        //        AccountInfo.sharedInstance().myApplicationCellNum = String(self.mineCellModelArray.count)
        AccountInfo.sharedInstance().myApplicationCellNum = String(format: "%d", self.mineCellModelArray.count )
        tableViewCellModel.className = "MineMoreTableViewCell"
        tableViewCellModel.lineViewShowType = true
        tableViewCellModel.collcetionViewSectionModellArray = (self.getHttpCollcetionViewModellArray(arrays: self.mineCellModelArray, operationType: .DeleteType))
        tableViewCellModel.block = {[weak self] (value:Any,value1:Any)in
            self?.tableViewCellModel.collcetionViewSectionModellArray = value as! NSMutableArray
            AccountInfo.sharedInstance().myApplicationCellNum = String(format: "%d", self?.tableViewCellModel.collcetionViewSectionModellArray.count ?? Int())
            self?.getType(model: value1 as! MineMoreCollectionViewCellModel)
            self?.myTableView.reloadData()
        }
    }
    // MARK:获取更多
    func getMoreApplicationsTwoHttpCmd(){
        let cmd:HttpCommand = MoreApplicationsTwoHttpCmd.init(version: PHttpVersion_v1)
        let block:httpBlock = {[weak self] (result:RequestResult!,useInfo:Any!)->() in
            if result != nil {
                self?.httpMoreOldApplicationsTwoHttpResultResponse(result: result)
            }else{
                print("空的")
            }
        }
        let dic:NSMutableDictionary = NSMutableDictionary()
        let attrDic:NSMutableDictionary = NSMutableDictionary()
        attrDic[kHttpMoreApplicationsTwoHttpCmd_userid] = AccountInfo.sharedInstance().UserId
        attrDic[kHttpMoreApplicationsTwoHttpCmd_empid] = judgmentStrNil(str: AccountInfo.sharedInstance().UserId)
        dic[kHttpMoreApplicationsTwoHttpCmd_attr] = attrDic
        //dic[kHttpMoreApplicationsTwoHttpCmd_orderby] = "createon"
        dic[kHttpMoreApplicationsTwoHttpCmd_pageNum] = ""
        
        dic[kHttpMoreApplicationsTwoHttpCmd_pageSize] = "200"
        dic[kHttpMoreApplicationsTwoHttpCmd_sort] = "desc"
        let filtersDic:NSMutableDictionary = NSMutableDictionary()
        if self.applicationType == .MyApplicationType {
            filtersDic[kHttpMoreApplicationsTwoHttpCmd_value] = "10"
        }else{
            filtersDic[kHttpMoreApplicationsTwoHttpCmd_value] = "11"
        }
        let filtersArray = NSMutableArray()
        filtersArray.add(filtersDic)
        dic[kHttpMoreApplicationsTwoHttpCmd_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 httpMoreOldApplicationsTwoHttpResultResponse(result:RequestResult){
        let r:MoreApplicationsTwoHttpResult = result as! MoreApplicationsTwoHttpResult
        if r.isOk() {
            let array:NSMutableArray = r.getMoreApplicationsTwoHttpResult()
            self.settableViewCellModel(modelArray: array)
        }else{
            SMToastView.showMessage("请查看当前网络状态！")
        }
        group.leave()
//        self.myTableView.reloadData()
    }
    /// 保存接口
//    func getSaveApplicationsHttpCmdOld(){
//        showHintView()
//        let cmd:HttpCommand = SaveApplicationsHttpCmd.init(version: PHttpVersion_v1)
//        let block:httpBlock = {[weak self] (result:RequestResult!,useInfo:Any!)->() in
//            if result != nil {
//                self?.httpHttpSaveApplicationsHttpResultResponse(result: result)
//            }else{
//                print("空的")
//            }
//        }
//        let dic:NSMutableDictionary = NSMutableDictionary()
//        dic[kHttpSaveApplicationsHttpCmd_userid] = AccountInfo.sharedInstance().UserId
////        if self.applicationType == .MyApplicationType {
////            dic[kHttpSaveApplicationsHttpCmd_type] = "10"
////        }else if self.applicationType == .OftenApplicationType{
////            dic[kHttpSaveApplicationsHttpCmd_type] = "11"
////        }else if self.applicationType == .HomeApplicationType{
//            dic[kHttpSaveApplicationsHttpCmd_system] = "1"
////        }
//        let array = NSMutableArray()
//        dic[kHttpSaveApplicationsHttpCmd_list] = getSeaveModelListArrayOld(httpArray: array)
//        cmd.requestInfo = dic as [NSObject:AnyObject]
//        let completeDelegate = SMBaseHttpComplete.init(block: block , withUserInfo: nil)
//        cmd.completeDelegate=completeDelegate
//        print("url==%@",cmd.getUrl())
//        cmd.execute()
//        
//    }
//    func httpHttpSaveApplicationsHttpResultResponse(result:RequestResult){
//        let r:SaveApplicationsHttpResult = result as! SaveApplicationsHttpResult
//        if r.isOk() {
//            let array:NSMutableArray = r.getSaveApplicationsHttpResult()
//            if array.count != 0{
//                SMToastView.showMessage("保存成功！")
//                NotificationCenter.default.post(name: Notification.Name(rawValue: "inforAction"), object: "0")
//            }else{
//                SMToastView.showMessage("保存失败！")
//            }
//            hidenHintView()
//        }else{
//            SMToastView.showMessage("请查看当前网络状态！")
//            hidenHintView()
//        }
//         actionHttpGCD()
//    }
//    func getSeaveModelListArrayOld(httpArray:NSMutableArray)->NSMutableArray{
//        let classModel:MineMoreTwoTableViewCellModel = self.tableViewCellModel.collcetionViewSectionModellArray[0] as! MineMoreTwoTableViewCellModel
//        for index in 0..<classModel.collcetionViewSectionModellArray.count{
//            let dic = NSMutableDictionary()
//            let model:MineMoreCollectionViewCellModel = classModel.collcetionViewSectionModellArray[index] as! MineMoreCollectionViewCellModel
//            dic[kHttpSaveApplicationsHttpCmd_id] =  model.id
//            dic[kHttpSaveApplicationsHttpCmd_title] =  model.title
//            dic[kHttpSaveApplicationsHttpCmd_status] =  model.status
//            dic[kHttpSaveApplicationsHttpCmd_createon] =  model.createon
//            dic[kHttpSaveApplicationsHttpCmd_createby] =  model.createby
//            dic[kHttpSaveApplicationsHttpCmd_pid] =  model.pid
//            dic[kHttpSaveApplicationsHttpCmd_author] =  model.author
//            dic[kHttpSaveApplicationsHttpCmd_createbyname] =  model.createbyname
//            dic[kHttpSaveApplicationsHttpCmd_updatebyname] =  model.updatebyname
//            dic[kHttpSaveApplicationsHttpCmd_image] =  model.image
//            dic[kHttpSaveApplicationsHttpCmd_homeshow] =  model.homeshow
//            dic[kHttpSaveApplicationsHttpCmd_comments] =  model.comments
//            dic[kHttpSaveApplicationsHttpCmd_docname] =  model.docname
//            dic[kHttpSaveApplicationsHttpCmd_type] =  model.type
//            dic[kHttpSaveApplicationsHttpCmd_foldertype] =  model.foldertype
//            dic[kHttpSaveApplicationsHttpCmd_kgimage] =  model.kgimage
//            dic[kHttpSaveApplicationsHttpCmd_listimage] =  model.listimage
//            httpArray .add(dic)
//        }
//        return httpArray
//    }
}
