//
//  ChangePassWordViewController+http.swift
//  MobilePortal
//
//  Created by xiejiangbo on 2019/6/28.
//  Copyright © 2019 yin chen. All rights reserved.
//

import UIKit

extension ChangePassWordViewController {
    func getChangePasswordHttpCmd(){
        let cmd:HttpCommand = ChangePasswordHttpCmd.init(version: PHttpVersion_v1)
        let block:httpBlock = {[weak self] (result:RequestResult!,useInfo:Any!)->() in
            if result != nil {
                self?.httpChangePasswordHttpResultResponse(result: result)
            }else{
                print("空的")
            }
        }
        let attrDic:NSMutableDictionary = NSMutableDictionary()
        let dic:NSMutableDictionary = NSMutableDictionary()
        dic[kHttpChangePasswordHttpPostCmd_oldPsw] = oldTextView.text
        dic[kHttpChangePasswordHttpPostCmd_password] = newTextView.text
        dic[kHttpChangePasswordHttpPostCmd_userid] = AccountInfo.sharedInstance().UserId
        attrDic[kHttpChangePasswordHttpPostCmd_attr] = dic
        cmd.requestInfo = attrDic as [NSObject:AnyObject]
        let completeDelegate = SMBaseHttpComplete.init(block: block , withUserInfo: nil)
        cmd.completeDelegate=completeDelegate
        print("url==%@",cmd.getUrl())
        cmd.execute()
    }
    func httpChangePasswordHttpResultResponse(result:RequestResult){
        let r:ChangePasswordHttpResult = result as! ChangePasswordHttpResult
        if r.isOk() {
            let array:NSMutableArray = r.getChangePasswordHttpResult()
            if array.count == 0{
                SMToastView.showMessage("密码修改成功！")
                AccountInfo.sharedInstance().clearAccount()
                if self.signOutBlock != nil{
                    signOutBlock()
                }
                arrowResponse()
            }else{
                SMToastView.showMessage(array[0] as! String)
            }
        }else{
            SMToastView.showMessage("请查看当前网络状态！")
        }
    }
}
