//
//  MineController.swift
//  OrderScheduling
//
//  Created by 中道 on 2023/8/18.
//

import Foundation
import DDAutoUIKit_Private
import DDControlsKit_Private
import SnapKit
import RxSwift
import RxRelay
import RxCocoa
import DDToastKit_Private
import DDProgressHUDKit_Private
import MJRefresh

extension MineController {
    func addActions() {
        mineView.scrollView.mj_header = MJRefreshNormalHeader(refreshingBlock: {[weak self] in
            self?.refreshRelay.accept(nil)
        })
        
        mineView.logoutButton.rx.tap
            .observe(on: MainScheduler.instance)
            .do(onNext: {[weak self] _ in
                self?.view.dd_showHUD()
            })
            .flatMapLatest({ _ in
                return RQ.logout(parameters: LogoutParameters(deviceId: 1))
            })
            .observe(on: MainScheduler.instance)
            .do(onNext: {[weak self] _ in
                self?.view.dd_hideHUD()
            })
            .observe(on: MainScheduler.instance)
            .subscribe(onNext: {[weak self] response in
                if response?.success == true {
                    NotificationCenter.default.post(name: NSNotification.Name(rawValue: Notification_logoutSuccessToLoginController), object: nil)
                }else{
                    self?.view.dd_makeToast(response?.msg)
                }
            })
            .disposed(by: disposeBag)
                
          refreshRelay
                .flatMapLatest({ _ in
                    return RQ.thisWeekNumber()
                })
                .flatMapLatest { numberModel in
                    return Single.zip(RQ.generalInfo(),RQ.getNeedConfirmPersonInfo(prameters: NeedConfirmPersonInfoParameters(supplierId: UserData.default.supplierId)),RQ.selectCountBySupplierId(parameters: SelectCountBySupplierIdPrameters(supplierId: UserData.default.supplierId,remindApp: 0,userId: UserData.default.userId)),Single.just(numberModel))
                }
                .observe(on: MainScheduler.instance)
                .subscribe(onNext: {[weak self] response,needConfirmPersonInfoModel,selectCountModel,numberModel in
                    self?.mineView.scrollView.mj_header?.endRefreshing()
                    if response?.success == true {
                        self?.mineView.carInfoView.descLabel.text = String(response?.data?.vehicleCount ?? 0)+"台"
                        self?.mineView.driverInfoView.descLabel.text = String(response?.data?.driverCount ?? 0)+"人"
                        if let icon = response?.data?.icon {
                            self?.mineView.avatar.sd_setImage(with: URL(string: icon),placeholderImage: UIImage(named: "placeholder_gender_man"))
                        }
                        
                        if let company = response?.data?.supplierName {
                            self?.mineView.companyLabel.text = company
                        }
                    }else{
                        self?.view.dd_makeToast(response?.msg)
                    }
                    
                    if needConfirmPersonInfoModel?.success == true {
                        self?.mineView.manageView.descLabel.text = String(needConfirmPersonInfoModel?.data?.count ?? 0)+"人"
                    }else{
                        self?.view.dd_makeToast(response?.msg)
                    }
                    
                    if numberModel?.success == true {
                        if let number = numberModel?.data, number > 0 {
                            self?.mineView.ershouche.contentView.isHidden = false
                            self?.mineView.ershouche.contentLabel.text = "\(number)"
                        }else{
                            self?.mineView.ershouche.contentView.isHidden = true
                        }
                    }else{
                        self?.view.dd_makeToast(numberModel?.msg)
                    }
                    
                    if selectCountModel?.success == true {
                        if let count = selectCountModel?.data, count > 0 {
                            self?.mineView.gongdanpici.contentView.isHidden = false
                            self?.mineView.gongdanpici.contentLabel.text = "\(count)"
                        }else{
                            self?.mineView.gongdanpici.contentView.isHidden = true
                        }
                    }else{
                        self?.view.dd_makeToast(selectCountModel?.msg)
                    }
                })
                .disposed(by: disposeBag)
                
        mineView.manageGes.rx.event
            .observe(on: MainScheduler.instance)
            .subscribe(onNext: { _ in
                if let supplierId = UserData.default.supplierId {
                    WEBTOOL.open(name: .managerPeople, appending: "&supplierId=\(supplierId)")
                }
            })
            .disposed(by: disposeBag)
        
        mineView.carInfoGes.rx.event
            .observe(on: MainScheduler.instance)
            .subscribe(onNext: { _ in
                WEBTOOL.open(name: .vehicleManage, appending: nil)
            })
            .disposed(by: disposeBag)
        
        mineView.driverInfoGes.rx.event
            .observe(on: MainScheduler.instance)
            .subscribe(onNext: { _ in
                if let supplierType = USER.supplierType {
                    WEBTOOL.open(name: .driverManage, appending: "&supplierType=\(supplierType)")
                }
            })
            .disposed(by: disposeBag)
        
        mineView.fuwushanganjianGes.rx.event
            .observe(on: MainScheduler.instance)
            .subscribe(onNext: { _ in
                WEBTOOL.open(name: .kpiCaseNew, appending: nil)
            })
            .disposed(by: disposeBag)
        
        mineView.shujutongjiGes.rx.event
            .observe(on: MainScheduler.instance)
            .subscribe(onNext: { _ in
                WEBTOOL.open(name: .kpiIndex, appending: nil)
            })
            .disposed(by: disposeBag)
        
        mineView.gongdanduizhangGes.rx.event
            .observe(on: MainScheduler.instance)
            .subscribe(onNext: { _ in
                WEBTOOL.open(name: .workOrderReconciliation, appending: nil)
            })
            .disposed(by: disposeBag)
        
        mineView.gongdanpiciGes.rx.event
            .observe(on: MainScheduler.instance)
            .subscribe(onNext: { _ in
                if let supplierId = USER.supplierId {
                    WEBTOOL.open(name: .invoicingNotify, appending: "&supplierId=\(supplierId)")
                }
            })
            .disposed(by: disposeBag)
        
        mineView.kaipiaoxinxiGes.rx.event
            .observe(on: MainScheduler.instance)
            .subscribe(onNext: { _ in
                if let supplierId = USER.supplierId {
                    WEBTOOL.open(name: .invoiceListInfo, appending: "&supplierId=\(supplierId)")
                }
            })
            .disposed(by: disposeBag)
        
        mineView.luqiaofeibaoxiaoGes.rx.event
            .observe(on: MainScheduler.instance)
            .subscribe(onNext: { _ in
                WEBTOOL.open(name: .roadAndbridgeTollReimbursement, appending: nil)
            })
            .disposed(by: disposeBag)
        
        mineView.dianpingjinxiaocunGes.rx.event
            .observe(on: MainScheduler.instance)
            .subscribe(onNext: { _ in
                WEBTOOL.open(name: .batteryList, appending: nil)
            })
            .disposed(by: disposeBag)
        
        mineView.wendangziliaoGes.rx.event
            .observe(on: MainScheduler.instance)
            .subscribe(onNext: { _ in
                if let supplierId = USER.supplierId {
                    WEBTOOL.open(name: .docmentList, appending: "&supplierId=\(supplierId)")
                }
            })
            .disposed(by: disposeBag)
        
        mineView.peixunwendangGes.rx.event
            .observe(on: MainScheduler.instance)
            .subscribe(onNext: { _ in
                if let supplierId = USER.supplierId,let userId = USER.userId {
                    WEBTOOL.open(name: .trainDocment, appending: "&supplierId=\(supplierId)&userId=\(userId)")
                }
            })
            .disposed(by: disposeBag)
        
        mineView.ershoucheGes.rx.event
            .observe(on: MainScheduler.instance)
            .subscribe(onNext: { _ in
                WEBTOOL.open(name: .indexList, appending: nil)
            })
            .disposed(by: disposeBag)
        
        mineView.canbaoGes.rx.event
            .observe(on: ConcurrentMainScheduler.instance)
            .subscribe(onNext: { _ in
                WEBTOOL.open(name: .insuredPage, appending: nil)
            })
            .disposed(by: disposeBag)
        
        mineView.chongdianGes.rx.event
            .observe(on: MainScheduler.instance)
            .do(onNext: {[weak self] _ in
                self?.view.dd_showHUD()
            })
            .flatMapLatest { _ in
                return RQ.gjTokenInfo()
            }
            .observe(on: MainScheduler.instance)
            .subscribe(onNext: {[weak self] response in
                self?.view.dd_hideHUD()
                if response?.success == true, let token = response?.data, let username = USER.username {
                    WEBTOOL.open(name: .gjUrl, appending: "userId=\(username)&token=\(token)")
                } else {
                    self?.view.dd_makeToast(response?.msg ?? "请先退出登录，然后重新登录app")
                }
            })
            .disposed(by: disposeBag)
        
        mineView.banbenjianceGes.rx.event
            .observe(on: MainScheduler.instance)
            .subscribe(onNext: { _ in
                APPUPDATE.requestAppUpdateRelay.accept(.manual)
            })
            .disposed(by: disposeBag)
        
        mineView.tongzhitixingGes.rx.event
            .observe(on: MainScheduler.instance)
            .subscribe(onNext: {[weak self] _ in
                let vc = NotificationSetUpController()
                self?.navigationController?.pushViewController(vc, animated: true)
            })
            .disposed(by: disposeBag)
        
        preRefreshRelay
            .observe(on: MainScheduler.instance)
            .subscribe(onNext: {[weak self] _ in
                self?.mineView.scrollView.mj_header?.beginRefreshing()
            })
            .disposed(by: disposeBag)
    }
}

