//
//  SinglePointViewController+LoginView.swift
//  MobilePortal
//
//  Created by caiyang on 2020/7/30.
//  Copyright © 2020 yin chen. All rights reserved.
//

import UIKit

extension SinglePointViewController {
    func autoLogin()  {
        if AccountInfo.sharedInstance().UserId != nil {
//            self.loginView.passTextView.text = AccountInfo.sharedInstance().passWord
            self.loginView.userTextView.text = AccountInfo.sharedInstance().login_UaesName
            DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {[weak self] in
                self?.getLoginHttpPostCmdCmd()
            }
        }
    }
    func addInitLoginView(){
        loginView.isHidden = false
        loginView.passTextView.text = nil
        self.view .addSubview(loginView)
        //长按手势
        let longpressGesutre = UILongPressGestureRecognizer.init(target: self, action: #selector(longpressGesutreAction(sender:)))
        //长按时间为1秒
        longpressGesutre.minimumPressDuration = 3
        loginView.headTitleImage.addGestureRecognizer(longpressGesutre)
        loginView.headTitleImage.isUserInteractionEnabled = true
        loginView.loginButton.addTarget(self, action: #selector(onLogin), for: .touchUpInside)
    }
    @objc func onLogin() {
        loginView.userTextView.resignFirstResponder()
        loginView.passTextView.resignFirstResponder()
        if loginView.userTextView.text == nil || loginView.userTextView.text?.count == 0 {
            SMToastView.showMessage("账号不能为空")
            return
        }
        if loginView.passTextView.text == nil || loginView.passTextView.text?.count == 0 {
            SMToastView.showMessage("密码不能为空")
            return
        }
        AccountInfo.sharedInstance().login_UaesName = loginView.userTextView.text
//        AccountInfo.sharedInstance().passWord = loginView.passTextView.text
        self.loginInitType = .LoginActionType
        getScopeListHttpCmd()
    }
    
    override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
        loginView.userTextView.resignFirstResponder()
        loginView.passTextView.resignFirstResponder()
    }
    @objc func longpressGesutreAction(sender : UILongPressGestureRecognizer){
        if sender.state == UIGestureRecognizerState.began{
            showAlert(title: "温馨提示", message: AccountInfo.sharedInstance().appUUID!, titleCancelBtn: "取消", titleSecondBtn: "复制") {[weak self] in
                self?.copyId()
            }
        }
    }
    /// 复制设备ID
    func copyId(){
        let pasteboard = UIPasteboard.general
        pasteboard.string = AccountInfo.sharedInstance().appUUID
        SMToastView.showMessage("内容已复制！")
    }
//    func newHttpAction(){
//        //        showHintView()
//        //        queue.async(group: group, execute: {[weak self] in
//        //            self?.group.enter()
//        //            self?.getLoginHttpPostCmdCmd()
//        //        })
//        //        group.notify(queue: DispatchQueue.main) {[weak self] in
//        NotificationCenter.default.post(name: Notification.Name(rawValue: "addTabBarWindow"), object: "0")
//        JPUSHService.setTags([AccountInfo.sharedInstance().appUUID!], completion: { (iResCode, iTags, seq) in
//            print(iResCode,iTags!,seq)
//            } as JPUSHTagsOperationCompletion, seq: 0)
//        JPUSHService.setAlias(AccountInfo.sharedInstance().UserId, completion: { (iResCode, iTags, seq) in
//            print(iResCode,iTags!,seq)
//        }, seq: 1)
//        //            self?.hidenHintView()
//        //        }
//    }
}
