杨锴
2024-11-07 62a24b3c7cf92919a93ee575e9460037e1a53816
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
//
//  MeVC.swift
//  XQMuse
//
//  Created by 无故事王国 on 2024/8/12.
//
 
import UIKit
import QMUIKit
import JQTools
 
let Refreh_Notice_Noti = Notification.Name.init("Refreh_Notice_Noti")
 
class MeVC: BaseVC {
 
                @IBOutlet weak var scrollView: UIScrollView!
                @IBOutlet weak var btn_collect: QMUIButton!
                @IBOutlet weak var btn_record: QMUIButton!
                @IBOutlet weak var btn_history: QMUIButton!
                @IBOutlet weak var btn_account: QMUIButton!
                @IBOutlet weak var btn_buy: QMUIButton!
                @IBOutlet weak var btn_customer: QMUIButton!
                @IBOutlet weak var btn_setting: QMUIButton!
                @IBOutlet weak var btn_share: QMUIButton!
                @IBOutlet weak var view_rank: GradientView!
                @IBOutlet weak var image_vipBg: UIImageView!
                @IBOutlet weak var label_expirtTime: UILabel!
                @IBOutlet weak var label_sustainDay: UILabel!
                @IBOutlet weak var label_today: UILabel!
                @IBOutlet weak var image_medal: UIImageView!
                @IBOutlet weak var btn_notice: NoticeBtn!
                
                @IBOutlet weak var image_userAvatar: UIImageView!
                @IBOutlet weak var label_userName: UILabel!
                @IBOutlet weak var label_phone: UILabel!
                @IBOutlet weak var label_vipInfo: UILabel!
                @IBOutlet weak var label_totalDay: UILabel!
                
                override func viewDidLoad() {
        super.viewDidLoad()
 
                                let tap = UITapGestureRecognizer(target: self, action: #selector(rankAction))
                                view_rank.isUserInteractionEnabled = true
                                view_rank.addGestureRecognizer(tap)
 
                                getData()
                                queryNotice()
    }
 
                override func setUI() {
                                super.setUI()
                                view.backgroundColor = UIColor(hexString: "#fafafa")
                                scrollView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 20, right: 0)
                                scrollView.showsVerticalScrollIndicator = false
                                btn_collect.imagePosition = .top
                                btn_record.imagePosition = .top
                                btn_history.imagePosition = .top
                                btn_account.imagePosition = .top
 
                                btn_buy.imagePosition = .top
                                btn_customer.imagePosition = .top
                                btn_setting.imagePosition = .top
                                btn_share.imagePosition = .top
                }
 
                private func queryNotice(){
                                Services.queryNotice().subscribe(onNext: {data in
                                                self.btn_notice.hasNotice(!(data.data ?? false))
                                }).disposed(by: disposeBag)
                }
 
                override func setRx() {
                                NotificationCenter.default.rx.notification(UpdateUserProfile_Noti, object: nil).take(until: self.rx.deallocated).subscribe(onNext: { _ in
                                                self.getData()
                                }).disposed(by: disposeBag)
 
                                NotificationCenter.default.rx.notification(Refreh_Notice_Noti, object: nil).take(until: self.rx.deallocated).subscribe(onNext: { _ in
                                                self.queryNotice()
                                }).disposed(by: disposeBag)
 
        NotificationCenter.default.rx.notification(LoginSuccess_Noti).take(until: self.rx.deallocated).subscribe(onNext: {data in
            self.getData()
            self.queryNotice()
        }).disposed(by: disposeBag)
 
        NotificationCenter.default.rx.notification(LoginQuit_Noti).take(until: self.rx.deallocated).subscribe(onNext: {data in
            self.label_userName.text = "请先登录"
            self.image_userAvatar.image = nil
            self.label_phone.text = ""
 
            self.label_totalDay.attributedText = AttributedStringbuilder.build().add(string: "0", withFont: Def_PingFang(fontSize: 60), withColor: UIColor(hexString: "#152715")!).add(string: "天", withFont: Def_PingFang(fontSize: 16), withColor: UIColor(hexString: "#353535")!).mutableAttributedString
 
            self.image_medal.image = nil
 
            self.label_sustainDay.attributedText = AttributedStringbuilder.build().add(string: "0", withFont: Def_PingFang(fontSize: 23), withColor: UIColor(hexString: "#353535")!).add(string: "天", withFont: Def_PingFang(fontSize: 12), withColor: UIColor(hexString: "#353535")!).mutableAttributedString
 
            self.image_vipBg.image = UIImage(named: "bg_vip_u")
            self.label_vipInfo.text = "升级为会员,解锁会员专属体验"
            self.label_expirtTime.text = "你还未开通会员服务"
            self.navigationController?.popToRootViewController(animated: false)
            self.navigationController?.tabBarController?.selectedIndex = 0
        }).disposed(by: disposeBag)
                }
 
                private func getData(){
 
        Services.getUserDetail().subscribe(onNext: {[weak self]data in
            if let model = data.data{
                UserViewModel.saveAvatarInfo(model)
                self?.setUserUI(model: model)
 
            }
        }) {[weak self] error in
            let model = UserViewModel.getAvatarInfo()
            if model.id > 0{
                self?.setUserUI(model: model)
            }
        }.disposed(by: disposeBag)
                }
 