open class MineController : ZDViewController {
    private let mineView = MineView()
    private let disposeBag = DisposeBag()
    private let preRefreshRelay = ReplayRelay<Any?>.create(bufferSize: 1)
    private let refreshRelay = ReplayRelay<Any?>.create(bufferSize: 1)
    
    open override func viewDidLoad() {
        super.viewDidLoad()
        dd_navigationBarBackgroundColor = .hex("354683")
        dd_navigationBarTitleTextAttributes = [.foregroundColor : UIColor.white(alpha: 0.7),.font:UIFont.mediumFont(auto(15))]
        dd_navigationBarBarButtonItemAttributes = [.foregroundColor : UIColor.white]
        dd_navigationItemTitle = "我的"
        dd_navigationBarShadowColor = .hex("354683")
        navigationItem.leftBarButtonItems = nil
        
        view.addSubview(mineView)
        mineView.snp.makeConstraints { make in
            make.top.equalTo(CGRectGetHeight(UIApplication.shared.dd_statusBarFrame) + CGRectGetHeight(navigationController?.navigationBar.frame ?? .zero) - 1)
            make.left.right.equalToSuperview()
            make.bottom.equalTo(-view.safeAreaInsets.bottom - CGRectGetHeight(tabBarController?.tabBar.frame ?? .zero))
        }
        
        mineView.manageView.titleLabel.text = "管理人员"
        mineView.manageView.imageView.image = UIImage(named: "mine_info_manage")
        mineView.carInfoView.titleLabel.text = "车辆管理"
        mineView.carInfoView.imageView.image = UIImage(named: "mine_info_car")
        mineView.driverInfoView.titleLabel.text = "司机管理"
        mineView.driverInfoView.imageView.image = UIImage(named: "mine_info_driver")

        mineView.fuwushanganjian.titleLabel.text = "服务商案件和车辆情况统计"
        mineView.shujutongji.titleLabel.text = "服务商KPI"
        mineView.gongdanduizhang.titleLabel.text = "工单对账"
        mineView.gongdanpici.titleLabel.text = "工单批次"
        mineView.kaipiaoxinxi.titleLabel.text = "开票信息"
        mineView.luqiaofeibaoxiao.titleLabel.text = "路桥费报销"
        mineView.dianpingjinxiaocun.titleLabel.text = "电瓶进销存"
        mineView.peixunwendang.titleLabel.text = "培训文档"
        mineView.wendangziliao.titleLabel.text = "文档资料"
        mineView.ershouche.titleLabel.text = "二手车信息"
        mineView.canbao.titleLabel.text = "参保救援职业责任险"
        mineView.chongdian.titleLabel.text = "充电管理"
        mineView.banbenjiance.titleLabel.text = "版本检测"
        mineView.tongzhitixing.titleLabel.text = "通知提醒"
        
        var orderRadiusViewAddHeightCount = 0
        
        if (USER.supplierId != 1128) && USER.supplierType == 1 {
            orderRadiusViewAddHeightCount+=1
            mineView.luqiaofeibaoxiao.isHidden = false
            mineView.luqiaofeibaoxiao.snp.updateConstraints { make in
                make.height.equalTo(auto(55))
            }
        }else{
            mineView.luqiaofeibaoxiao.isHidden = true
            mineView.luqiaofeibaoxiao.snp.updateConstraints { make in
                make.height.equalTo(0)
            }
        }

        if USER.supplierType == 1 {
            orderRadiusViewAddHeightCount+=1
            mineView.dianpingjinxiaocun.isHidden = false
        }else{
            mineView.dianpingjinxiaocun.isHidden = true
        }
        
        if orderRadiusViewAddHeightCount > 0 {
            mineView.kaipiaoxinxi.line.isHidden = false
        }else{
            mineView.kaipiaoxinxi.line.isHidden = true
        }
        
        if orderRadiusViewAddHeightCount == 2 {
            mineView.luqiaofeibaoxiao.line.isHidden = false
        }else{
            mineView.luqiaofeibaoxiao.line.isHidden = true
        }
        
        mineView.orderRadiusView.snp.updateConstraints({ make in
            make.height.equalTo(auto(165) + CGFloat(orderRadiusViewAddHeightCount) * auto(55))
        })
        
        addActions()
    }
    
