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

import UIKit

extension MineInfoViewController {

    func addInitTableView() {
        self.view.addSubview(myTableView)
        myTableView.snp.makeConstraints { (make) in
            make.width.height.equalToSuperview()
            make.center.equalToSuperview()
        }
        self.dataSource = NSMutableArray()
        initDate()
        self.delegate = MineInfoViewControllerDelegate()
        self.delegate.dataSource = self.dataSource
        self.myTableView.delegate = self.delegate
        self.myTableView.dataSource = self.delegate
    }
    func initDate(){
        /// 头像
        self.dataSource.add(getMineInfoHeadTableViewCellModel())
        /// 用户名
        self.getMineInfoTableViewCellModel(imageName: "email_image", title: judgmentStrNil(str: self.inforHttpModel.cnname), name: "用户名", block: {
            
        }, accessoryType: .none)
        /// 公司
        self.getMineInfoTableViewCellModel(imageName: "email_image", title: judgmentStrNil(str: self.inforHttpModel.companyname), name: "公司", block: {
            
        }, accessoryType: .none)
        /// 部门
        self.getMineInfoTableViewCellModel(imageName: "email_image", title: judgmentStrNil(str: self.inforHttpModel.deptnames), name: "所属部门", block: {
            
        }, accessoryType: .none)
        /// 修改密码
        self.getMineInfoTableViewCellModel(imageName: "email_image", title: "", name: "修改密码", block: {[weak self] in
            self?.gotoChangePassWordViewController(changePassWordType: .OrdinaryChangePassWordType)
        }, accessoryType: .disclosureIndicator)
        /// 设置
        self.getMineInfoTableViewCellModel(imageName: "email_image", title: "", name: "设置", block: {[weak self] in
            let vc = SetUpViewController()
            self?.pushViewController(viewController: vc, animated: true)
            
        }, accessoryType: .disclosureIndicator)
        /// 添加分割
        self.getNormalTableViewCellModel()
        /// 邮箱
        self.getMineInfoTableViewCellModel(imageName: "email_image", title: judgmentStrNil(str: self.inforHttpModel.email), name: "邮箱", block: {
            
        }, accessoryType: .disclosureIndicator)
        /// 手机
        self.getMineInfoTableViewCellModel(imageName: "mineinfo_iphone_image", title: judgmentStrNil(str: self.inforHttpModel.mobilephone), name: "手机", block: {
            
        }, accessoryType: .disclosureIndicator)
        /// 座机
//        self.getMineInfoTableViewCellModel(imageName: "mineinfo_landline_image", title: judgmentStrNil(str: self.inforHttpModel.phone2), name: "座机", block: {
//
//        }, accessoryType: .disclosureIndicator)
        self.getMineInfoTableViewCellModel(imageName: "mineinfo_landline_image", title: judgmentStrNil(str: self.inforHttpModel.phone), name: "座机", block: {
            
        }, accessoryType: .disclosureIndicator)
        /// QQ
//        self.getMineInfoTableViewCellModel(imageName: "mineinfo_QQ_image", title: judgmentStrNil(str: self.inforHttpModel.qq), name: "QQ", block: {
//
//        }, accessoryType: .disclosureIndicator)
        self.getMineInfoTableViewCellModel(imageName: "mineinfo_QQ_image", title: weiChatqq(value: self.inforHttpModel.qq), name: "QQ", block: {
            
        }, accessoryType: .disclosureIndicator)
        /// 微信
//        self.getMineInfoTableViewCellModel(imageName: "mineinfo_weixin_image", title: judgmentStrNil(str: self.inforHttpModel.wechat), name: "微信", block: {
//
//        }, accessoryType: .disclosureIndicator)
//        self.getMineInfoTableViewCellModel(imageName: "mineinfo_weixin_image", title: weiChatqq(value: self.inforHttpModel.wechatname), name: "微信", block: {[weak self] in
//            if ((self!.inforHttpModel.wechatname) == nil || (self!.inforHttpModel.wechatname) == "") {
//                self?.getWeChatHttp()
//            } else {
//                SMToastView.showMessage("该账号已被微信绑定！")
//            }
//        }, accessoryType: .disclosureIndicator)
        
        self.getNormalTableViewCellModel()
        
        
        
//        self.getMineInfoTableViewCellModel(imageName: "mineinfo_shezhi_image", title: "", name: "设置", block: {
//            
//        }, accessoryType: .disclosureIndicator)
//        self.getNormalTableViewCellModel()
//        let infoDictionary:NSDictionary = Bundle.main.infoDictionary! as NSDictionary
//        self.getMineInfoTableViewCellModel(imageName: "mineinfo_banben_image", title: infoDictionary.object(forKey: "CFBundleVersion") as! String, name: "版本信息", block: {
//
//        }, accessoryType: .none)
        
        self.getSignOutTableViewCellModel()
    }
    func weiChatqq(value:String?)->String {
        if value != nil && value != ""{
            return value!
        }
        return "未绑定"
    }
    
    func getMineInfoHeadTableViewCellModel() -> MineInfoHeadTableViewCellModel{
        let headModel = MineInfoHeadTableViewCellModel()
        headModel.className = "MineInfoHeadTableViewCell"
        headModel.nameStr = judgmentStrNil(str: self.inforHttpModel.cnname)
        headModel.companyStr = judgmentStrNil(str: self.inforHttpModel.companyname)
        headModel.departementStr = judgmentStrNil(str: self.inforHttpModel.deptnames)
        headModel.headImageUrl = "head_image"
        headModel.accessoryType = .none
        headModel.block = {
            
        }
        return headModel
    }
    
    func getNormalTableViewCellModel() {
        let model = NormalTableViewCellModel()
        model.className = "NormalTableViewCell"
        self.dataSource.add(model)
        //return model
    }
    func getMineInfoTableViewCellModel(imageName:String,title:String,name:String,block:@escaping selectBlock,accessoryType:UITableViewCellAccessoryType){
        let model = MineInfoTableViewCellModel()
        model.className = "MineInfoTableViewCell"
        model.imageName = imageName
        model.titleStr = title
        model.nameStr = name
        model.block = block
        model.accessoryType = accessoryType
        self.dataSource.add(model)
    }
    func getSignOutTableViewCellModel(){
        let model = MineInfoTableViewCellModel()
        model.className = "SignOutTableViewCell"
        model.block = {[weak self] in
            self?.signOutButtonAction()
        }
        self.dataSource.add(model)
    }
}
class MineInfoViewControllerDelegate: BaseOneTableViewDelegate {
   
    
    override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0
    }
    
    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        
        if (section==0){
            return 0
        }
        return 0
    }
    
    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        let model:BaseCellModel = self.dataSource[indexPath.row] as! BaseCellModel
        if model.className == "MineInfoHeadTableViewCell" {
            return 80
        }else if model.className == "NormalTableViewCell"{
            return 19.33
        }
        return 44.67
    }
}
