<commit_before>//
//  UserTableViewController.swift
//  wp
//
//  Created by macbook air on 16/12/22.
//  Copyright © 2016年 com.yundian. All rights reserved.
//

import UIKit
import SideMenuController
import DKNightVersion
class UserTableViewController: BaseTableViewController {
    //用户名
    @IBOutlet weak var nameLabel: UILabel!
    //总单数
    @IBOutlet weak var propertyNumber: UILabel!
    @IBOutlet weak var yuanLabel: UILabel!
    //总手数
    @IBOutlet weak var integralLabel: UILabel!
    @IBOutlet weak var fenLabel: UILabel!
    //退出登录
    @IBOutlet weak var logoutButton: UIButton!
    //资金按钮
    @IBOutlet weak var myPropertyBtn: UIButton!
    //个人cell的背景颜色
    @IBOutlet weak var personBackgroud: UIView!
    @IBOutlet weak var propertyBackgroud: UIView!
    @IBOutlet weak var integralBackground: UIView!
    @IBOutlet weak var memberImageView: UIImageView!
    
    lazy var numberFormatter:NumberFormatter = {
       let formatter = NumberFormatter()
        formatter.numberStyle = .currency
        return formatter
    }()
    
    let jumpNotifyDict = [1 : AppConst.NotifyDefine.jumpToDealList,
                          2 : AppConst.NotifyDefine.jumpToWithdraw,
                          3 : AppConst.NotifyDefine.jumpToRecharge,]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //用户余额数据请求
        UserModel.share().addObserver(self, forKeyPath: AppConst.KVOKey.balance.rawValue, options: .new, context: nil)
        registerNotify()
        //更新token
        AppDataHelper.instance().checkTokenLogin()
        requstTotalHistroy()
        initUI()
    }
    func initUI() {
        tableView.contentSize = CGSize(width: 0, height: 600.0)
        tableView.backgroundColor = UIColor(hexString: "#F5F5F5")
        personBackgroud.dk_backgroundColorPicker = DKColorTable.shared().picker(withKey: AppConst.Color.main)
        propertyBackgroud.backgroundColor = UIColor(red: 255.0 / 255.0, green: 255.0 / 255.0, blue: 255.0 / 255.0, alpha: 0.2)
        integralBackground.backgroundColor = UIColor(red: 255.0 / 255.0, green: 255.0 / 255.0, blue: 255.0 / 255.0, alpha: 0.2)
        logoutButton.layer.borderWidth = 0.7
        logoutButton.layer.borderColor = UIColor(hexString: "#cccccc").cgColor
    }
    
    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
        
        if keyPath == AppConst.KVOKey.balance.rawValue {
            guard UserModel.share().currentUser != nil else { return }
            nameLabel.text = formatMoneyString(balance: (UserModel.share().currentUser?.balance)! )
            nameLabel.adjustsFontSizeToFitWidth = true
        }
    }
    
    func formatMoneyString(balance:Double) -> String? {
       let str = numberFormatter.string(from: NSNumber(value: balance))
        return str?.components(separatedBy: "￥").last?.components(separatedBy: "¥").last?.components(separatedBy: "$").last
    }
    
    func requstTotalHistroy() {
        AppAPIHelper.user().getTotalHistoryData(complete: { [weak self](result) -> ()? in
            if let model = result as? TotalHistoryModel {
                self?.propertyNumber.text = "\(model.amount)"
                self?.integralLabel.text = "\(model.count)"
            }
            return nil
        }, error: errorBlockFunc())
    }
    //MARK: -- 添加通知
    func registerNotify() {
        let notificationCenter = NotificationCenter.default
        //登录成功
        notificationCenter.addObserver(self, selector: #selector(updateUI), name: NSNotification.Name(rawValue: AppConst.NotifyDefine.UpdateUserInfo), object: nil)
        
    }
    override var prefersStatusBarHidden: Bool {
        return true
    }
    //登录成功
    func updateUI()  {
        memberImageView.isHidden = UserModel.share().getCurrentUser()?.type == 0
    }
    //退出登录
    @IBAction func logout(_ sender: Any) {
        AppDataHelper.instance().clearUserInfo()
        sideMenuController?.toggle()
    }
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if indexPath.row == 0 || indexPath.row > 3{
            return
        }
        NotificationCenter.default.post(name: NSNotification.Name(rawValue: jumpNotifyDict[indexPath.row]!), object: nil, userInfo: nil)
        sideMenuController?.toggle()
        tableView.deselectRow(at: indexPath, animated: true)
    }
    
    deinit {
        UserModel.share().currentUser?.removeObserver(self, forKeyPath: "balance")
        NotificationCenter.default.removeObserver(self)
    }
    
}<commit_msg>退出登录确认弹窗<commit_after>//
//  UserTableViewController.swift
//  wp
//
//  Created by macbook air on 16/12/22.
//  Copyright © 2016年 com.yundian. All rights reserved.
//