    open override func reloadData() {
        super.reloadData()
        NewTraining.default.newTrainingRelay.accept(nil)
        preRefreshRelay.accept(nil)
    }
    
    open override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        mineView.usedCarRadiusView.isHidden = false
        
        if WEBTOOL.bannerInMineDataSourcesContains(name: .indexList) {
            mineView.ershouche.isHidden = false
            mineView.ershouche.snp.updateConstraints { make in
                make.height.equalTo(auto(55))
            }
        }else{
            mineView.ershouche.isHidden = true
            mineView.ershouche.snp.updateConstraints { make in
                make.height.equalTo(0)
            }
        }
        if WEBTOOL.bannerInMineDataSourcesContains(name: .insuredPage) {
            mineView.canbao.isHidden = false
            mineView.canbao.line.isHidden = false
            mineView.canbao.snp.updateConstraints { make in
                make.height.equalTo(auto(55))
            }
        }else{
            mineView.canbao.isHidden = true
            mineView.canbao.line.isHidden = true
            mineView.canbao.snp.updateConstraints { make in
                make.height.equalTo(0)
            }
        }
    }
}

open class MineView : DDView {
    public let scrollView : DDScrollView
    private let scrollContentView : DDView
    private let topBackgroundImageView : DDImageView
    public let avatar : DDImageView
    public let companyLabel : DDLabel
    public let manageGes : UITapGestureRecognizer
    public let manageView : MineInfoView
    public let carInfoGes : UITapGestureRecognizer
    public let carInfoView : MineInfoView
    public let driverInfoGes : UITapGestureRecognizer
    public let driverInfoView : MineInfoView
    public let infoRadiusView : DDView
    private let infoStackView: UIStackView
    public let infoRadiusSeparate : DDImageView
    public let statisticsRadiusView : DDView
    public let orderRadiusView : DDView
    public let materialRadiusView : DDView
    public let usedCarRadiusView : DDView
    public let settingsRadiusView : DDView
    public let fuwushanganjianGes : UITapGestureRecognizer
    public let fuwushanganjian : MineCell
    public let shujutongjiGes : UITapGestureRecognizer
    public let shujutongji : MineCell
    public let gongdanduizhangGes : UITapGestureRecognizer
    public let gongdanduizhang : MineCell
    public let gongdanpiciGes : UITapGestureRecognizer
    public let gongdanpici : MineCell
    public let kaipiaoxinxiGes : UITapGestureRecognizer
    public let kaipiaoxinxi : MineCell
    public let luqiaofeibaoxiaoGes : UITapGestureRecognizer
    public let luqiaofeibaoxiao : MineCell
    public let dianpingjinxiaocunGes : UITapGestureRecognizer
    public let dianpingjinxiaocun : MineCell
    public let peixunwendangGes : UITapGestureRecognizer
    public let peixunwendang : MineCell
    public let wendangziliaoGes : UITapGestureRecognizer
    public let wendangziliao : MineCell
    public let ershoucheGes : UITapGestureRecognizer
    public let ershouche : MineCell
    public let canbaoGes : UITapGestureRecognizer
    public let canbao : MineCell
    public let chongdianGes : UITapGestureRecognizer
    public let chongdian : MineCell
    public let banbenjianceGes : UITapGestureRecognizer
    public let banbenjiance : MineCell
    public let tongzhitixingGes : UITapGestureRecognizer
    public let tongzhitixing : MineCell
    public let logoutButton : DDButton
    
