//
//  MineInfoViewController+http.swift
//  SYMobilePortal
//
//  Created by xiejiangbo on 2018/5/14.
//  Copyright © 2018年 yin chen. All rights reserved.
//

import UIKit

extension MineInfoViewController {

    //获取个人信息接口
    func getMyInformationHttpGetCmd(){
//        let cmd:HttpCommand = MyInformationHttpGetCmd.init(version: PHttpVersion_v1)
//        let block:httpBlock = {[weak self] (result:RequestResult!,useInfo:Any!)->() in
//            if result != nil {
//                self?.httpMyInformationHttpGetResultResponse(result: result)
//            }else{
//                print("空的")
//            }
//        }
//        let dic:NSMutableDictionary = NSMutableDictionary()
//        dic[kHttpMyInformationHttpGetCmd_userid] = AccountInfo.sharedInstance().UserId
//        let completeDelegate = SMBaseHttpComplete.init(block: block , withUserInfo: nil)
//        cmd.requestInfo = dic as? [AnyHashable : Any]
//        cmd.completeDelegate=completeDelegate
//        print("url==%@",cmd.getUrl())
//        cmd.execute()
        let cmd:HttpCommand = UserInfoHttpPostCmd.init(version: PHttpVersion_v1)
        let block:httpBlock = {[weak self] (result:RequestResult!,useInfo:Any!)->() in
            if result != nil {
                self?.httpMyInformationHttpGetResultResponse(result: result)
            }else{
                print("空的")
            }
        }
        let dic:NSMutableDictionary = NSMutableDictionary()
        let arrtDic:NSMutableDictionary = NSMutableDictionary()
        arrtDic[kHttpUserInfoHttpPostCmd_name] = AccountInfo.sharedInstance().UserId
        dic[kHttpUserInfoHttpPostCmd_attr] = arrtDic
        let completeDelegate = SMBaseHttpComplete.init(block: block , withUserInfo: nil)
        cmd.requestInfo = (dic as! [AnyHashable : Any])
        cmd.completeDelegate=completeDelegate
        print("url==%@",cmd.getUrl())
        cmd.execute()
    }
    func httpMyInformationHttpGetResultResponse(result:RequestResult){
//        let r:MyInformationHttpGetResult = result as! MyInformationHttpGetResult
//        if r.isOk() {
//            let array:NSMutableArray = r.getMyInformationAllData()
//            self.inforHttpModel = array[0] as! MyInformationHttpModel
//            self.dataSource = NSMutableArray()
//            initDate()
//        }else{
//            SMToastView.showMessage("请查看当前网络状态！")
//        }
        let r:UserInfoHttpPostResult = result as! UserInfoHttpPostResult
        if r.isOk() {
            let array:NSMutableArray = r.getUserInfoHttpPostResult()
            self.inforHttpModel = array[0] as! MyInformationHttpModel
            self.dataSource = NSMutableArray()
            initDate()
        }else{
            SMToastView.showMessage("请查看当前网络状态！")
        }
        group.leave()
    }
    
    /// 微信绑定
    func getWeChatBindingHttpPostCmd(){
        showHintView()
        let cmd:HttpCommand = WeChatBindingHttpPostCmd.init(version: PHttpVersion_v1)
        let block:httpBlock = {[weak self] (result:RequestResult!,useInfo:Any!)->() in
            if result != nil {
                self?.httpWeChatBindingHttpResultResponse(result: result)
            }else{
                print("空的")
            }
        }
        let dic:NSMutableDictionary = NSMutableDictionary()
        dic[kHttpWeChatBindingHttpPostCmd_userid] = AccountInfo.sharedInstance().UserId
        dic[kHttpWeChatBindingHttpPostCmd_wechatid] = AccountInfo.sharedInstance().weChat_unionid
        dic[kHttpWeChatBindingHttpPostCmd_state] = "1"
        dic[kHttpWeChatBindingHttpPostCmd_wechatname] = AccountInfo.sharedInstance().weChatInfo_nickname
        let completeDelegate = SMBaseHttpComplete.init(block: block , withUserInfo: nil)
        cmd.requestInfo = dic as? [AnyHashable : Any]
        cmd.completeDelegate=completeDelegate
        print("url==%@",cmd.getUrl())
        cmd.execute()
        
    }
    func httpWeChatBindingHttpResultResponse(result:RequestResult){
        let r:WeChatBindingHttpResult = result as! WeChatBindingHttpResult
        if r.isOk() {
            let array:NSMutableArray = r.getWeChatBindingHttpResult()
            if (array.count == 0) {
                actionHttpGCD()
                NotificationCenter.default.post(name: Notification.Name(rawValue: "inforAction"), object: "0")
                SMToastView.showMessage("绑定成功！")
            } else {
                SMToastView.showMessage((array[0] as! String))
                self.hidenHintView()
            }
        }else{
            SMToastView.showMessage("请查看当前网络状态！")
            self.hidenHintView()
        }
    }
}
