//
//  UpcomingListVC+NewHttp.swift
//  MobilePortal
//
//  Created by caiyang on 2020/11/16.
//  Copyright © 2020 yin chen. All rights reserved.
//

import UIKit

extension UpcomingListVC {
    /// 获取列表
    func getUpcomingNewListPostCmd(){
        let cmd:HttpCommand = UpcomingNewListPostCmd.init(version: PHttpVersion_v1)
        let block:httpBlock = {[weak self] (result:RequestResult!,useInfo:Any!)->() in
            if result != nil {
                self?.httpUpcomingNewListHttpResultResponse(result: result)
            }else{
                print("空的")
            }
        }
        let dic:NSMutableDictionary = NSMutableDictionary()
        dic[kHttpUpcomingNewListPostCmd_key] = judgmentStrNil(str: appModel.todokey)
//        dic[kHttpUpcomingNewListPostCmd_userCode] = "188500"
        dic[kHttpUpcomingNewListPostCmd_userCode] = judgmentStrNil(str: AccountInfo.sharedInstance().UserId)
        dic[kHttpUpcomingNewListPostCmd_pageNo] = self.page
        dic[kHttpUpcomingNewListPostCmd_pageSize] = "20"
        dic[kHttpUpcomingNewListPostCmd_type] = self.upcomingType == .DoneType ? UnifiedAgencyType.DoneUnifiedAgencyType.rawValue:UnifiedAgencyType.UpcomingUnifiedAgencyType.rawValue
        cmd.requestInfo = dic as [NSObject:AnyObject]
        let completeDelegate = SMBaseHttpComplete.init(block: block , withUserInfo: nil)
        cmd.completeDelegate=completeDelegate
        print("url==%@",cmd.getUrl())
        cmd.execute()
    }
    func httpUpcomingNewListHttpResultResponse(result:RequestResult){
        let r:UpcomingNewListHttpResult = result as! UpcomingNewListHttpResult
        if r.isOk() {
            let array:NSMutableArray = r.getUpcomingNewListHttpResult() as NSMutableArray
            httpListData = array[0] as! UpcomingListModel
        }else{
            SMToastView.showMessage("请查看当前网络状态！")
        }
        group.leave()
    }
    func initSetDataNew(httpArray:NSMutableArray){
        if self.page == 1 {
            self.dataSource = NSMutableArray()
            self.delegate.dataSource = self.dataSource
        }
        if httpArray.count != 1 {
            self.page = self.page+1
        }else if httpArray.count == 0 && self.page != 1 {
            SMToastView.showMessage("暂无更多数据！")
        }
        for index in 0..<httpArray.count {
            let httpModel:UpcomingListItemModel = httpArray[index] as! UpcomingListItemModel
            self.addNewUpcomingListTableViewCellModel(httpModel: httpModel)
        }
        self.delegate.dataSource = self.dataSource
        //        self.myTableView .reloadData()
    }
    func addNewUpcomingListTableViewCellModel(httpModel:UpcomingListItemModel){
        let model = UpcomingListTableViewCellModel()
        model.className = "UpcomingListTableViewCell"
        if self.upcomingType == .DoneType {
            model.title = self.titleType + "详细通知"
        } else {
            model.title = self.titleType + "详细通知"
        }
        model.subTitle = judgmentStrNil(str:httpModel.title)
        //        model.dateTime = self.getDateFormatString(timeStamp: httpModel.msgtime!)
        model.dateTime = judgmentStrNil(str:httpModel.dealtime)
        model.minuteTime = judgmentStrNil(str:httpModel.dealtime)
        model.upcomingType = self.upcomingType
        model.block = {[weak self] in
//            self?.gotoDetails(model: model)
            self?.gotoDetails(model: httpModel)
        }
        model.retractUnfoldType = .UnfoldType
        model.retractUnfoldBlack = {[weak self] (value:Any) in
            let type:RetractUnfoldType = value as! RetractUnfoldType
            model.retractUnfoldType = type == RetractUnfoldType.Retractype ? RetractUnfoldType.UnfoldType : RetractUnfoldType.Retractype
            self?.myTableView.reloadData()
        }
        self.dataSource.add(model)
    }
    
}