    public override init(frame: CGRect) {
        scrollView = DDScrollView()
        scrollContentView = DDView()
        topBackgroundImageView = DDImageView()
        avatar = DDImageView(image: UIImage(named: "placeholder_gender_man"))
        companyLabel = DDLabel.dd_init(withText: "", font: .mediumFont(auto(12)), textColor: .hex("FFFFFF").alpha(0.5))
        manageView = MineInfoView()
        manageGes = UITapGestureRecognizer()
        carInfoView = MineInfoView()
        carInfoGes = UITapGestureRecognizer()
        driverInfoView = MineInfoView()
        driverInfoGes = UITapGestureRecognizer()
        infoRadiusView = DDView()
        infoStackView = UIStackView()
        infoRadiusSeparate = DDImageView(image: UIImage(named: "mine_info_separate"))
        statisticsRadiusView = DDView()
        orderRadiusView = DDView()
        materialRadiusView = DDView()
        usedCarRadiusView = DDView()
        settingsRadiusView = DDView()
        fuwushanganjianGes = UITapGestureRecognizer()
        fuwushanganjian = MineCell()
        shujutongjiGes = UITapGestureRecognizer()
        shujutongji = MineCell()
        gongdanduizhangGes = UITapGestureRecognizer()
        gongdanduizhang = MineCell()
        gongdanpiciGes = UITapGestureRecognizer()
        gongdanpici = MineCell()
        kaipiaoxinxiGes = UITapGestureRecognizer()
        kaipiaoxinxi = MineCell()
        luqiaofeibaoxiaoGes = UITapGestureRecognizer()
        luqiaofeibaoxiao = MineCell()
        dianpingjinxiaocunGes = UITapGestureRecognizer()
        dianpingjinxiaocun = MineCell()
        peixunwendangGes = UITapGestureRecognizer()
        peixunwendang = MineCell()
        wendangziliaoGes = UITapGestureRecognizer()
        wendangziliao = MineCell()
        ershoucheGes = UITapGestureRecognizer()
        ershouche = MineCell()
        canbaoGes = UITapGestureRecognizer()
        canbao = MineCell()
        chongdianGes = UITapGestureRecognizer()
        chongdian = MineCell()
        banbenjianceGes = UITapGestureRecognizer()
        banbenjiance = MineCell()
        tongzhitixingGes = UITapGestureRecognizer()
        tongzhitixing = MineCell()
        logoutButton = DDButton.dd_initCustom()
        super.init(frame: frame)
        
        backgroundColor = .hex("F4F5F7")
        
        addSubview(scrollView)
        scrollView.addSubview(scrollContentView)
        
        topBackgroundImageView.backgroundColor = .hex("354683")
        scrollContentView.addSubview(topBackgroundImageView)
        avatar.layer.cornerRadius = auto(27)
        avatar.layer.masksToBounds = true
        scrollContentView.addSubview(avatar)
        scrollContentView.addSubview(companyLabel)
        infoRadiusView.backgroundColor = .hex("FFFFFF")
        infoRadiusView.layer.cornerRadius = auto(12)
        scrollContentView.addSubview(infoRadiusView)

        infoStackView.axis = .horizontal
        infoStackView.alignment = .fill
        infoStackView.distribution = .fillEqually
        infoRadiusView.addSubview(infoStackView)

        manageView.addGestureRecognizer(manageGes)
        carInfoView.addGestureRecognizer(carInfoGes)
        driverInfoView.addGestureRecognizer(driverInfoGes)

        infoStackView.addArrangedSubview(manageView)
        infoStackView.addArrangedSubview(carInfoView)
        infoStackView.addArrangedSubview(driverInfoView)

        scrollContentView.addSubview(infoRadiusSeparate)
        statisticsRadiusView.backgroundColor = .hex("FFFFFF")
        statisticsRadiusView.layer.cornerRadius = auto(6)
        scrollContentView.addSubview(statisticsRadiusView)
        orderRadiusView.backgroundColor = .hex("FFFFFF")
        orderRadiusView.layer.cornerRadius = auto(6)
        scrollContentView.addSubview(orderRadiusView)
        materialRadiusView.backgroundColor = .hex("FFFFFF")
        materialRadiusView.layer.cornerRadius = auto(6)
        scrollContentView.addSubview(materialRadiusView)
        usedCarRadiusView.backgroundColor = .hex("FFFFFF")
        usedCarRadiusView.layer.cornerRadius = auto(6)
        scrollContentView.addSubview(usedCarRadiusView)
        settingsRadiusView.backgroundColor = .hex("FFFFFF")
        settingsRadiusView.layer.cornerRadius = auto(6)
        scrollContentView.addSubview(settingsRadiusView)
        fuwushanganjian.addGestureRecognizer(fuwushanganjianGes)
        statisticsRadiusView.addSubview(fuwushanganjian)
        shujutongji.addGestureRecognizer(shujutongjiGes)
        shujutongji.line.isHidden = true
        statisticsRadiusView.addSubview(shujutongji)
        gongdanduizhang.addGestureRecognizer(gongdanduizhangGes)
        orderRadiusView.addSubview(gongdanduizhang)
        gongdanpici.addGestureRecognizer(gongdanpiciGes)
        orderRadiusView.addSubview(gongdanpici)
        kaipiaoxinxi.line.isHidden = true
        kaipiaoxinxi.addGestureRecognizer(kaipiaoxinxiGes)
        orderRadiusView.addSubview(kaipiaoxinxi)
        luqiaofeibaoxiao.addGestureRecognizer(luqiaofeibaoxiaoGes)
        luqiaofeibaoxiao.line.isHidden = true
        luqiaofeibaoxiao.isHidden = true
        orderRadiusView.addSubview(luqiaofeibaoxiao)
        dianpingjinxiaocun.addGestureRecognizer(dianpingjinxiaocunGes)
        dianpingjinxiaocun.line.isHidden = true
        dianpingjinxiaocun.isHidden = true
        orderRadiusView.addSubview(dianpingjinxiaocun)
        peixunwendang.addGestureRecognizer(peixunwendangGes)
        materialRadiusView.addSubview(peixunwendang)
        wendangziliao.line.isHidden = true
        wendangziliao.addGestureRecognizer(wendangziliaoGes)
        materialRadiusView.addSubview(wendangziliao)
        usedCarRadiusView.isHidden = true
        ershouche.addGestureRecognizer(ershoucheGes)
        ershouche.contentImageView.image = UIImage(named: "ershouche_new")
        ershouche.contentLabel.text = "0"
        ershouche.isHidden = true
        usedCarRadiusView.addSubview(ershouche)
        canbao.addGestureRecognizer(canbaoGes)
        canbao.isHidden = true
        usedCarRadiusView.addSubview(canbao)
        chongdian.addGestureRecognizer(chongdianGes)
        chongdian.line.isHidden = true
        usedCarRadiusView.addSubview(chongdian)
        banbenjiance.addGestureRecognizer(banbenjianceGes)
        settingsRadiusView.addSubview(banbenjiance)
        tongzhitixing.line.isHidden = true
        settingsRadiusView.addSubview(tongzhitixing)
        tongzhitixing.addGestureRecognizer(tongzhitixingGes)
        logoutButton.backgroundColor = .hex("545D78").alpha(0.25)
        logoutButton.layer.cornerRadius = auto(17.5)
        logoutButton.setTitle("退出登录", for: .normal)
        logoutButton.setTitleColor(.white, for: .normal)
        logoutButton.titleLabel?.font = .mediumFont(auto(13))
        scrollContentView.addSubview(logoutButton)
        
        scrollView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        scrollContentView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
            make.width.equalToSuperview()
        }
        
