杨锴
2025-05-11 7453d2d0cef415b34323d1b91e6cfa4a6ba31178
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
//
//  SearchVC.swift
//  WanPai
//
//  Created by 杨锴 on 2023/6/8.
//
 
import UIKit
import JQTools
 
class SearchVC: BaseVC {
                @IBOutlet weak var scrollView: UIScrollView!
                @IBOutlet weak var banner_collectionView: UICollectionView!
                @IBOutlet weak var func_collectionView: UICollectionView!
                @IBOutlet weak var user_avarImg: UIImageView!
                @IBOutlet weak var label_userName: UILabel!
                @IBOutlet weak var label_vip: UILabel!
                @IBOutlet weak var img_vipMedal: UIImageView!
                @IBOutlet weak var label_wpCoin: UILabel!
                @IBOutlet weak var label_coin: UILabel!
                @IBOutlet weak var btn_becomeVIP: UIButton!
    @IBOutlet weak var view_top: UIView!
    @IBOutlet weak var coinCollectionView: UICollectionView!
    @IBOutlet weak var btn_coupon: UIButton!
    @IBOutlet weak var btn_shopping: UIButton!
    var benefitHomeModel:BenefitHomeModel?
                private var models = [StartClouseExploreModel]()
 
//                private var items = ["我的二维码","我的订场","社区世界杯","已报名活动","我的运动营","人员管理","我的券包","兑换记录","消费记录","积分明细","我的玩湃币"]
                private var items = ["我的二维码","我的订场","社区世界杯","已报名活动","我的运动营","人员管理","我的券包","兑换记录","消费记录","积分明细","玩湃惠民卡"]
//                private var itemsImg = ["me_code","me_yard","me_wordCup","me_activity","me_camp","me_peoples","me_coupons","me_withdrawRec","me_consume","me_coin","me_payCoin","me_judge"]
                private var itemsImg = ["me_code","me_yard","me_wordCup","me_activity","me_camp","me_peoples","me_coupons","me_withdrawRec","me_consume","me_coin","me_card"]
 
                override func viewDidDisappear(_ animated: Bool) {
                                super.viewDidDisappear(animated)
                }
 
                override func viewDidLoad() {
                                super.viewDidLoad()
                                scrollView.contentInsetAdjustmentBehavior = .never
 
                                Services.exploreHome().subscribe(onNext: {[weak self] data in
                                                if let models = data.data,models.count > 0{
                                                                self?.models = models
                                                                self?.banner_collectionView.reloadData()
                                                }else{
 
                                                }
                                }).disposed(by: disposeBag)
                }
 
                override func viewDidAppear(_ animated: Bool) {
                                super.viewDidAppear(animated)
                                getData()
//        navigationController?.isNavigationBarHidden = true
                }
 
                override func setUI() {
                                banner_collectionView.delegate = self
                                banner_collectionView.dataSource = self
                                banner_collectionView.register(UINib(nibName: "SearchBannerCCell", bundle: nil), forCellWithReuseIdentifier: "_SearchBannerCCell")
        banner_collectionView.contentInset = UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20)
                                func_collectionView.delegate = self
                                func_collectionView.dataSource = self
                                func_collectionView.register(UINib(nibName: "FindItemCCell", bundle: nil), forCellWithReuseIdentifier: "_FindItemCCell")
                                func_collectionView.contentInset = UIEdgeInsets(top: 25, left: 0, bottom: 25, right: 0)
 
        coinCollectionView.delegate  = self
        coinCollectionView.dataSource = self
        coinCollectionView.register(UINib(nibName: "WelfareCoinCCell", bundle: nil), forCellWithReuseIdentifier: "_WelfareCoinCCell")
 
 
                                //临时隐藏会员功能按钮
                            label_vip.text = "普通会员"
                                label_vip.isHidden = false
                            img_vipMedal.isHidden = true
                            btn_becomeVIP.isEnabled = false
                                //临时隐藏会员功能按钮
         let rightBarButtonItem = UIBarButtonItem(image: UIImage(named: "btn_s_setting"), style: .plain, target: self, action: #selector(settingAction))
        rightBarButtonItem.tintColor = .white
        navigationItem.rightBarButtonItem = rightBarButtonItem
                }
 
 
                override func viewDidLayoutSubviews() {
                                super.viewDidLayoutSubviews()
        view_top.jq_addShadows(shadowColor: .black.withAlphaComponent(0.1), corner: 10, radius: 5, offset: CGSize(width: 10, height: 0), opacity: 1)
                }
 
