//
|
// JoinMemberVC.swift
|
// WanPai
|
//
|
// Created by Robert on 2025/8/19.
|
//
|
|
import UIKit
|
|
class JoinMemberVC: BaseVC, UITableViewDelegate, UITableViewDataSource {
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
if let m = model {
|
return 1 + m.vipList[selectIndex].couponList.count + m.vipList[selectIndex].ticketList.count
|
}else{
|
return 0
|
}
|
}
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
if indexPath.row == 0 {
|
let cell = tableView.dequeueReusableCell(withIdentifier: "CouponCellThreeId", for: indexPath) as! CouponCellThree
|
cell.vipList = model?.vipList
|
cell.selectBlock = { index in
|
self.selectIndex = index
|
}
|
return cell
|
|
}else if indexPath.row > 0 && indexPath.row < ((model?.vipList[selectIndex].couponList.count ?? 0) + 1) {
|
let cell = tableView.dequeueReusableCell(withIdentifier: "_WelfareCouponsTCell", for: indexPath) as! WelfareCouponsTCell
|
// cell.moneyLab.text = model?.vipList[selectIndex].couponList[indexPath.row - 1].ruleModel?.deductionAmount
|
// cell.remarksLab.text = model?.vipList[selectIndex].couponList[indexPath.row - 1].ruleModel?.conditionalAmount
|
// cell.nameLab.text = model?.vipList[selectIndex].couponList[indexPath.row - 1].name
|
// cell.timeLab.text = "有效期至\(model?.vipList[selectIndex].couponList[indexPath.row - 1].effectiveTime ?? "")"
|
// cell.contentLab.text = model?.vipList[selectIndex].couponList[indexPath.row - 1].instructionsForUse
|
if let m = model?.vipList[selectIndex].couponList[indexPath.row - 1] {
|
cell.couponModel = m
|
}
|
|
return cell
|
}else{
|
let cell = tableView.dequeueReusableCell(withIdentifier: "CouponCellTwoId", for: indexPath) as! CouponCellTwo
|
let index = indexPath.row - ((model?.vipList[selectIndex].couponList.count ?? 0) + 1)
|
cell.nameLab.text = model?.vipList[selectIndex].ticketList[index].name
|
cell.timeLab.text = "领取后\(model?.vipList[selectIndex].ticketList[index].time ?? 0)有效"
|
cell.numberLab.text = "\(model?.vipList[selectIndex].ticketList[index].count ?? 0)张"
|
return cell
|
}
|
|
}
|
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
|
if indexPath.row == 0 {
|
return 295
|
|
}else if indexPath.row > 0 && indexPath.row < ((model?.vipList[selectIndex].couponList.count ?? 0) + 1) {
|
return 170
|
}else{
|
return 110
|
}
|
}
|
|
@IBOutlet weak var tabView: UITableView!
|
@IBOutlet weak var scrBackView: UIView!
|
var model: VipDataModel?
|
var selectIndex: Int = 0
|
|
@IBOutlet weak var headerImg: UIImageView!
|
@IBOutlet weak var memberLab: UILabel!
|
@IBOutlet weak var nameLab: UILabel!
|
var acceptXy: Bool = false
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
tabView.separatorStyle = .none
|
tabView.delegate = self
|
tabView.dataSource = self
|
tabView.register(UINib(nibName: "CouponCellThree", bundle: nil), forCellReuseIdentifier: "CouponCellThreeId")
|
tabView.register(UINib(nibName: "CouponCellTwo", bundle: nil), forCellReuseIdentifier: "CouponCellTwoId")
|
tabView.register(UINib(nibName: "WelfareCouponsTCell", bundle: nil), forCellReuseIdentifier: "_WelfareCouponsTCell")
|
// tabView.register(UINib(nibName: "CouponCell", bundle: nil), forCellReuseIdentifier: "CouponCellId")
|
Services.vipPayment().subscribe(onNext: { [weak self]data in
|
self?.model = data.data
|
self?.tabView.reloadData()
|
self?.nameLab.text = data.data?.name
|
if data.data?.isVip ?? 0 > 0 {
|
self?.memberLab.text = "当前暂未开通会员"
|
}else{
|
self?.memberLab.text = "Vip"
|
}
|
self?.headerImg.sd_setImage(with: URL(string: self?.model?.headImg ?? ""))
|
}).disposed(by: disposeBag)
|
|
}
|
|
|
@IBAction func selectAcceptAction(_ sender: UIButton) {
|
sender.isSelected = !sender.isSelected
|
acceptXy = sender.isSelected
|
}
|
|
@IBAction func lookxyAction(_ sender: UIButton) {
|
if acceptXy == false {
|
alertError(msg: "请先同意会员协议")
|
}else{
|
push(vc: CommonWebVC(type: .matchPoint,customTitle: "会员协议",content: "",needBackBtn: true))
|
}
|
}
|
|
|
@IBAction func playAction(_ sender: Any) {
|
PaymentView.show(enumType: .joinMember, money: (ali:self.model?.vipList[self.selectIndex].price?.doubleValue ?? 0,wx:self.model?.vipList[self.selectIndex].price?.doubleValue ?? 0,coin:nil,course:nil,integral:nil)) { type in
|
Services.enrollMember(paytype: type,id: self.model?.vipList[self.selectIndex].id ?? 0).subscribe(onNext: {data in
|
if let m = data.data{
|
switch type {
|
case .aliPay:
|
if let orderString = data.data?.orderString{
|
YYPaymentManager.shared.sendPaymentRequest(YYAlipayRequest(orderString: orderString)) {[weak self] result in
|
guard let weakSelf = self else { return }
|
switch result {
|
case .success:
|
let vc = PaymentResultVC(result: .success, objType: .member, handleVC: nil, courseConfigId: nil, againClouse: nil)
|
weakSelf.push(vc: vc)
|
case .cancel:
|
let vc = PaymentResultVC(result: .fail("已取消支付", 0), objType: .member, handleVC: nil, courseConfigId: nil, againClouse: nil)
|
weakSelf.push(vc: vc)
|
case .failure(let error):
|
if let er = error as? NetworkRequest.NetRequestError{
|
switch er {
|
case .Other(let code,let string):
|
let vc = PaymentResultVC(result: .fail(string,code), objType: .member)
|
weakSelf.push(vc: vc)
|
default:
|
let vc = PaymentResultVC(result: .fail("支付失败",0), objType: .member)
|
weakSelf.push(vc: vc)
|
}
|
}
|
}
|
}
|
}
|
case .wechat:
|
YYPaymentManager.shared.sendPaymentRequest(YYWeChatPayRequest(partnerId: m.partnerid, prepayId: m.prepayid, package: m.package, nonceStr: m.noncestr, timeStamp: m.timestamp, sign: m.sign)) {[weak self] result in
|
guard let weakSelf = self else { return }
|
switch result {
|
case .success:
|
let vc = PaymentResultVC(result: .success, objType: .member, handleVC: nil, courseConfigId: nil, againClouse: nil)
|
weakSelf.push(vc: vc)
|
case .cancel:
|
let vc = PaymentResultVC(result: .fail("已取消支付", 0), objType: .member, handleVC: nil, courseConfigId: nil, againClouse: nil)
|
weakSelf.push(vc: vc)
|
case .failure(let error):
|
if let er = error as? NetworkRequest.NetRequestError{
|
switch er {
|
case .Other(let code,let string):
|
let vc = PaymentResultVC(result: .fail(string,code), objType: .member)
|
weakSelf.push(vc: vc)
|
default:
|
let vc = PaymentResultVC(result: .fail("支付失败",0), objType: .member)
|
weakSelf.push(vc: vc)
|
}
|
}
|
}
|
}
|
default:break
|
}
|
}
|
|
}).disposed(by: self.disposeBag)
|
}
|
}
|
}
|