        topBackgroundImageView.snp.makeConstraints { make in
            make.left.top.right.equalToSuperview()
            make.height.equalTo(auto(115))
        }
        
        avatar.snp.makeConstraints { make in
            make.top.equalTo(auto(10))
            make.left.equalTo(auto(25))
            make.width.height.equalTo(auto(54))
        }
        
        companyLabel.snp.makeConstraints { make in
            make.left.equalTo(avatar.snp.right).offset(auto(15))
            make.centerY.equalTo(avatar)
        }
        
        infoRadiusView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(topBackgroundImageView.snp.bottom).offset(-auto(37.5))
            make.height.equalTo(auto(73))
            make.width.equalTo(auto(350))
        }
        
        infoStackView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        infoRadiusSeparate.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.centerY.equalToSuperview()
        }
        
        statisticsRadiusView.snp.makeConstraints { make in
            make.top.equalTo(infoRadiusView.snp.bottom).offset(auto(10))
            make.width.equalTo(infoRadiusView)
            make.centerX.equalToSuperview()
        }
        
        orderRadiusView.snp.makeConstraints { make in
            make.top.equalTo(statisticsRadiusView.snp.bottom).offset(auto(10))
            make.width.equalTo(infoRadiusView)
            make.centerX.equalToSuperview()
            make.height.equalTo(auto(165))
        }
        
        materialRadiusView.snp.makeConstraints { make in
            make.top.equalTo(orderRadiusView.snp.bottom).offset(auto(10))
            make.width.equalTo(infoRadiusView)
            make.centerX.equalToSuperview()
            make.height.equalTo(auto(110))
        }
        
        usedCarRadiusView.snp.makeConstraints { make in
            make.top.equalTo(materialRadiusView.snp.bottom).offset(auto(10))
            make.width.equalTo(infoRadiusView)
            make.centerX.equalToSuperview()
        }
        
        settingsRadiusView.snp.makeConstraints { make in
            make.top.equalTo(usedCarRadiusView.snp.bottom).offset(auto(10))
            make.width.equalTo(infoRadiusView)
            make.centerX.equalToSuperview()
            make.height.equalTo(auto(110))
        }
        
        fuwushanganjian.snp.makeConstraints { make in
            make.left.right.top.equalToSuperview()
            make.height.equalTo(auto(55))
        }
        
        shujutongji.snp.makeConstraints { make in
            make.top.equalTo(fuwushanganjian.snp.bottom)
            make.left.right.equalToSuperview()
            make.height.equalTo(auto(55))
            make.bottom.equalToSuperview()
        }
        
        gongdanduizhang.snp.makeConstraints { make in
            make.left.right.top.equalToSuperview()
            make.height.equalTo(auto(55))
        }
        
        gongdanpici.snp.makeConstraints { make in
            make.top.equalTo(gongdanduizhang.snp.bottom)
            make.left.right.equalToSuperview()
            make.height.equalTo(gongdanduizhang)
        }
        
        kaipiaoxinxi.snp.makeConstraints { make in
            make.top.equalTo(gongdanpici.snp.bottom)
            make.left.right.equalToSuperview()
            make.height.equalTo(gongdanduizhang)
        }
        
        luqiaofeibaoxiao.snp.makeConstraints { make in
            make.top.equalTo(kaipiaoxinxi.snp.bottom)
            make.left.right.equalToSuperview()
            make.height.equalTo(0)
        }
        
        dianpingjinxiaocun.snp.makeConstraints { make in
            make.top.equalTo(luqiaofeibaoxiao.snp.bottom)
            make.left.right.bottom.equalToSuperview()
        }
        
        peixunwendang.snp.makeConstraints { make in
            make.top.left.right.equalToSuperview()
            make.height.equalTo(auto(55))
        }
        
        wendangziliao.snp.makeConstraints { make in
            make.top.equalTo(peixunwendang.snp.bottom)
            make.left.bottom.right.equalToSuperview()
        }
        
        ershouche.snp.makeConstraints { make in
            make.left.top.right.equalToSuperview()
            make.height.equalTo(0)
        }
        
        canbao.snp.makeConstraints { make in
            make.top.equalTo(ershouche.snp.bottom)
            make.left.right.equalToSuperview()
            make.height.equalTo(0)
        }
        
        chongdian.snp.makeConstraints { make in
            make.top.equalTo(canbao.snp.bottom)
            make.left.bottom.right.equalToSuperview()
            make.height.equalTo(auto(55))
        }
        
        banbenjiance.snp.makeConstraints { make in
            make.left.top.right.equalToSuperview()
            make.height.equalTo(auto(55))
        }
        
        tongzhitixing.snp.makeConstraints { make in
            make.top.equalTo(banbenjiance.snp.bottom)
            make.left.bottom.right.equalToSuperview()
        }
        
        logoutButton.snp.makeConstraints { make in
            make.top.equalTo(settingsRadiusView.snp.bottom).offset(auto(20))
            make.bottom.equalToSuperview().offset(-auto(20))
            make.centerX.equalToSuperview()
            make.width.equalTo(auto(110))
            make.height.equalTo(auto(35))
        }
    }
    
    public required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

