CNLiveMineInfoAlertView.swift 27.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790
//
//  CNLiveMineInfoAlertView.swift
//  metaCode
//
//  Created by open on 2023/6/9.
//

import Foundation



typealias CloseGenderResultBlock = (_ text: Any) ->Void
class MineInfoAlertView: UIView {
    
    lazy var tapGesture = UITapGestureRecognizer()
    lazy var grayMaskView: UIView = {
       let grayMaskView = UIView()
       tapGesture.addTarget(self, action: #selector(setupCloseButtonAction))
       grayMaskView.backgroundColor = UIColor.black.withAlphaComponent(0.2)
       grayMaskView.addGestureRecognizer(tapGesture)
       return grayMaskView
    }()
    
    lazy var backView: UIView = {
        let backView = UIView()
        backView.backgroundColor = UIColor.white
        backView.layer.cornerRadius = 12
        return backView
    }()
    
    lazy var contentView : UIView = {
        let contentView = UIView.init()
        contentView.backgroundColor = .white
        contentView.isHidden = true
        return contentView
    }()
    
    lazy var wBtn: UIButton = {
        let wBtn = UIButton.init(type: .custom)
        wBtn.backgroundColor = .white
        wBtn.setImage(UIImage(named: "mine_info_alert_icon_w_nomal"), for: .normal)
        wBtn.setImage(UIImage(named: "mine_info_alert_icon_w_nomal"), for: .highlighted)
        wBtn.setImage(UIImage(named: "mine_info_alert_icon_w_select"), for: .selected)
        wBtn.imageView?.contentMode = .scaleToFill
        wBtn.layer.cornerRadius = 40
        wBtn.layer.masksToBounds = true
        wBtn.addTarget(self, action: #selector(wClickAction), for: .touchUpInside)
        return wBtn
    }()
    
    lazy var mBtn: UIButton = {
        let mBtn = UIButton.init(type: .custom)
        mBtn.backgroundColor = .white
        mBtn.setImage(UIImage(named: "mine_info_alert_icon_m_nomal"), for: .normal)
        mBtn.setImage(UIImage(named: "mine_info_alert_icon_m_nomal"), for: .highlighted)
        mBtn.setImage(UIImage(named: "mine_info_alert_icon_m_select"), for: .selected)
        mBtn.imageView?.contentMode = .scaleToFill
        mBtn.layer.cornerRadius = 40
        mBtn.layer.masksToBounds = true
        mBtn.addTarget(self, action: #selector(mClickAction), for: .touchUpInside)
        return mBtn
    }()
    
    lazy var wLabel: UILabel = {
        let wLabel = UILabel.init()
        wLabel.text = "女"
        wLabel.textAlignment = .center
        wLabel.textColor = .black
        wLabel.font = BoldFont_17_Fit
        return wLabel
    }()
    
    lazy var mLabel: UILabel = {
        let mLabel = UILabel.init()
        mLabel.text = "男"
        mLabel.textAlignment = .center
        mLabel.textColor = .black
        mLabel.font = BoldFont_17_Fit
        return mLabel
    }()
    
    lazy var wView: UIImageView = {
        let wView = UIImageView.init()
        wView.image = UIImage(named: "mine_info_alert_icon_g_select")
        wView.layer.cornerRadius = 8
        wView.layer.masksToBounds = true
        wView.backgroundColor = .clear
        wView.isHidden = true
        return wView
    }()
    
    lazy var mView: UIImageView = {
        let mView = UIImageView.init()
        mView.image = UIImage(named: "mine_info_alert_icon_g_select")
        mView.layer.cornerRadius = 8
        mView.layer.masksToBounds = true
        mView.backgroundColor = .clear
        mView.isHidden = true
        return mView
    }()
    
    lazy var datePicker: UIDatePicker = {
        let datePicker = UIDatePicker.init()
        datePicker.locale = Locale(identifier: "zh_CN")
        datePicker.setValue(HexColor("#3C3C3C"), forKey: "textColor")
        datePicker.datePickerMode = .date
        datePicker.isHidden = true
        if #available(iOS 13.4, *) {
            datePicker.preferredDatePickerStyle = .wheels
        } else {
            // Fallback on earlier versions
        }
        if UserInfoManager.shared.userInfo.birthday.count > 0 {
            let dateFomatter = DateFormatter()
            dateFomatter.dateFormat = "yyyy-MM-dd"
            dateFomatter.locale = Locale.init(identifier: "zh_CN")
            let date = dateFomatter.date(from: UserInfoManager.shared.userInfo.birthday)
            datePicker.setDate(date!, animated: true)
        }
        datePicker.minimumDate = Date.init(timeIntervalSince1970: -60*60*24*365*60)
        datePicker.maximumDate = Date.init(timeInterval: 0, since: Date.init())
        datePicker.addTarget(self, action: #selector(dateChangeAction), for: .valueChanged)
        return datePicker
    }()
    
    lazy var nameLable : UILabel = {
        let nameLable = UILabel.init()
        nameLable.backgroundColor = .white
        nameLable.font = BoldFont_16_Fit
        nameLable.textAlignment  = .center
        nameLable.textColor = .black
        return nameLable
    }()
    
    lazy var lineLable : UILabel = {
        let lineLable = UILabel.init()
        lineLable.backgroundColor = HexColor("#E6E6E6")
        return lineLable
    }()
    
    lazy var doneButton : UIButton = {
        let doneButton = UIButton(type: .custom)
        doneButton.setTitle("确定", for: .normal)
        doneButton.setTitleColor(HexColor("#0066FE"), for: .normal)
        doneButton.titleLabel?.font = Font_16
        doneButton.addTarget(self, action: #selector(setupDoneButtonAction), for: .touchUpInside)
        return doneButton
    }()
    
    lazy var closeButton : UIButton = {
        let closeButton = UIButton(type: .custom)
        closeButton.setImage(UIImage(named: "login_alert_country_close"), for: .normal)
        closeButton.backgroundColor = .clear
        closeButton.addTarget(self, action: #selector(setupCloseButtonAction), for: .touchUpInside)
        return closeButton
    }()
    
    var gender: String? = UserInfoManager.shared.userInfo.gender
    var birthday: String? = UserInfoManager.shared.userInfo.birthday
    var result: CloseGenderResultBlock?
    var type: CNLiveMineRequestType?
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        addSubview(grayMaskView)
        addSubview(backView)
        backView.addSubview(datePicker)
        backView.addSubview(contentView)
        contentView.addSubview(wBtn)
        contentView.addSubview(mBtn)
        contentView.addSubview(wLabel)
        contentView.addSubview(mLabel)
        contentView.addSubview(wView)
        contentView.addSubview(mView)
        backView.addSubview(nameLable)
        backView.addSubview(lineLable)
        backView.addSubview(closeButton)
        backView.addSubview(doneButton)

        wBtn.isSelected = UserInfoManager.shared.userInfo.gender == "男"
        mBtn.isSelected = UserInfoManager.shared.userInfo.gender == "女"
        if UserInfoManager.shared.userInfo.gender != "未知" {
            mView.isHidden = UserInfoManager.shared.userInfo.gender == "男"
            wView.isHidden = UserInfoManager.shared.userInfo.gender == "女"
        }

        setConstraints()
    }
    
    func setConstraints() {
        grayMaskView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        backView.snp.makeConstraints { make in
            make.top.equalTo(self.snp.bottom).offset(0)
            make.left.right.equalToSuperview()
            make.height.equalTo(250)
        }
        doneButton.snp.makeConstraints { make in
            make.right.equalToSuperview()
            make.top.equalTo(10)
            make.height.equalTo(30)
            make.width.equalTo(60)
        }
        closeButton.snp.makeConstraints { make in
            make.centerY.equalTo(doneButton)
            make.left.equalTo(8)
            make.size.equalTo(30)
        }
        nameLable.snp.makeConstraints { make in
            make.centerY.equalTo(doneButton)
            make.centerX.equalToSuperview()
        }
        lineLable.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.height.equalTo(1)
            make.top.equalTo(doneButton.snp.bottom).offset(10)
        }
        datePicker.snp.makeConstraints { make in
            make.bottom.equalToSuperview()
            make.left.right.equalToSuperview()
            make.top.equalTo(lineLable.snp.bottom)
        }
        contentView.snp.makeConstraints { make in
            make.bottom.equalToSuperview()
            make.left.right.equalToSuperview()
            make.top.equalTo(lineLable.snp.bottom)
        }
        mBtn.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-(KSreenWidth - 160)/3)
            make.size.equalTo(80)
        }
        wBtn.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset((KSreenWidth - 160)/3)
            make.size.equalTo(80)
        }
        mLabel.snp.makeConstraints { make in
            make.centerX.equalTo(wBtn)
            make.top.equalTo(wBtn.snp.bottom).offset(10)
        }
        wLabel.snp.makeConstraints { make in
            make.centerX.equalTo(mBtn)
            make.top.equalTo(mBtn.snp.bottom).offset(10)
        }
        mView.snp.makeConstraints { make in
            make.centerX.equalTo(mBtn)
            make.bottom.equalTo(mBtn.snp.bottom).offset(8)
            make.size.equalTo(16)
        }
        wView.snp.makeConstraints { make in
            make.centerX.equalTo(wBtn)
            make.bottom.equalTo(wBtn.snp.bottom).offset(8)
            make.size.equalTo(16)
        }

    }
    
