iOS_YIJIANLIAN/oneTouch/ONETHuoDongVC.swift

397 lines
15 KiB
Swift

//
// ONETHuoDongVC.swift
// oneTouch
//
// Created by gz on 2025/11/24.
//
import UIKit
import HandyJSON
import Alamofire
import MBProgressHUD
import SDCycleScrollView
class ONETHuoDongVC: UIViewController ,UITableViewDataSource, UITableViewDelegate{
@IBOutlet weak var topONETAcTitle: UILabel!
public lazy var activityONETtbView : UITableView = {
let tableView = UITableView(frame: CGRect.zero, style: .plain)
tableView.dataSource = self
tableView.delegate = self
tableView.separatorStyle = .none
tableView.rowHeight = 132
tableView.showsVerticalScrollIndicator = false
tableView.backgroundColor = .clear
let tableViewcellNib = UINib(nibName: "ONETHuoDongCell", bundle: nil)
tableView.register (tableViewcellNib, forCellReuseIdentifier: "ONETHuoDongCell")
return tableView
}()
var activityONETArr : [activityONETMainChildLmModel]?
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(activityONETtbView)
activityONETtbView.snp.makeConstraints { make in
make.top.equalTo(topONETAcTitle.snp_bottomMargin).offset(10)
make.left.right.bottom.equalToSuperview()
}
let param: Parameters = ["phoneNumber": UserDefaults.standard.string(forKey: "saveusrONEname") ?? "","phToken": UserDefaults.standard.string(forKey: "PhONEToken") ?? "","pageNum":"1","pageSize":"10","clientTypeArray":"2"]
AF.request(self.currentONEHostApi() + "vpn/getActivity",method: .post,parameters: param).responseString { resultDic in
switch resultDic.result {
case .success(let value):
if let modelDic = JSONDeserializer<activityONETModel>
.deserializeFrom(json: value) {
if modelDic.code == 200 {
self.activityONETArr = modelDic.data?.data?.list
self.activityONETtbView.reloadData()
}
else{
self.showONEHDView(modelDic.message ?? "获取活动失败")
}
}
else{
self.showONEHDView("获取活动失败")
}
case .failure(_):
self.showONEHDView("获取活动失败,请检查网络")
}
}
}
func showONEHDView(_ msg : String?){
let Onehud = MBProgressHUD.showAdded(to: view, animated: true)
Onehud.mode = .text
Onehud.detailsLabel.text = msg
Onehud.hide(animated: true, afterDelay:1.5)
}
func showONEhDProgreeView(_ msg : String? = nil){
let Onehud = MBProgressHUD.showAdded(to: view, animated: true)
Onehud.mode = .indeterminate
Onehud.label.text = msg
Onehud.hide(animated: true, afterDelay:5)
}
func hidehDHUD(){
MBProgressHUD.hide(for: self.view, animated: true)
}
func currentONEHostApi() -> String{
let LocalONEHostApi = "https://api.yijianlianjsq.com";//todo
if let hostONEApi = UserDefaults.standard.string(forKey: "currentONEHost") {
print("url等于\(hostONEApi)/netbarcloud/")
return "\(hostONEApi)/netbarcloud/"
} else {
let hostONEApi = LocalONEHostApi
UserDefaults.standard.setValue(hostONEApi, forKey: "currentONEHost")
print("url等于\(hostONEApi)/netbarcloud/")
return "\(hostONEApi)/netbarcloud/"
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.activityONETArr?.count ?? 0
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 132
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let activityONETCell: ONETHuoDongCell = tableView.dequeueReusableCell(withIdentifier: "ONETHuoDongCell") as! ONETHuoDongCell
activityONETCell.selectionStyle = .none
activityONETCell.sethuodongONETData(acONETmodel: self.activityONETArr?[indexPath.row])
return activityONETCell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let modelData = self.activityONETArr?[indexPath.row]
let activityONETCellStr = modelData?.redirectLink ?? ""
if activityONETCellStr.contains("BindAccount"){
if UserDefaults.standard.bool(forKey: "IsONEPerfect") {
let popONEView = ONETpopBPopView(frame: CGRect(x: 0, y: 0, width: 220, height: 190))
popONEView.didONEPhoneCallBack = {
let ONEvc = ONETBandInfoVC()
self.navigationController?.pushViewController(ONEvc, animated: true)
}
popONEView.didONEemilCallBack = {
let ONEvc = ONETBandInfoVC()
ONEvc.isONEPhoeType = false
self.navigationController?.pushViewController(ONEvc, animated: true)
}
let vProperty = FWPopupViewProperty()
vProperty.popupCustomAlignment = .center
vProperty.popupAnimationType = .position
vProperty.maskViewColor = UIColor(white: 0, alpha: 0.2)
vProperty.touchWildToHide = "1"
vProperty.popupViewEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
vProperty.animationDuration = 0.3
popONEView.vProperty = vProperty
popONEView.show()
}
else{
self.showONEHDView("已绑定")
}
}else if activityONETCellStr.contains("weekcharge"){
let NextONETVC = ONETApplePayVC()
NextONETVC.isHiddenBackBtn = 1
self.navigationController?.pushViewController(NextONETVC, animated: true)
}else if activityONETCellStr.contains("shareAction"){
let NextONETVC = ONETShareVC()
self.navigationController?.pushViewController(NextONETVC, animated: true)
}else{
UIPasteboard.general.string = UserDefaults.standard.string(forKey: "userONECommand") ?? ""
let popONEView = ONETAcKFopView(frame: CGRect(x: 15, y: 0, width: kScreenONEWidth - 30, height: 280))
popONEView.activityONETModel = modelData
let vProperty = FWPopupViewProperty()
vProperty.popupCustomAlignment = .center
vProperty.popupAnimationType = .position
vProperty.maskViewColor = UIColor(white: 0, alpha: 0.2)
vProperty.touchWildToHide = "1"
vProperty.popupViewEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
vProperty.animationDuration = 0.3
popONEView.vProperty = vProperty
popONEView.show()
}
}
@IBAction func backONETAction(_ sender: Any) {
self.navigationController?.popViewController(animated: true)
}
}
class ONETAcKFopView: FWPopupView {
@objc public var didONEPhoneCallBack: (()->Void)?
@objc public var didONEemilCallBack: (()->Void)?
private lazy var bgView: UIView = {
let v = UIView()
v.backgroundColor = .white
return v
}()
public var activityONETModel : activityONETMainChildLmModel?{
didSet{
activityONETTitle.text = activityONETModel?.title ?? ""
activityONETcontent.text = activityONETModel?.content ?? ""
activityONETredirectLink.text = "链接:\(activityONETModel?.redirectLink ?? "")"
activityONETrPassword.text = "领会员口令:\(UserDefaults.standard.string(forKey: "userONECommand") ?? "")(已复制,加群后发送)"
}
}
let activityONETTitle: UILabel = UIFactorONEyUtil.createONELabel("", fontSize: 20, textColor: .init("0x0073FF"), fontType: .OONEmedium,textAlignment: .center)
let activityONETcontent: UILabel = UIFactorONEyUtil.createONELabel("", fontSize: 16, textColor: .black)
let activityONETredirectLink: UILabel = UIFactorONEyUtil.createONELabel("", fontSize: 16, textColor: .black)
let activityONETrPassword: UILabel = UIFactorONEyUtil.createONELabel("", fontSize: 16, textColor: .black)
let activityONETrOKBut: UIButton = UIFactorONEyUtil.createONEButton("跳转", fontSize: 16, textColor: .white)
let activityONETrcancelBtn: UIButton = UIFactorONEyUtil.createONEButton("关闭", fontSize: 16, textColor: .init("0x0073FF"))
override init(frame: CGRect) {
super.init(frame: frame)
self.setUI()
}
@MainActor required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setUI() {
self.setCorner(radius:10)
self.addSubview(bgView)
self.bgView.addSubviews([self.activityONETTitle,self.activityONETcontent,self.activityONETredirectLink,self.activityONETrPassword,self.activityONETrOKBut,self.activityONETrcancelBtn])
self.bgView.layer.cornerRadius = 20
self.bgView.layer.masksToBounds = true
self.bgView.backgroundColor = .white
self.bgView.snp.makeConstraints { make in
make.left.right.top.bottom.equalToSuperview()
}
activityONETTitle.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.left.right.equalToSuperview().inset(15)
make.top.equalToSuperview().offset(25)
}
activityONETcontent.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.top.equalTo(activityONETTitle.snp_bottomMargin).offset(30)
make.left.right.equalToSuperview().inset(15)
}
activityONETredirectLink.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.top.equalTo(activityONETcontent.snp_bottomMargin).offset(30)
make.left.right.equalToSuperview().inset(15)
}
activityONETrPassword.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.top.equalTo(activityONETredirectLink.snp_bottomMargin).offset(30)
make.left.right.equalToSuperview().inset(15)
}
activityONETrOKBut.backgroundColor = .init("0x0073FF")
activityONETrOKBut.setBorderAndRadius(radius: 20, borderWidth: 0, color: .clear)
activityONETrOKBut.snp.makeConstraints { make in
make.right.equalToSuperview().offset(-25)
make.bottom.equalToSuperview().offset(-20)
make.size.equalTo(CGSize(width: 120, height: 40))
}
activityONETrcancelBtn.setBorderAndRadius(radius: 20, borderWidth: 1, color: .init("0x0073FF"))
activityONETrcancelBtn.snp.makeConstraints { make in
make.left.equalToSuperview().offset(25)
make.bottom.equalToSuperview().offset(-20)
make.size.equalTo(CGSize(width: 120, height: 40))
}
self.activityONETrOKBut.addTarget(self, action: #selector(bdONEPhoneAction), for: .touchUpInside)
self.activityONETrcancelBtn.addTarget(self, action: #selector(bdONEEmliAction), for: .touchUpInside)
}
@objc func bdONEPhoneAction(){
self.hide()
if let activityONETurl = URL(string: activityONETModel?.redirectLink ?? ""){
UIApplication.shared.open(activityONETurl, options: [:], completionHandler: nil)
}
}
@objc func bdONEEmliAction(){
self.hide()
}
}
class ActivityONETRechargePopView: FWPopupView, SDCycleScrollViewDelegate {
var cycONETActivityleScrollView: SDCycleScrollView!
public var didRechargeONETCallBack: ((activityONETMainChildLmModel)->Void)?
var activityONETImageArr : [String]?
public var activityONETList : [activityONETMainChildLmModel]? {
didSet {
self.activityONETImageArr = []
if activityONETList?.count ?? 0 > 0{
for item in activityONETList! {
if item.content?.count ?? 0 > 0{
self.activityONETImageArr?.append(item.content ?? "")
}
}
self.cycONETActivityleScrollView.imageURLStringsGroup = self.activityONETImageArr
}
}
}
@objc public var didONEPhoneCallBack: (()->Void)?
@objc public var didONEemilCallBack: (()->Void)?
private lazy var bgView: UIView = {
let v = UIView()
v.backgroundColor = .clear
return v
}()
let activityONETrcancelBtn: UIButton = UIFactorONEyUtil.createONEButton(normalImage: UIImage(named: "ONET_close_pop"))
override init(frame: CGRect) {
super.init(frame: frame)
self.setUI()
}
@MainActor required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setUI() {
self.addSubview(bgView)
self.bgView.snp.makeConstraints { make in
make.left.right.top.bottom.equalToSuperview()
}
cycONETActivityleScrollView = SDCycleScrollView(frame: CGRect(x: 0, y: 0, width: 300, height: 350))
// 2.
cycONETActivityleScrollView.delegate = self //
cycONETActivityleScrollView.autoScrollTimeInterval = 3.5 // 3
cycONETActivityleScrollView.pageControlBottomOffset = -10 // pageControl
cycONETActivityleScrollView.autoScroll = true //
cycONETActivityleScrollView.backgroundColor = .clear
cycONETActivityleScrollView.isUserInteractionEnabled = true
cycONETActivityleScrollView.bannerImageViewContentMode = .scaleAspectFit
cycONETActivityleScrollView.hidesForSinglePage = true
self.bgView.addSubviews([self.cycONETActivityleScrollView,self.activityONETrcancelBtn])
activityONETrcancelBtn.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.height.equalTo(40)
make.width.equalTo(40)
make.bottom.equalToSuperview()
}
self.activityONETrcancelBtn.addTarget(self, action: #selector(bdONEEmliAction), for: .touchUpInside)
}
@objc func bdONEEmliAction(){
self.hide()
}
func cycleScrollView(_ cycleScrollView: SDCycleScrollView!, didSelectItemAt index: Int) {
self.hide()
if self.activityONETList?.count == self.activityONETImageArr?.count{
print("点击了第 \(index) 张图片") //
self.didRechargeONETCallBack?(self.activityONETList![index])
}
}
}
class activityONETModel :HandyJSON{
required init() {
}
var message: String?
var code:Int?
var data:activityFirstChildONETModel?
}
class activityFirstChildONETModel : HandyJSON{
required init() {
}
var data:activitySecondMainChildONETModel?
}
class activitySecondMainChildONETModel : HandyJSON{
required init() {
}
var list:[activityONETMainChildLmModel]?
}
class activityONETMainChildLmModel : HandyJSON{
required init() {
}
var title: String?
var content: String?
var awardDay : Int?
var redirectLink: String?
}