open class MineCell : DDView {
    public let titleLabel : DDLabel
    public let arrow : DDImageView
    public let line : DDView
    
    public let contentView : UIView
    public let contentImageView : UIImageView
    public let contentLabel : UILabel
    
    override init(frame: CGRect) {
        titleLabel = DDLabel.dd_init(withText: "", font: .mediumFont(auto(14)), textColor: .hex("323643"))
        arrow = DDImageView(image: UIImage(named: "mine_info_arrow"))
        line = DDView()
        contentView = UIView()
        contentImageView = UIImageView()
        contentLabel = UILabel()
        super.init(frame: frame)
        addSubview(titleLabel)
        addSubview(arrow)
        line.backgroundColor = .hex("E9E9EA")
        addSubview(line)
        contentView.isHidden = true
        addSubview(contentView)
        contentView.addSubview(contentImageView)
        contentLabel.font = .dd_systemFont(ofSize: 14, weight: .medium)
        contentLabel.textColor = .dd_hex(light: "d81e06")
        contentView.addSubview(contentLabel)
        
        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(auto(20))
            make.centerY.equalToSuperview()
        }
        
        arrow.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.right.equalTo(-auto(20))
        }
        
        line.snp.makeConstraints { make in
            make.bottom.equalToSuperview()
            make.left.equalTo(titleLabel)
            make.right.equalTo(arrow)
            make.height.equalTo(1)
        }
        
        contentView.snp.makeConstraints { make in
            make.right.equalTo(arrow.snp.left).offset(-auto(10))
            make.centerY.equalToSuperview()
        }
        
        contentImageView.snp.makeConstraints { make in
            make.left.equalToSuperview()
            make.top.bottom.equalToSuperview().inset(auto(5))
        }
        
        contentLabel.snp.makeConstraints { make in
            make.left.equalTo(contentImageView.snp.right).offset(auto(5))
            make.centerY.equalToSuperview()
            make.right.equalToSuperview()
        }
    }
    
    public required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