    static public func showSelectView(showType: CNLiveMineRequestType, result: @escaping CloseGenderResultBlock){
        let pickerView = MineInfoAlertView()
        pickerView.result = result
        pickerView.type = showType
        switch showType {
        case .gender:
            pickerView.nameLable.text = "设置性别"
            pickerView.contentView.isHidden = false
            pickerView.datePicker.isHidden = true
        case .birthday:
            pickerView.nameLable.text = "选择生日"
            pickerView.contentView.isHidden = true
            pickerView.datePicker.isHidden = false
            pickerView.birthday = UserInfoManager.shared.userInfo.birthday
        case .nickName:
            break
        case .email:
            break
        case .location:
            break
        case .icon:
            break
        case .other:
            break
        }
        
        let window = UIApplication.shared.windows.last
        window?.addSubview(pickerView)
        pickerView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        window?.layoutIfNeeded()
        pickerView.alpha = 0
        UIView.animate(withDuration: 0.1) {
            pickerView.alpha = 1
        } completion: { _ in
            UIView.animate(withDuration: 0.1) {
                pickerView.backView.snp.updateConstraints { make in
                    make.top.equalTo(pickerView.snp.bottom).offset(-pickerView.backView.frame.height)
                }
                pickerView.layoutIfNeeded()
            }
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    @objc func dateChangeAction(sender: UIDatePicker) {
        let formatter = DateFormatter()
        formatter.dateFormat = "yyyy-MM-dd"
        birthday = formatter.string(from: datePicker.date)
    }
    
    @objc func setupDoneButtonAction() {
        print("进行更改\(gender ?? "")")
        removeFromSuperview()
        var value = ""
        if type == .birthday {
            value = birthday ?? ""
        }
        if type == .gender {
            value = gender ?? ""
        }
        CNLiveMineViewModel.requestUpdateUserInfoAction(type: type!, value: value) { [self] type, statue in
            if statue {
                let userInfo = UserInfoManager.shared.userInfo
                if type == .gender {
                    userInfo.gender = (value  == "m" ? "男" : "女")
                }
                if type == .birthday {
                    userInfo.birthday = value
                    print("存储到本地的数据是=>\(userInfo.birthday)")
                }
                UserInfoManager.cacheUserInfo(userInfo: userInfo)
                result!(value)
            }
        }
    }
    
    @objc func setupCloseButtonAction() -> Void {
        removeFromSuperview()
    }
    
    @objc func mClickAction(sender: UIButton) {
        sender.isSelected = !sender.isSelected
        wBtn.isSelected = !sender.isSelected
        mView.isHidden = !sender.isSelected
        wView.isHidden = sender.isSelected
        gender = "f"
    }
    
    @objc func wClickAction(sender: UIButton) {
        sender.isSelected = !sender.isSelected
        mBtn.isSelected = !sender.isSelected
        wView.isHidden = !sender.isSelected
        mView.isHidden = sender.isSelected
        gender = "m"
    }
}


class UpdataAlertView: UIView {
    
    lazy var grayMaskView: UIView = {
       let grayMaskView = UIView()
       grayMaskView.backgroundColor = UIColor.black.withAlphaComponent(0.2)
       return grayMaskView
    }()
    
    lazy var backView: UIView = {
        let backView = UIView()
        backView.backgroundColor = .clear
        backView.layer.cornerRadius = 15
        backView.layer.masksToBounds = true
        return backView
    }()
    
    lazy var contentView : UIView = {
        let contentView = UIView.init()
        contentView.backgroundColor = .white
        contentView.layer.cornerRadius = 15
        contentView.clipsToBounds = true
        return contentView
    }()
    
    lazy var headerView: UIImageView = {
        let headerView = UIImageView.init()
        headerView.backgroundColor = .clear
        headerView.image = UIImage(named: "main_apper_alert_header_updata")
        headerView.contentMode = .scaleToFill
        return headerView
    }()
    
    lazy var versionLabel: UILabel = {
        let versionLabel = UILabel.init()
        versionLabel.backgroundColor = .clear
        versionLabel.textColor = .white
        versionLabel.font = BoldFont_18_Fit
        return versionLabel
    }()
    
    lazy var descLabel: UILabel = {
        let descLabel = UILabel.init()
        descLabel.textColor = HexColor("#333333")
        descLabel.font = Font_15
        descLabel.lineBreakMode = .byWordWrapping
        descLabel.numberOfLines = 0
        return descLabel
    }()
    
    lazy var updataButton: UIButton = {
        let updataButton = UIButton(type: .custom)
        updataButton.setTitle("立即更新", for: .normal)
        updataButton.setTitleColor(.white, for: .normal)
        updataButton.titleLabel?.font = BoldFont_16_Fit
        updataButton.layer.cornerRadius = 20
        updataButton.layer.masksToBounds = true
        updataButton.addTarget(self, action: #selector(sendLoginActionMothod), for: .touchUpInside)
        return updataButton
    }()
    
    lazy var cancelButton: UIButton = {
        let cancelButton = UIButton(type: .custom)
        cancelButton.setTitleColor(HexColor("#999999"), for: .normal)
        cancelButton.setTitle("下次再说", for: .normal)
        cancelButton.titleLabel?.font = Font_13
        cancelButton.backgroundColor = .white
        cancelButton.addTarget(self, action: #selector(setupCloseButtonAction), for: .touchUpInside)
        return cancelButton
    }()
    
    var _updateModel: UpdateInfoModel?
    init(frame: CGRect, updateModel: UpdateInfoModel) {
        super.init(frame: frame)
        
        _updateModel = updateModel
        addSubview(grayMaskView)
        addSubview(backView)
        backView.addSubview(headerView)
        headerView.addSubview(versionLabel)
        backView.addSubview(contentView)
        contentView.addSubview(descLabel)
        contentView.addSubview(updataButton)
        contentView.addSubview(cancelButton)
        
        cancelButton.isHidden = ((_updateModel?.isForce) == nil)
        versionLabel.text = updateModel.version
        
        let paraph = NSMutableParagraphStyle()
        paraph.lineSpacing = 10
        let attributes = [NSAttributedString.Key.font:Font_16_Fit,
                          NSAttributedString.Key.paragraphStyle: paraph]
        descLabel.attributedText = NSAttributedString(string: updateModel.upgradePoint, attributes: attributes)
        
        
        setConstraints()
    }
    
    func setConstraints() {
        grayMaskView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        backView.snp.makeConstraints { make in
            make.center.equalToSuperview()
            make.width.equalTo(KSreenWidth - 60)
            make.height.equalTo((KSreenWidth - 60) * 1.4)
        }
        headerView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.left.right.equalToSuperview()
            make.height.equalTo(200)
        }
        versionLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(23)
            make.bottom.equalToSuperview().offset(-55)
        }
        contentView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(headerView.snp.bottom).offset(-15)
            make.left.right.equalToSuperview()
            make.height.equalTo((KSreenWidth - 60) * 1.4 - 185)
        }
        descLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(45)
            make.left.equalToSuperview().offset(20)
            make.right.equalToSuperview().offset(-20)
        }
        cancelButton.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.bottom.equalToSuperview().offset(-20)
            make.width.equalTo(KSreenWidth - 100)
            make.height.equalTo(20)
        }
        updataButton.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            if ((_updateModel?.isForce) == nil) {
                make.bottom.equalToSuperview().offset(-30)
            } else {
                make.bottom.equalToSuperview().offset(-50)
            }
            make.left.equalToSuperview().offset(30)
            make.right.equalToSuperview().offset(-30)
            make.height.equalTo(40)
        }

        updataButton.setGradient(colors: [UIColor(red: 103/255.0, green: 197/255.0, blue: 255/255.0, alpha: 1),UIColor(red: 96/255.0, green: 154/255.0, blue: 255/255.0, alpha: 1)], startPoint: CGPoint(x: 0, y: 0.5), endPoint: CGPoint(x: 1, y: 0.5))
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    static public func showUpdataView(updataModel: UpdateInfoModel){
        
        let updateView = UpdataAlertView(frame: .zero, updateModel: updataModel)
        
        let window = UIApplication.shared.windows.last
        window?.addSubview(updateView)
        updateView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        window?.layoutIfNeeded()
        updateView.alpha = 0
        UIView.animate(withDuration: 0.1) {
            updateView.alpha = 1
        }
    }
    
    
    @objc func sendLoginActionMothod() -> Void {
        print("跳转到appstore")
        ConfigManager.shared.show_update = false
        showMessage(message: "跳转到AppStore")
    }
    
    @objc func setupCloseButtonAction() -> Void {
        ConfigManager.shared.show_update = false
        removeFromSuperview()
    }
}