                private func getData(){
                                Services.benefitHome().subscribe(onNext: {[weak self] data in
                                                if let model = data.data{
                                                                guard let weakSelf = self else { return }
                                                                self?.benefitHomeModel = model
                                                                self?.user_avarImg.sd_setImage(with: URL(string: model.userHeadImg))
                                                                self?.label_userName.text = model.userName.isEmpty ? "未命名":model.userName
 
                                                                if model.isMember != "年度会员"{
                                                                                self?.label_vip.text = "成为会员"
                                                                }else{
                                                                                self?.label_vip.text = model.isMember
                                                                }
 
                                                                self?.label_wpCoin.text = model.wpCoin.currencyNotPrefix()
                                                                self?.label_coin.text = "\(model.userIntegral)"
                                                                self?.img_vipMedal.isHidden = model.isMember != "年度会员"
                                                                self?.btn_becomeVIP.isEnabled = model.isMember != "年度会员"
 
 
                                                                //临时隐藏会员功能按钮
                                                                self?.label_vip.text = "普通会员"
                                                                self?.label_vip.isHidden = false
                                                                self?.img_vipMedal.isHidden = true
                                                                self?.btn_becomeVIP.isEnabled = false
                                                                //临时隐藏会员功能按钮
 
 
                if let coupon = model.image?.myConpons{
                    self?.btn_coupon.sd_setImage(with: URL(string: coupon), for: .normal, placeholderImage: nil,context: nil)
                }
 
                if let onlineShop = model.image?.onlineShop{
                    self?.btn_shopping.sd_setImage(with: URL(string: onlineShop), for: .normal, placeholderImage: nil,context: nil)
                }
 
                                                                if model.referee == 1{
                                                                                if !weakSelf.items.contains(where: {$0 == "裁判入口"}){
                                                                                                self?.items.append("裁判入口")
                                                                                                self?.itemsImg.append("me_judge")
                                                                                                self?.func_collectionView.reloadData()
                                                                                }
                                                                }else {
                                                                                if weakSelf.items.contains(where: {$0 == "裁判入口"}){
                                                                                                self?.items.removeLast()
                                                                                                self?.itemsImg.removeLast()
                                                                                                self?.func_collectionView.reloadData()
                                                                                }
                                                                }
                self?.coinCollectionView.reloadData()
                                                }
                                }) { error in
 
                                }.disposed(by: disposeBag)
 
//        Services.benefitHome().subscribe(onNext: {[weak self] data in
//            if let model = data.data{
//                self?.benefitHomeModel = model
//            
//            }
//        }) { error in
//
//        }.disposed(by: disposeBag)
                }
 
    @IBAction func shoppingAction(_ sender: UIButton) {
        CommonAlertView.show(title: "提示", content: "即将打开京东,是否继续?") { status in
            if status{
 
                if UIApplication.shared.canOpenURL(URL(string: "openApp.jdMobile://")!){
                    let url = "openApp.jdMobile://virtual?params={\"category\":\"jump\",\"des\":\"jshopMain\",\"shopId\":\"15995015\",\"sourceType\":\"APP\",\"sourceValue\":\"1000\",\"landPageId\":\"iOS\"}"
                    UIApplication.shared.open(URL(string: url)!)
                }else{
                    let url = "https://shop.m.jd.com/shop/home?shopId=15995015"
                    UIApplication.shared.open(URL(string: url)!)
                }
 
 
            }
        }
    }
 
    @IBAction func couponsAction(_ sender: UIButton) {
        let vc = WelfareCouponsListVC()
        push(vc: vc)
    }
 
                @IBAction func becomeVIPAction(_ sender: Any) {
                                let vc = JoinMemberIntroduceVC()
                                push(vc: vc)
                }
                
                @IBAction func customerAction(_ sender: Any) {
                                let vc = CustomerListVC()
                                push(vc: vc)
                }
 
                @IBAction func wpCoinDetailAction(_ sender: Any) {
                                let vc = RechargeRecordVC(coin: benefitHomeModel?.wpCoin ?? 0,subtype: .coin)
                                push(vc: vc)
                }
 
                @IBAction func coinDetailAction(_ sender: Any) {
                                let vc = RechargeRecordVC(coin: benefitHomeModel?.userIntegral ?? 0,subtype: .integral)
                                push(vc: vc)
                }
 
 
                @IBAction func settingAction(_ sender: Any) {
                                let vc = ProfileVC()
                                push(vc: vc)
                }
                
 
                @IBAction func aboutMinProgram(_ sender: Any) {
 
                                CommonAlertView.show(title: "提示", content: "即将打开小程序,是否继续?") { status in
                                                if status{
                                                                let miniProgam = WXLaunchMiniProgramReq.object()
                                                                miniProgam.userName = WeChatMinProgram
#if DEBUG
                                                                miniProgam.miniProgramType = .preview
#else
                                                                miniProgam.miniProgramType = .release
#endif
                                                                miniProgam.path = WeChatMinProgramPath
                                                                WXApi.send(miniProgam) { s in
                                                                                if !s{
                                                                                                alert(msg: "打开失败")
                                                                                }
                                                                }
                                                }
                                }
                }
 