import UIKit
import SideMenuController
import DKNightVersion
class UserTableViewController: BaseTableViewController {
    //用户名
    @IBOutlet weak var nameLabel: UILabel!
    //总单数
    @IBOutlet weak var propertyNumber: UILabel!
    @IBOutlet weak var yuanLabel: UILabel!
    //总手数
    @IBOutlet weak var integralLabel: UILabel!
    @IBOutlet weak var fenLabel: UILabel!
    //退出登录
    @IBOutlet weak var logoutButton: UIButton!
    //资金按钮
    @IBOutlet weak var myPropertyBtn: UIButton!
    //个人cell的背景颜色
    @IBOutlet weak var personBackgroud: UIView!
    @IBOutlet weak var propertyBackgroud: UIView!
    @IBOutlet weak var integralBackground: UIView!
    @IBOutlet weak var memberImageView: UIImageView!
    
    lazy var numberFormatter:NumberFormatter = {
       let formatter = NumberFormatter()
        formatter.numberStyle = .currency
        return formatter
    }()
    
    let jumpNotifyDict = [1 : AppConst.NotifyDefine.jumpToDealList,
                          2 : AppConst.NotifyDefine.jumpToWithdraw,
                          3 : AppConst.NotifyDefine.jumpToRecharge,]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //用户余额数据请求
        UserModel.share().addObserver(self, forKeyPath: AppConst.KVOKey.balance.rawValue, options: .new, context: nil)
        registerNotify()
        //更新token
        AppDataHelper.instance().checkTokenLogin()
        requstTotalHistroy()
        initUI()
    }
    
    func initUI() {
        tableView.contentSize = CGSize(width: 0, height: 600.0)
        tableView.backgroundColor = UIColor(hexString: "#F5F5F5")
        personBackgroud.dk_backgroundColorPicker = DKColorTable.shared().picker(withKey: AppConst.Color.main)
        propertyBackgroud.backgroundColor = UIColor(red: 255.0 / 255.0, green: 255.0 / 255.0, blue: 255.0 / 255.0, alpha: 0.2)
        integralBackground.backgroundColor = UIColor(red: 255.0 / 255.0, green: 255.0 / 255.0, blue: 255.0 / 255.0, alpha: 0.2)
        logoutButton.layer.borderWidth = 0.7
        logoutButton.layer.borderColor = UIColor(hexString: "#cccccc").cgColor
    }
    
    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
        
        if keyPath == AppConst.KVOKey.balance.rawValue {
            guard UserModel.share().currentUser != nil else { return }
            nameLabel.text = formatMoneyString(balance: (UserModel.share().currentUser?.balance)! )
            nameLabel.adjustsFontSizeToFitWidth = true
        }
    }
    
    func formatMoneyString(balance:Double) -> String? {
       let str = numberFormatter.string(from: NSNumber(value: balance))
        return str?.components(separatedBy: "￥").last?.components(separatedBy: "¥").last?.components(separatedBy: "$").last
    }
    
    func requstTotalHistroy() {
        AppAPIHelper.user().getTotalHistoryData(complete: { [weak self](result) -> ()? in
            if let model = result as? TotalHistoryModel {
                self?.propertyNumber.text = "\(model.amount)"
                self?.integralLabel.text = "\(model.count)"
            }
            return nil
        }, error: errorBlockFunc())
    }
    //MARK: -- 添加通知
    func registerNotify() {
        let notificationCenter = NotificationCenter.default
        //登录成功
        notificationCenter.addObserver(self, selector: #selector(updateUI), name: NSNotification.Name(rawValue: AppConst.NotifyDefine.UpdateUserInfo), object: nil)
        
    }
    override var prefersStatusBarHidden: Bool {
        return true
    }
    //登录成功
    func updateUI()  {
        memberImageView.isHidden = UserModel.share().getCurrentUser()?.type == 0
    }
    //退出登录
    @IBAction func logout(_ sender: Any) {
        let logoutController = UIAlertController.init(title: "退出登录", message: "确认退出当前账号", preferredStyle: .alert)
        let cancelAction = UIAlertAction.init(title: "取消", style: .cancel, handler: nil)
        let sureAction = UIAlertAction.init(title: "确认", style: .default, handler: { [weak self]btn in
            AppDataHelper.instance().clearUserInfo()
            self?.sideMenuController?.toggle()
        })
        logoutController.addAction(cancelAction)
        logoutController.addAction(sureAction)
        present(logoutController, animated: true, completion: nil)
    }
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if indexPath.row == 0 || indexPath.row > 3{
            return
        }
        NotificationCenter.default.post(name: NSNotification.Name(rawValue: jumpNotifyDict[indexPath.row]!), object: nil, userInfo: nil)
        sideMenuController?.toggle()
        tableView.deselectRow(at: indexPath, animated: true)
    }
    
    deinit {
        UserModel.share().currentUser?.removeObserver(self, forKeyPath: "balance")
        NotificationCenter.default.removeObserver(self)
    }
    
}
{'fraction_non_alphanumeric': 0.10874948411060668, 'fraction_numerical': 0.01609574907139909, 'mean_word_length': 2.741026630644539, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1779774', 'n_tokens_mistral': 3041, 'n_tokens_neox': 2939, 'n_words': 611}