CNLiveMineHeaderView.swift 17 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
//
//  CNLiveMineHeaderView.swift
//  metaCode
//
//  Created by open on 2023/6/7.
//

import Foundation
import HXPHPicker
import Kingfisher

class MineHeaderView : UIView {
    
    lazy var iconView : UIImageView = {
       
        let iconView = UIImageView.init()
        iconView.image = UIImage(named: "mine_header_icon_defult_ava")
        iconView.backgroundColor = .clear
        iconView.layer.cornerRadius = 30
        iconView.layer.masksToBounds = true
        iconView.contentMode = .scaleAspectFill
        iconView.isUserInteractionEnabled = true
        let tap = UITapGestureRecognizer.init(target: self, action: #selector(pushMineInfoAction))
        iconView.addGestureRecognizer(tap)
        return iconView
    }()
    
    lazy var nameLabel: UILabel = {
        let nameLabel = UILabel.init()
        nameLabel.textColor = .white
        nameLabel.font = Font_16
        return nameLabel
    }()
    
    lazy var tipBtn: UIButton = {
        let tipBtn = UIButton(type: .custom)
        tipBtn.backgroundColor = .clear
        tipBtn.setImage(UIImage(named: "mine_header_icon_notice"), for: .normal)
        tipBtn.imageView?.contentMode = .scaleToFill
        tipBtn.addTarget(self, action: #selector(tipBtnAction), for: .touchUpInside)
        return tipBtn
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = .clear
        
        addSubview(iconView)
        iconView.snp.makeConstraints { make in
            make.centerY.equalToSuperview().offset(10)
            make.left.equalToSuperview().offset(20)
            make.size.equalTo(60)
        }
        addSubview(nameLabel)
        nameLabel.snp.makeConstraints { make in
            make.centerY.equalToSuperview().offset(10)
            make.left.equalTo(iconView.snp.right).offset(15)
        }
        addSubview(tipBtn)
        tipBtn.snp.makeConstraints { make in
            make.centerY.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-15)
            make.size.equalTo(30)
        }
        updateHeaderView()
    }
    
    public func updateHeaderView() {
        iconView.kf.indicatorType = .activity
        iconView.kf.setImage(with: URL(string: UserInfoManager.shared.userInfo.bigFaceUrl), placeholder: UIImage(named: "mine_header_icon_defult_ava"))
        nameLabel.text = UserInfoManager.shared.userInfo.nickName
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    @objc func tipBtnAction() {
        currentViewController()?.navigationController?.pushViewController(CNLiveMineAddInfoViewController.init(show_type: .message), animated: true)
    }
    
    @objc func pushMineInfoAction() {
        currentViewController()?.navigationController?.pushViewController(CNLiveTypeFeedBackViewController.init(show_type: .info), animated: true)
    }
}

class MineAboutHeaderView: UIView {
    
    lazy var iconView: UIImageView = {
        let iconView = UIImageView.init()
        iconView.image = UIImage(named: "mine_sub_about_app_logo")
        iconView.contentMode = .scaleToFill
        iconView.backgroundColor = .clear
        return iconView
    }()
    
    lazy var nameLabel: UILabel = {
        let nameLabel = UILabel.init()
        nameLabel.text = "\(kAppDisplayName)"
        nameLabel.textColor = HexColor("#333333")
        nameLabel.font = BoldFont_18_Fit
        nameLabel.textAlignment = .center
        return nameLabel
    }()
    
    lazy var verLabel: UILabel = {
        let verLabel = UILabel.init()
        verLabel.text = "YUANMA\(kAppVersion)"
        verLabel.textColor = HexColor("#333333")
        verLabel.font = Font_16_Fit
        verLabel.textAlignment = .center
        return verLabel
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(verLabel)
        
        iconView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(60)
            make.size.equalTo(80)
        }
        nameLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(iconView.snp.bottom).offset(8)
        }
        verLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(nameLabel.snp.bottom).offset(8)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}


typealias ClickResultBlock = (_ index: String,_ imageUrl: String) ->Void
class MinePhotoUploadView: UIView, PhotoPickerControllerDelegate {
    