public class MineInfoView : DDView {
    public let imageView : DDImageView
    public let titleLabel : DDLabel
    public let descLabel : DDLabel
    public let arrow : DDImageView
    public override init(frame: CGRect) {
        imageView = DDImageView()
        titleLabel = DDLabel.dd_init(withText: "", font: .mediumFont(auto(14)), textColor: .hex("203152"))
        descLabel = DDLabel.dd_init(withText: "", font: .regularFont(auto(12)), textColor: .hex("000000").alpha(0.55))
        arrow = DDImageView(image: UIImage(named: "mine_info_arrow"))
        super.init(frame: frame)
        
        addSubview(imageView)
        addSubview(titleLabel)
        addSubview(descLabel)
        addSubview(arrow)
        
        imageView.contentMode = .scaleAspectFit
        imageView.snp.makeConstraints { make in
            make.right.equalTo(titleLabel.snp.left).offset(-auto(5))
            make.width.height.equalTo(auto(24))
            make.centerY.equalTo(titleLabel)
        }

        titleLabel.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(auto(10))
            make.bottom.equalTo(snp.centerY).offset(-auto(2.5))
            make.centerX.equalToSuperview().offset(auto(8))
        }

        descLabel.snp.makeConstraints { make in
            make.left.equalTo(titleLabel)
            make.top.equalTo(snp.centerY).offset(auto(2.5))
            make.bottom.equalToSuperview().offset(-auto(10))
        }

        arrow.contentMode = .scaleAspectFit
        arrow.snp.makeConstraints { make in
            make.left.equalTo(titleLabel.snp.right).offset(auto(5))
            make.centerY.equalTo(titleLabel)
            make.width.height.equalTo(auto(8))
        }
    }
    
    public required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