enum CNLiveStandListAlertShowType {
    case custom
    case text
    case date
}
class MineStandListAlertView: UIView, UIPickerViewDelegate, UIPickerViewDataSource {
    
    lazy var tapGesture = UITapGestureRecognizer()
    lazy var grayMaskView: UIView = {
       let grayMaskView = UIView()
       tapGesture.addTarget(self, action: #selector(setupCloseButtonAction))
       grayMaskView.backgroundColor = UIColor.black.withAlphaComponent(0.2)
       grayMaskView.addGestureRecognizer(tapGesture)
       return grayMaskView
    }()
    
    lazy var backView: UIView = {
        let backView = UIView()
        backView.backgroundColor = UIColor.white
        backView.layer.cornerRadius = 12
        return backView
    }()
    
    lazy var pickerView: UIPickerView = {
        let pickerView = UIPickerView.init()
        pickerView.backgroundColor = .white
        pickerView.delegate = self
        pickerView.dataSource = self
        pickerView.isHidden = true
        if !(_show_type == .custom) || !(_show_type == .text) {
            pickerView.isHidden = false
        }
        
        return pickerView
    }()
    
    lazy var datePicker: UIDatePicker = {
        let datePicker = UIDatePicker.init()
        datePicker.locale = Locale(identifier: "zh_CN")
        datePicker.setValue(HexColor("#3C3C3C"), forKey: "textColor")
        datePicker.datePickerMode = .date
        datePicker.isHidden = !(_show_type == .date)
        if #available(iOS 13.4, *) {
            datePicker.preferredDatePickerStyle = .wheels
        } else {
            // Fallback on earlier versions
        }
        if UserInfoManager.shared.userInfo.birthday.count > 0 {
            let dateFomatter = DateFormatter()
            dateFomatter.dateFormat = "yyyy-MM-dd"
            dateFomatter.locale = Locale.init(identifier: "zh_CN")
            let date = dateFomatter.date(from: UserInfoManager.shared.userInfo.birthday)
            datePicker.setDate(date!, animated: true)
        }
        datePicker.minimumDate = Date.init(timeIntervalSince1970: -60*60*24*365*60)
        datePicker.maximumDate = Date.init(timeInterval: 60*60*24*365*10, since: Date.init())
        datePicker.addTarget(self, action: #selector(dateChangeAction), for: .valueChanged)
        return datePicker
    }()
    
    lazy var nameLable : UILabel = {
        let nameLable = UILabel.init()
        nameLable.backgroundColor = .white
        nameLable.font = BoldFont_16_Fit
        nameLable.textAlignment  = .center
        nameLable.textColor = .black
        return nameLable
    }()
    
    lazy var lineLable : UILabel = {
        let lineLable = UILabel.init()
        lineLable.backgroundColor = HexColor("#E6E6E6")
        return lineLable
    }()
    
    lazy var doneButton : UIButton = {
        let doneButton = UIButton(type: .custom)
        doneButton.setTitle("确定", for: .normal)
        doneButton.setTitleColor(HexColor("#0066FE"), for: .normal)
        doneButton.titleLabel?.font = Font_16
        doneButton.addTarget(self, action: #selector(setupDoneButtonAction), for: .touchUpInside)
        return doneButton
    }()
    
    lazy var closeButton : UIButton = {
        let closeButton = UIButton(type: .custom)
        closeButton.setTitle("取消", for: .normal)
        closeButton.setTitleColor(HexColor("#B4B4B4"), for: .normal)
        closeButton.titleLabel?.font = Font_16
        closeButton.addTarget(self, action: #selector(setupCloseButtonAction), for: .touchUpInside)
        return closeButton
    }()
    
    var text: Any?
    var _infos: NSArray?
    var _show_type: CNLiveStandListAlertShowType?
    var result: CloseGenderResultBlock?
    init(frame: CGRect, infos: NSArray, show_type: CNLiveStandListAlertShowType) {
        super.init(frame: frame)
        
        _infos = infos
        _show_type = show_type//56842.5+7840.34
        if _show_type == .custom {
            text = (infos.firstObject as! MineStandInfoModel).name
        } else if _show_type == .text {
            text = infos.firstObject as? Dictionary<String, String>
        }else{
            let formatter = DateFormatter()
            formatter.dateFormat = "yyyy-MM-dd"
            text = formatter.string(from: datePicker.date)
        }
        
        
        addSubview(grayMaskView)
        addSubview(backView)
        backView.addSubview(pickerView)
        backView.addSubview(datePicker)
        backView.addSubview(nameLable)
        backView.addSubview(lineLable)
        backView.addSubview(closeButton)
        backView.addSubview(doneButton)
        setConstraints()
    }
    
    func setConstraints() {
        grayMaskView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        backView.snp.makeConstraints { make in
            make.top.equalTo(self.snp.bottom).offset(0)
            make.left.right.equalToSuperview()
            make.height.equalTo(250)
        }
        doneButton.snp.makeConstraints { make in
            make.right.equalToSuperview()
            make.top.equalTo(10)
            make.height.equalTo(30)
            make.width.equalTo(60)
        }
        closeButton.snp.makeConstraints { make in
            make.centerY.equalTo(doneButton)
            make.left.equalTo(8)
            make.height.equalTo(30)
            make.width.equalTo(60)
        }
        nameLable.snp.makeConstraints { make in
            make.centerY.equalTo(doneButton)
            make.centerX.equalToSuperview()
        }
        lineLable.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.height.equalTo(1)
            make.top.equalTo(doneButton.snp.bottom).offset(10)
        }
        pickerView.snp.makeConstraints { make in
            make.bottom.equalToSuperview()
            make.left.right.equalToSuperview()
            make.top.equalTo(lineLable.snp.bottom)
        }
        datePicker.snp.makeConstraints { make in
            make.bottom.equalToSuperview()
            make.left.right.equalToSuperview()
            make.top.equalTo(lineLable.snp.bottom)
        }
    }
    
    static public func showStandListView(infos: NSArray, name: String, show_type: CNLiveStandListAlertShowType, result: @escaping CloseGenderResultBlock) {
        let pickerView = MineStandListAlertView.init(frame: .zero, infos: infos, show_type: show_type)
        pickerView.result = result
        pickerView.nameLable.text = name
        let window = UIApplication.shared.windows.last
        window?.addSubview(pickerView)
        pickerView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        window?.layoutIfNeeded()
        pickerView.alpha = 0
        UIView.animate(withDuration: 0.1) {
            pickerView.alpha = 1
        } completion: { _ in
            UIView.animate(withDuration: 0.1) {
                pickerView.backView.snp.updateConstraints { make in
                    make.top.equalTo(pickerView.snp.bottom).offset(-pickerView.backView.frame.height)
                }
                pickerView.layoutIfNeeded()
            }
        }
    }
    
    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 1
    }
    
    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return _infos?.count ?? 0
    }
    
    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        if _show_type == .custom {
            let infoModel = _infos![row] as! MineStandInfoModel
            return infoModel.name
        }
        if _show_type == .text {
            let dict = _infos![row] as? Dictionary<String, String>
            return dict?["title"] ?? ""
        }
        return ""
    }
    
    func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
        return 45.0
    }
    
    func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        if _show_type == .custom {
            let infoModel = _infos![row] as! MineStandInfoModel
            text = infoModel.name ?? ""
        }
        if _show_type == .text {
            text = _infos![row] as? Dictionary<String, String>
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    @objc func setupCloseButtonAction() -> Void {
        removeFromSuperview()
    }
    
    @objc func setupDoneButtonAction() -> Void {
        removeFromSuperview()
        if (result != nil) {
            result!(text ?? "")
        }
    }
    
    @objc func dateChangeAction(sender: UIDatePicker) {
        let formatter = DateFormatter()
        formatter.dateFormat = "yyyy-MM-dd"
        let date = formatter.string(from: datePicker.date)
        print("获取到的时间是:\(date)")
        text = date
    }
}