    lazy var imageView01: UIImageView = {
        let imageView = UIImageView.init()
        imageView.backgroundColor = .white
        imageView.image = UIImage(named: "mine_sub_quest_addd_image")
        imageView.contentMode = .scaleAspectFill
        imageView.isUserInteractionEnabled = true
        imageView.tag = 1000
        imageView.layer.cornerRadius = 7
        imageView.layer.masksToBounds = true
        imageView.clipsToBounds = true
        let tapGes = UITapGestureRecognizer.init(target: self, action: #selector(touchImageAction))
        imageView.addGestureRecognizer(tapGes)
        return imageView
    }()
    
    lazy var imageView02: UIImageView = {
        let imageView = UIImageView.init()
        imageView.backgroundColor = .white
        imageView.image = UIImage(named: "mine_sub_quest_addd_image")
        imageView.contentMode = .scaleAspectFill
        imageView.isUserInteractionEnabled = true
        imageView.tag = 1001
        imageView.isHidden = true
        imageView.clipsToBounds = true
        imageView.layer.cornerRadius = 7
        imageView.layer.masksToBounds = true
        let tapGes = UITapGestureRecognizer.init(target: self, action: #selector(touchImageAction))
        imageView.addGestureRecognizer(tapGes)
        return imageView
    }()
    
    lazy var imageView03: UIImageView = {
        let imageView = UIImageView.init()
        imageView.backgroundColor = .white
        imageView.image = UIImage(named: "mine_sub_quest_addd_image")
        imageView.contentMode = .scaleAspectFill
        imageView.isUserInteractionEnabled = true
        imageView.tag = 1002
        imageView.isHidden = true
        imageView.clipsToBounds = true
        imageView.layer.cornerRadius = 7
        imageView.layer.masksToBounds = true
        let tapGes = UITapGestureRecognizer.init(target: self, action: #selector(touchImageAction))
        imageView.addGestureRecognizer(tapGes)
        return imageView
    }()
    
    lazy var temp_imageView : UIImageView = {
        return UIImageView.init()
    }()
    
    lazy var selectedImages: NSMutableArray = {
        let tempArrray = NSMutableArray.init()
        tempArrray.addObjects(from: ["","",""])
        return tempArrray
    }()
    
    
    var _resutBlock : ClickResultBlock?
    init(frame: CGRect, resutBlock: @escaping ClickResultBlock) {
        super.init(frame: frame)
        backgroundColor = .white
        
        _resutBlock = resutBlock
        addSubview(imageView01)
        imageView01.snp.makeConstraints { make in
            make.size.height.equalTo((KSreenWidth - 40)/3)
            make.top.equalToSuperview()
            make.left.equalToSuperview().offset(10)
        }
        addSubview(imageView02)
        imageView02.snp.makeConstraints { make in
            make.top.equalToSuperview()
            make.size.height.equalTo((KSreenWidth - 40)/3)
            make.size.width.equalTo(imageView02)
            make.left.equalTo(imageView01.snp.right).offset(10)
        }
        addSubview(imageView03)
        imageView03.snp.makeConstraints { make in
            make.size.height.equalTo((KSreenWidth - 40)/3)
            make.size.width.equalTo(imageView02)
            make.top.equalToSuperview()
            make.right.equalToSuperview().offset(-10)
            make.left.equalTo(imageView02.snp.right).offset(10)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    @objc private func touchImageAction(ges: UITapGestureRecognizer) {
        temp_imageView = ges.view as! UIImageView
        if selectedImages.object(at: temp_imageView.tag - 1000) is String {
            let config = PhotoTools.getWXPickerConfig()
            config.selectMode = .single
            config.selectOptions = .photo
            config.maximumSelectedPhotoCount = 3
            let pickerController = PhotoPickerController(picker: config)
            pickerController.pickerDelegate = self
            pickerController.isOriginal = false
            currentViewController()!.present(pickerController, animated: true, completion: nil)
        }
    }
}

extension MinePhotoUploadView {
    
    func pickerController(_ pickerController: PhotoPickerController,
                            didFinishSelection result: PickerResult) {
        result.getImage { [weak self] (image, photoAsset, index) in
            if let image = image {
                self!.temp_imageView.image = image
                if self!.temp_imageView == self!.imageView01 {
                    UploadManager.uploadImage(imageData: image.jpegData(compressionQuality: 1.0)! as NSData, progressBlock: {key, progress in
                        print("获取进度==>\(progress)")
                    }, successBlock: { [weak self] key,url in
                        self!.imageView02.isHidden = false
                        self!.selectedImages.replaceObject(at: 0, with: image)
                        self!._resutBlock!("1",url)
                    })
                }
                if self!.temp_imageView == self!.imageView02 {
                    UploadManager.uploadImage(imageData: image.jpegData(compressionQuality: 1.0)! as NSData, progressBlock: {key, progress in
                        print("获取进度==>\(progress)")
                    }, successBlock: { [weak self] key,url in
                        self!.imageView03.isHidden = false
                        self!.selectedImages.replaceObject(at: 1, with: image)
                        self!._resutBlock!("2",url)
                    })
                }
                if self!.temp_imageView == self!.imageView03 {
                    UploadManager.uploadImage(imageData: image.jpegData(compressionQuality: 1.0)! as NSData, progressBlock: {key, progress in
                        print("获取进度==>\(progress)")
                    }, successBlock: { [weak self] key,url in
                        self!.selectedImages.replaceObject(at: 2, with: image)
                        self!._resutBlock!("3",url)
                    })
                }
            }else {
                print("failed")
            }
        } completionHandler: { (images) in

        }
    }
}


class MineQuestHeaderView: UIView {
    
    lazy var mainView: UIImageView = {
        let mainView = UIImageView.init()
        mainView.image = UIImage(named: "mine_header_quest_back")
        mainView.clipsToBounds = true
        mainView.backgroundColor = .clear
        mainView.layer.cornerRadius = 10
        mainView.layer.masksToBounds = true
        mainView.isUserInteractionEnabled = true
        return mainView
    }()
    
    lazy var pointBtn: UIButton = {
        let pointBtn = UIButton(type: .custom)
        pointBtn.size = CGSize(width: 72, height: 20)
        pointBtn.backgroundColor = .clear
        pointBtn.setTitle("积分收益", for: .normal)
        pointBtn.setTitleColor(.white, for: .normal)
        pointBtn.setImage(UIImage(named: "mine_list_icon_right_white_more"), for: .normal)
        pointBtn.titleLabel?.font = Font_15
        pointBtn.setupButtonImageAndTitlePossitionWith(padding: 0, style: .right)
        pointBtn.addTarget(self, action: #selector(pushEarnRecordAction), for: .touchUpInside)
        return pointBtn
    }()
    
    lazy var balanceBtn: UIButton = {
        let balanceBtn = UIButton(type: .custom)
        balanceBtn.size = CGSize(width: 102, height: 20)
        balanceBtn.backgroundColor = .clear
        balanceBtn.setTitle("元码余额收益", for: .normal)
        balanceBtn.setTitleColor(.white, for: .normal)
        balanceBtn.setImage(UIImage(named: "mine_list_icon_right_white_more"), for: .normal)
        balanceBtn.titleLabel?.font = Font_15
        balanceBtn.setupButtonImageAndTitlePossitionWith(padding: 0, style: .right)
        balanceBtn.addTarget(self, action: #selector(pushEarnBalanceAction), for: .touchUpInside)
        return balanceBtn
    }()
    
    lazy var pointLabel: UILabel = {
        let pointLabel = UILabel.init()
        pointLabel.text = "10.28W"
        pointLabel.textColor = .white
        pointLabel.backgroundColor = .clear
        pointLabel.font = BoldFont_25_Fit
        return pointLabel
    }()
    
    lazy var balanceLabel: UILabel = {
        let balanceLabel = UILabel.init()
        balanceLabel.text = "3.15"
        balanceLabel.textColor = .white
        balanceLabel.backgroundColor = .clear
        balanceLabel.font = BoldFont_25_Fit
        return balanceLabel
    }()
    
    lazy var descBtn: UIButton = {
        let descBtn = UIButton.init(type: .custom)
        descBtn.setTitle("您可随时将积分兑换成元码余额", for: .normal)
        descBtn.setTitleColor(.white, for: .normal)
        descBtn.setImage(UIImage(named: "mine_header_quest_tip"), for: .normal)
        descBtn.titleLabel?.font = Font_11
        descBtn.setupButtonImageAndTitlePossitionWith(padding: 3, style: .left)
        return descBtn
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = .clear
        
        addSubview(mainView)
        mainView.addSubview(pointBtn)
        mainView.addSubview(balanceBtn)
        mainView.addSubview(pointLabel)
        mainView.addSubview(balanceLabel)
        mainView.addSubview(descBtn)
        
        setupConstraints()
    }
    
    func setupConstraints() {
        
        mainView.snp.makeConstraints { make in
            make.center.equalToSuperview()
            make.left.right.equalToSuperview()
            make.top.equalToSuperview().offset(10)
            make.bottom.equalToSuperview().offset(-10)
        }
        pointBtn.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(15)
            make.top.equalToSuperview().offset(15)
        }
        balanceBtn.snp.makeConstraints { make in
            make.centerX.equalToSuperview().offset(50)
            make.top.equalToSuperview().offset(15)
        }
        pointLabel.snp.makeConstraints { make in
            make.left.equalTo(pointBtn.snp.left)
            make.top.equalTo(pointBtn.snp.bottom).offset(10)
        }
        balanceLabel.snp.makeConstraints { make in
            make.left.equalTo(balanceBtn.snp.left)
            make.top.equalTo(balanceBtn.snp.bottom).offset(10)
        }
        descBtn.snp.makeConstraints { make in
            make.left.equalTo(pointBtn.snp.left)
            make.bottom.equalToSuperview().offset(-15)
            make.width.equalTo(180)
        }
    }
    
    @objc func pushEarnRecordAction() {
        currentViewController()?.navigationController?.pushViewController(CNLiveMineEarnViewController.init(index: 1), animated: true)
    }
    
    @objc func pushEarnBalanceAction() {
        currentViewController()?.navigationController?.pushViewController(CNLiveMineEarnViewController.init(index: 0), animated: true)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}



class MineEarnHeaderView: UIView {
    
    lazy var mainView: UIView = {
        let mainView = UIView.init()
        mainView.backgroundColor = .white
        mainView.layer.cornerRadius = 10
        mainView.layer.masksToBounds = true
        return mainView
    }()
    
    lazy var exChangeBtn : UIButton = {
        let exChangeBtn = UIButton.init(type: .custom)
        exChangeBtn.backgroundColor = .blue
        exChangeBtn.setTitle("去兑换", for: .normal)
        exChangeBtn.addTarget(self, action: #selector(pushExChangeMethod), for: .touchUpInside)
        return exChangeBtn
    }()
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        addSubview(mainView)
        mainView.addSubview(exChangeBtn)
        
        setupConstraints()
    }
    
    func setupConstraints() {
        mainView.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(10)
            make.bottom.equalToSuperview().offset(-10)
            make.left.equalToSuperview().offset(20)
            make.right.equalToSuperview().offset(-20)
        }
        exChangeBtn.snp.makeConstraints { make in
            make.center.equalToSuperview()
            make.height.equalTo(50)
            make.width.equalTo(100)
        }
    }
    
    @objc func pushExChangeMethod() {
        currentViewController()?.navigationController?.pushViewController(CNLiveMineExchangeViewController.init(), animated: true)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}