                override var preferredStatusBarStyle: UIStatusBarStyle{
                                return .lightContent
                }
}
 
extension SearchVC:UICollectionViewDelegate{
                func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
                                if collectionView == func_collectionView{
                                                switch items[indexPath.row]
                                                {
                                                                case "我的二维码":
                                                            let vc    = MeQRCodeVC()
                                                                push(vc: vc)
                                                                case "我的订场":
                                                                let vc = YardBookingListVC()
                                                                push(vc: vc)
                                                                case "社区世界杯":
                                                                let vc = WorldCupVC()
                                                                push(vc: vc)
                                                                case "已报名活动":
                                                                let vc = ActivitySignupListVC()
                                                                push(vc: vc)
                                                                case "我的运动营":
                                                                push(vc: SignUpCourseVC())
                                                                case "人员管理":
                                                                let vc = StudentsManagerListVC()
                                                                push(vc: vc)
                                                                case "我的券包":
                                                                let vc = WelfareCouponsListVC()
                                                                push(vc: vc)
                                                                case "兑换记录":
                                                                let vc = WelfareExchangeRecordListVC()
                                                                push(vc: vc)
                                                                case "消费记录":
                                                                 let vc = WelfareBillListVC()
                                                                push(vc: vc)
                                                                case "积分明细":
                                                                let vc = RechargeRecordVC(coin: benefitHomeModel?.userIntegral ?? 0,subtype: .integral)
                                                                push(vc: vc)
                                                                case "我的玩湃币":
                                                                let vc = RechargeRecordVC(coin: benefitHomeModel?.wpCoin ?? 0,subtype: .coin)
                                                                push(vc: vc)
                case "玩湃惠民卡":
                Services.getMyHuiminCard(page: 1,progress: true).subscribe(onNext: {data in
                    var firstM:HuiminCardMyItemModel?
                    if data.data?.count == 1,let m = data.data?.first{
                        firstM = m
                    }
                    let vc = MyCardListVC()
                    vc.jumpToFirst = firstM
                    self.push(vc: vc,animated: false)
 
                }).disposed(by: disposeBag)
 
 
                                                                case "裁判入口":
                                                                let vc = JudgeListVC()
                                                                push(vc: vc)
                                                                default:
                                                                                break
                                                }
                                
 
                                }
 
                                if collectionView == banner_collectionView{
                                                let model = models[indexPath.row]
                                                let vc = SearchStoreDetailVC(id: model.storeId)
                                                push(vc: vc)
                                }
                }
}
 
extension SearchVC:UICollectionViewDataSource{
                func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
                                if collectionView == func_collectionView{
                                                return items.count
                                }
 
        if collectionView == coinCollectionView{
            return benefitHomeModel?.commodities.count ?? 0
        }
 
                                return models.count
                }
 
                func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
 
                                if collectionView == func_collectionView{
                                                let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_FindItemCCell", for: indexPath) as! FindItemCCell
                                                cell.label_title.text = items[indexPath.row]
                                                cell.img_avar.image = UIImage(named: itemsImg[indexPath.row])
                                                return cell
                                }
 
        if collectionView == coinCollectionView{
            let model = benefitHomeModel!.commodities[indexPath.row]
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_WelfareCoinCCell", for: indexPath) as! WelfareCoinCCell
            cell.label_name.text = model.commodityName
 
            switch model.redemptionMethod {
                case 1: //积分
                    cell.label_price.text = "\(model.integral)积分"
                case 2: //现金+积分
                    cell.label_price.text = "\(model.integral)积分+\(model.commodityPrice.currency())"
                case 3://现金
                    cell.label_price.text = "\(model.commodityPrice.currency())"
                default:
                    cell.label_price.text = ""
            }
 
 
            cell.img_cover.sd_setImage(with: URL(string: model.commodityImg), placeholderImage: nil)
            return cell
        }
 
                                let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_SearchBannerCCell", for: indexPath) as! SearchBannerCCell
                                let model = models[indexPath.row]
                                cell.startClouseExploreItemModel = model
                                return cell
                }
}
 
 
extension SearchVC:UICollectionViewDelegateFlowLayout{
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
 
                                if collectionView == func_collectionView{
                                                return 0
                                }
        if collectionView == coinCollectionView{
            return 0
        }
                                return 14
                }
 
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
                                if collectionView == func_collectionView{
                                                return 0
                                }
        if collectionView == coinCollectionView{
            return 0
        }
                                return 14
                }
 
                func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
                                if collectionView == func_collectionView{
                                                return CGSize(width: JQ_ScreenW/4, height: 120)
                                }
        if collectionView == coinCollectionView{
            return CGSize(width: 144.0, height: 178)
        }
        return CGSize(width: JQ_ScreenW * 0.743, height: JQ_ScreenW * 0.743 * 0.931)
                }
}