    private func setUserUI(model:UserInfoModel){
        self.image_userAvatar.sd_setImage(with: URL(string: model.avatar))
        self.label_userName.text = model.nickname
        self.label_phone.text = model.cellPhone
 
        self.label_totalDay.attributedText = AttributedStringbuilder.build().add(string: "\(model.cumulative)", withFont: Def_PingFang(fontSize: 60), withColor: UIColor(hexString: "#353535")!).add(string: "天", withFont: Def_PingFang(fontSize: 16), withColor: UIColor(hexString: "#353535")!).mutableAttributedString
 
        self.label_sustainDay.attributedText = AttributedStringbuilder.build().add(string: "\(model.continuity)", withFont: Def_PingFang(fontSize:23), withColor: UIColor(hexString: "#353535")!).add(string: "天", withFont: Def_PingFang(fontSize:12), withColor: UIColor(hexString: "#353535")!).mutableAttributedString
 
        self.image_medal.sd_setImage(with: URL(string: model.levelIcon.jq_urlEncoded()))
 
        let timeTurple = Date.jq_formateToTime_tuple(model.today * 60)
 
        self.label_today.attributedText = AttributedStringbuilder.build().add(string: "\(timeTurple.hour)", withFont: Def_PingFang(fontSize:23), withColor: UIColor(hexString: "#353535")!).add(string: "时", withFont: Def_PingFang(fontSize:12), withColor: UIColor(hexString: "#353535")!).add(string: "\(timeTurple.minute)", withFont: Def_PingFang(fontSize:23), withColor: UIColor(hexString: "#353535")!).add(string: "分", withFont: Def_PingFang(fontSize: 12), withColor: UIColor(hexString: "#353535")!).mutableAttributedString
 
        if model.isVip == .yes{
            self.image_vipBg.image = UIImage(named: "bg_vip")
            self.label_vipInfo.text = "您将享受所有会员专享音频,尽情畅游心泉·疗愈世界"
            self.label_expirtTime.text = model.vipExpireTime.components(separatedBy: " ").first! + "到期"
        }else{
            self.image_vipBg.image = UIImage(named: "bg_vip_u")
            self.label_vipInfo.text = "升级为会员,解锁会员专属体验"
            self.label_expirtTime.text = "你还未开通会员服务"
        }
    }
 
                @objc func rankAction(){
        let vc = WebVC(url: ShareUrl + "/ranking/ranking?userId=\(UserViewModel.getAvatarInfo().id)")
                                vc.title = "爱心榜单"
                                push(vc: vc)
                }
 
                @IBAction func vipCenterAction(_ sender: Any) {
        guard sceneDelegate!.checkisLoginState() else {return}
                                 let vc = VIPCenterVC()
                                push(vc: vc)
                }
                
 
                @IBAction func userProfileAction(_ sender: UIButton) {
        guard sceneDelegate!.checkisLoginState() else {return}
                                let profileVC = UserProfileVC()
                                jq_push(vc: profileVC)
                }
 
                @IBAction func studyLevelAction(_ sender: TapBtn) {
        guard sceneDelegate!.checkisLoginState() else {return}
                                let vc = LevelVC()
                                push(vc: vc)
                }
 
                @IBAction func systemMessageAction(_ sender: UIButton) {
                                let vc = NoticeCenterVC()
                                push(vc: vc)
                }
 
                @IBAction func settingAction(_ sender: UIButton) {
                                let vc = SettingVC()
                                push(vc: vc)
                }
                
                //学习记录
                @IBAction func studyAction(_ sender: UIButton) {
        guard sceneDelegate!.checkisLoginState() else {return}
                                let vc = StudyListVC()
                                push(vc: vc)
                }
 
 
                //我的账户
                @IBAction func myAccountAction(_ sender: QMUIButton) {
        guard sceneDelegate!.checkisLoginState() else {return}
                                 let vc = WalletVC()
                                push(vc: vc)
                }
 
                //观看历史
                @IBAction func watchHistoryAction(_ sender: QMUIButton) {
        guard sceneDelegate!.checkisLoginState() else {return}
                                let vc = WatchHistoryVC(type: .history)
                                push(vc: vc)
                }
 
                //我的收藏
                @IBAction func myColletAction(_ sender: QMUIButton) {
        guard sceneDelegate!.checkisLoginState() else {return}
                                let vc = WatchHistoryVC(type: .collect)
                                push(vc: vc)
                }
 
                /// 我的已购
                @IBAction func paymentCourseAction(_ sender: QMUIButton) {
        guard sceneDelegate!.checkisLoginState() else {return}
                                let vc = WatchHistoryVC(type: .payment)
                                push(vc: vc)
                }
 
                /// 联系客服
                @IBAction func customerAction(_ sender: QMUIButton) {
                                let vc = ContactCustomerVC()
                                push(vc: vc)
                }
                
                ///分享
                @IBAction func shareAction(_ sender: QMUIButton) {
         let vc =  InviteVC()
        push(vc: vc)
                }
}
 
class GradientView:UIView{
 
                override init(frame: CGRect) {
                                super.init(frame: frame)
 
                                jq_gradientColor(colorArr: [UIColor(hexString: "#F3FFF8")!.cgColor,UIColor.white.cgColor])
                }
                
                required init?(coder: NSCoder) {
                                super.init(coder: coder)
 
                }
                
                override func awakeFromNib() {
                                super.awakeFromNib()
                                jq_gradientColor(colorArr: [UIColor(hexString: "#F3FFF8")!.cgColor,UIColor.white.cgColor], cornerRadius: 10, startPoint: CGPoint(x: 0, y: 0), endPoint: CGPoint(x: 0, y: 1), bounds: nil, locations: nil)
                }
}