//
//  SelectCompanyViewController.swift
//  MobilePortal
//
//  Created by xiejiangbo on 2019/3/28.
//  Copyright © 2019 yin chen. All rights reserved.
//

import UIKit

class SelectCompanyViewController: BaseViewController {

    @IBOutlet weak var rightComanyLayoutConstraint: NSLayoutConstraint!
    @IBOutlet weak var companyTableView: UITableView!
    var dataSource:NSMutableArray!
    var delegate:SelectCompanyViewControllerDelegate!
    
    @IBOutlet weak var departmentTableView: UITableView!
    @IBOutlet weak var leftDepartmentLayoutConstraint: NSLayoutConstraint!
    var depDataSource:NSMutableArray!
    var depDelegate:SelectCompanyViewControllerDelegate!
    
    
    var block:passParameterBlock!
    var selecClassModel:AdvisoryHttpListModel!
    
    var selecCompanyModel:SelectCompanyHttpCompanyDataModel!
    var selecDepartmentModel:SelectCompanyHttpOrgListDataModel!
    
    class func createViewController(createArgs:AnyObject?) ->AnyObject{
        let storyboard:UIStoryboard=UIStoryboard(name: "SelectCompanyViewController", bundle: nil)
        let vc:SelectCompanyViewController=storyboard.instantiateViewController(withIdentifier: "SelectCompanyViewController") as! SelectCompanyViewController
        vc.createArgs=createArgs
        return vc
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.initTitleBar()
        self.title = "公司及部门选择"
        addInitTableView()
        addInitdepartmentTableView()
        actionCompanyHttpGCD()
        // Do any additional setup after loading the view.
    }
    
    func setVcTitle(userid:String?,partyOpcode:String?){
        let setTitle:String = "公司及部门选择"+"（"+userid!+"/"+partyOpcode!+"）"
        self.title = setTitle
    }
    func actionCompanyHttpGCD(){
        showHintView()
        queue.async(group: group, execute: {[weak self] in
            self?.group.enter()
            self?.getSelectCompanyHttpCmd()
        })
        group.notify(queue: DispatchQueue.main) {[weak self] in
            self?.delegate.dataSource = self?.dataSource
            self?.companyTableView.reloadData()
            self?.depDelegate.dataSource = self?.depDataSource
            self?.departmentTableView.reloadData()
            self?.hidenHintView()
        }
    }
    func actiondepartmentHttpGCD(){
        showHintView()
        queue.async(group: group, execute: {[weak self] in
            self?.group.enter()
            self?.getSelectDepartmentListHttpCmd()
        })
        group.notify(queue: DispatchQueue.main) {[weak self] in
            self?.depDelegate.dataSource = self?.depDataSource
            self?.departmentTableView.reloadData()
            self?.companyTableView.reloadData()
            self?.hidenHintView()
        }
    }
    override func gotoMessageVC(){
        self.actionGotoMessageWeb(messageId: AccountInfo.sharedInstance().messageId!, isHomePushType: .NOIsHomePushType)
    }
}
