Robert
1 天以前 d23fce7c9da9f47cb4bb4630c3b428b12ce1c7eb
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
//
//  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)
        }
    }
}